Class: OpenUSD::Format::Usda::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/openusd/format/usda/parser.rb

Overview

Recursive-descent parser for USDA layers.

Constant Summary collapse

SPECIFIERS =

Authored prim specifier keywords.

%w[def over class].freeze
LIST_OPERATIONS =

Recognized list-edit operation keywords.

%w[prepend append delete reorder add explicit].freeze
QUALIFIERS =

Recognized property qualifiers.

%w[custom uniform varying].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, file: nil) ⇒ Parser

Returns a new instance of Parser.



25
26
27
28
29
# File 'lib/openusd/format/usda/parser.rb', line 25

def initialize(source, file: nil)
  @lexer = Lexer.new(source, file: file)
  @file = file
  advance
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



23
24
25
# File 'lib/openusd/format/usda/parser.rb', line 23

def file
  @file
end

Class Method Details

.parse(source, file: nil) ⇒ Layer

Parse a USDA string.

Returns:



18
19
20
# File 'lib/openusd/format/usda/parser.rb', line 18

def parse(source, file: nil)
  new(source, file: file).parse
end

Instance Method Details

#parseLayer

Parse the configured source.

Returns:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/openusd/format/usda/parser.rb', line 33

def parse
  header = expect(:magic, description: "USDA header")
  error!("unsupported USDA version #{header.value}") unless header.value == "1.0"

  layer = Layer.new(file)
  layer..merge!((layer_comment: true)) if symbol?("(")
  layer.add_root_prim(parse_prim) until current.type == :eof
  layer
rescue OpenUSD::PathError, OpenUSD::TypeError => e
  error!(e.message)
end