PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.14k stars 1.22k forks source link

Grammar railroad diagram #3019

Open mingodad opened 7 months ago

mingodad commented 7 months ago

I've just added this project grammar to https://mingodad.github.io/parsertl-playground/playground/ an Yacc/Lex compatible online editor/tester (select OpenUSD parser from Examples then click Parse to see a parse tree for the content in Input source).

And here is an EBNF to generate a nice navigable railroad diagram:

//
// EBNF to be viewd at
//    (IPV6) https://www.bottlecaps.de/rr/ui
//    (IPV4) https://rr.red-dove.com/ui
//
// Copy and paste this at one of the urls shown above in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//

sdf_file::=
      layer

keyword::=
      TOK_ABSTRACT
    | TOK_ADD
    | TOK_APPEND
    | TOK_CLASS
    | TOK_CONFIG
    | TOK_CONNECT
    | TOK_CUSTOM
    | TOK_CUSTOMDATA
    | TOK_DEF
    | TOK_DEFAULT
    | TOK_DELETE
    | TOK_DICTIONARY
    | TOK_DISPLAYUNIT
    | TOK_DOC
    | TOK_INHERITS
    | TOK_KIND
    | TOK_NAMECHILDREN
    | TOK_NONE
    | TOK_OFFSET
    | TOK_OVER
    | TOK_PAYLOAD
    | TOK_PERMISSION
    | TOK_PREFIX_SUBSTITUTIONS
    | TOK_SUFFIX_SUBSTITUTIONS
    | TOK_PREPEND
    | TOK_PROPERTIES
    | TOK_REFERENCES
    | TOK_RELOCATES
    | TOK_REL
    | TOK_RENAMES
    | TOK_REORDER
    | TOK_ROOTPRIMS
    | TOK_SCALE
    | TOK_SPECIALIZES
    | TOK_SUBLAYERS
    | TOK_SYMMETRYARGUMENTS
    | TOK_SYMMETRYFUNCTION
    | TOK_TIME_SAMPLES
    | TOK_UNIFORM
    | TOK_VARIANTS
    | TOK_VARIANTSET
    | TOK_VARIANTSETS
    | TOK_VARYING

layer_metadata_form::=
      layer_metadata_opt
    | layer_metadata_opt prim_list newlines_opt

layer::=
      TOK_MAGIC layer_metadata_form

layer_metadata_opt::=
      newlines_opt
    | newlines_opt '(' layer_metadata_list_opt ')' newlines_opt

layer_metadata_list_opt::=
      newlines_opt
    | newlines_opt layer_metadata_list stmtsep_opt

layer_metadata_list::=
      layer_metadata
    | layer_metadata_list stmtsep layer_metadata

layer_metadata_key::=
      identifier

layer_metadata::=
      TOK_STRING
    | layer_metadata_key '=' metadata_value
    | TOK_DELETE identifier '=' metadata_listop_list
    | TOK_ADD identifier '=' metadata_listop_list
    | TOK_PREPEND identifier '=' metadata_listop_list
    | TOK_APPEND identifier '=' metadata_listop_list
    | TOK_REORDER identifier '=' metadata_listop_list
    | TOK_DOC '=' TOK_STRING
    | TOK_SUBLAYERS '=' sublayer_list

sublayer_list::=
      '[' newlines_opt ']'
    | '[' newlines_opt sublayer_list_int listsep_opt ']'

sublayer_list_int::=
      sublayer_stmt
    | sublayer_list_int listsep sublayer_stmt

sublayer_stmt::=
      layer_ref layer_offset_opt

layer_ref::=
      TOK_ASSETREF

layer_offset_opt::=
      /*%empty*/
    | '(' layer_offset_int stmtsep_opt ')'

layer_offset_int::=
      layer_offset_stmt
    | layer_offset_int stmtsep layer_offset_stmt

layer_offset_stmt::=
      TOK_OFFSET '=' TOK_NUMBER
    | TOK_SCALE '=' TOK_NUMBER

prim_list::=
      prim_stmt
    | prim_list newlines prim_stmt

prim_stmt::=
      TOK_DEF prim_stmt_int
    | TOK_DEF prim_type_name prim_stmt_int
    | TOK_CLASS prim_stmt_int
    | TOK_CLASS prim_type_name prim_stmt_int
    | TOK_OVER prim_stmt_int
    | TOK_OVER prim_type_name prim_stmt_int
    | TOK_REORDER TOK_ROOTPRIMS '=' name_list

prim_type_name::=
      identifier
    | prim_type_name '.' identifier

prim_stmt_int::=
      TOK_STRING prim_metadata_opt '{' prim_contents_list_opt '}'

prim_metadata_opt::=
      newlines_opt
    | newlines_opt '(' prim_metadata_list_opt ')' newlines_opt

prim_metadata_list_opt::=
      newlines_opt
    | newlines_opt prim_metadata_list stmtsep_opt

prim_metadata_list::=
      prim_metadata
    | prim_metadata_list stmtsep prim_metadata

prim_metadata_key::=
      identifier
    | TOK_CUSTOMDATA
    | TOK_SYMMETRYARGUMENTS

prim_metadata::=
      TOK_STRING
    | prim_metadata_key '=' metadata_value
    | TOK_DELETE identifier '=' metadata_listop_list
    | TOK_ADD identifier '=' metadata_listop_list
    | TOK_PREPEND identifier '=' metadata_listop_list
    | TOK_APPEND identifier '=' metadata_listop_list
    | TOK_REORDER identifier '=' metadata_listop_list
    | TOK_DOC '=' TOK_STRING
    | TOK_KIND '=' TOK_STRING
    | TOK_PERMISSION '=' identifier
    | TOK_PAYLOAD '=' payload_list
    | TOK_DELETE TOK_PAYLOAD '=' payload_list
    | TOK_ADD TOK_PAYLOAD '=' payload_list
    | TOK_PREPEND TOK_PAYLOAD '=' payload_list
    | TOK_APPEND TOK_PAYLOAD '=' payload_list
    | TOK_REORDER TOK_PAYLOAD '=' payload_list
    | TOK_INHERITS '=' inherit_list
    | TOK_DELETE TOK_INHERITS '=' inherit_list
    | TOK_ADD TOK_INHERITS '=' inherit_list
    | TOK_PREPEND TOK_INHERITS '=' inherit_list
    | TOK_APPEND TOK_INHERITS '=' inherit_list
    | TOK_REORDER TOK_INHERITS '=' inherit_list
    | TOK_SPECIALIZES '=' specializes_list
    | TOK_DELETE TOK_SPECIALIZES '=' specializes_list
    | TOK_ADD TOK_SPECIALIZES '=' specializes_list
    | TOK_PREPEND TOK_SPECIALIZES '=' specializes_list
    | TOK_APPEND TOK_SPECIALIZES '=' specializes_list
    | TOK_REORDER TOK_SPECIALIZES '=' specializes_list
    | TOK_REFERENCES '=' reference_list
    | TOK_DELETE TOK_REFERENCES '=' reference_list
    | TOK_ADD TOK_REFERENCES '=' reference_list
    | TOK_PREPEND TOK_REFERENCES '=' reference_list
    | TOK_APPEND TOK_REFERENCES '=' reference_list
    | TOK_REORDER TOK_REFERENCES '=' reference_list
    | TOK_RELOCATES '=' relocates_map
    | TOK_VARIANTS '=' typed_dictionary
    | TOK_VARIANTSETS '=' name_list
    | TOK_DELETE TOK_VARIANTSETS '=' name_list
    | TOK_ADD TOK_VARIANTSETS '=' name_list
    | TOK_PREPEND TOK_VARIANTSETS '=' name_list
    | TOK_APPEND TOK_VARIANTSETS '=' name_list
    | TOK_REORDER TOK_VARIANTSETS '=' name_list
    | TOK_SYMMETRYFUNCTION '=' identifier
    | TOK_SYMMETRYFUNCTION '='
    | TOK_PREFIX_SUBSTITUTIONS '=' string_dictionary
    | TOK_SUFFIX_SUBSTITUTIONS '=' string_dictionary

payload_list::=
      TOK_NONE
    | payload_list_item
    | '[' newlines_opt ']'
    | '[' newlines_opt payload_list_int listsep_opt ']'

payload_list_int::=
      payload_list_item
    | payload_list_int listsep payload_list_item

payload_list_item::=
      layer_ref prim_path_opt payload_params_opt
    | TOK_PATHREF payload_params_opt

payload_params_opt::=
      /*%empty*/
    | '(' newlines_opt ')'
    | '(' newlines_opt payload_params_int stmtsep_opt ')'

payload_params_int::=
      payload_params_item
    | payload_params_int stmtsep payload_params_item

payload_params_item::=
      layer_offset_stmt

reference_list::=
      TOK_NONE
    | reference_list_item
    | '[' newlines_opt ']'
    | '[' newlines_opt reference_list_int listsep_opt ']'

reference_list_int::=
      reference_list_item
    | reference_list_int listsep reference_list_item

reference_list_item::=
      layer_ref prim_path_opt reference_params_opt
    | TOK_PATHREF reference_params_opt

reference_params_opt::=
      /*%empty*/
    | '(' newlines_opt ')'
    | '(' newlines_opt reference_params_int stmtsep_opt ')'

reference_params_int::=
      reference_params_item
    | reference_params_int stmtsep reference_params_item

reference_params_item::=
      layer_offset_stmt
    | TOK_CUSTOMDATA '=' typed_dictionary

inherit_list::=
      TOK_NONE
    | inherit_list_item
    | '[' newlines_opt ']'
    | '[' newlines_opt inherit_list_int listsep_opt ']'

inherit_list_int::=
      inherit_list_item
    | inherit_list_int listsep inherit_list_item

inherit_list_item::=
      prim_path

specializes_list::=
      TOK_NONE
    | specializes_list_item
    | '[' newlines_opt ']'
    | '[' newlines_opt specializes_list_int listsep_opt ']'

specializes_list_int::=
      specializes_list_item
    | specializes_list_int listsep specializes_list_item

specializes_list_item::=
      prim_path

relocates_map::=
      '{' newlines_opt relocates_stmt_list_opt '}'

relocates_stmt_list_opt::=
      /*%empty*/
    | relocates_stmt_list listsep_opt

relocates_stmt_list::=
      relocates_stmt
    | relocates_stmt_list listsep relocates_stmt

relocates_stmt::=
      TOK_PATHREF ':' TOK_PATHREF

name_list::=
      name_list_item
    | '[' newlines_opt name_list_int listsep_opt ']'

name_list_int::=
      name_list_item
    | name_list_int listsep name_list_item

name_list_item::=
      TOK_STRING

prim_contents_list_opt::=
      newlines_opt
    | newlines_opt prim_contents_list

prim_contents_list::=
      prim_contents_list_item
    | prim_contents_list prim_contents_list_item

prim_contents_list_item::=
      prim_property stmtsep
    | prim_child_order_stmt stmtsep
    | prim_property_order_stmt stmtsep
    | prim_stmt newlines
    | variantset_stmt newlines

variantset_stmt::=
      TOK_VARIANTSET TOK_STRING '=' newlines_opt '{' newlines_opt variant_list '}'

variant_list::=
      variant_stmt
    | variant_list variant_stmt

variant_stmt::=
      TOK_STRING prim_metadata_opt '{' prim_contents_list_opt '}' newlines_opt

prim_child_order_stmt::=
      TOK_REORDER TOK_NAMECHILDREN '=' name_list

prim_property_order_stmt::=
      TOK_REORDER TOK_PROPERTIES '=' name_list

prim_property::=
      prim_attribute
    | prim_relationship

prim_attr_variability::=
      TOK_UNIFORM
    | TOK_CONFIG

prim_attr_qualifiers::=
      prim_attr_variability

prim_attr_type::=
      identifier
    | identifier '[' ']'

prim_attribute_full_type::=
      prim_attr_type
    | prim_attr_qualifiers prim_attr_type

prim_attribute_default::=
      prim_attribute_full_type namespaced_name attribute_assignment_opt attribute_metadata_list_opt

prim_attribute_fallback::=
      TOK_CUSTOM prim_attribute_full_type namespaced_name attribute_assignment_opt attribute_metadata_list_opt

prim_attribute_connect::=
      prim_attribute_full_type namespaced_name '.' TOK_CONNECT '=' connect_rhs
    | TOK_ADD prim_attribute_full_type namespaced_name '.' TOK_CONNECT '=' connect_rhs
    | TOK_PREPEND prim_attribute_full_type namespaced_name '.' TOK_CONNECT '=' connect_rhs
    | TOK_APPEND prim_attribute_full_type namespaced_name '.' TOK_CONNECT '=' connect_rhs
    | TOK_DELETE prim_attribute_full_type namespaced_name '.' TOK_CONNECT '=' connect_rhs
    | TOK_REORDER prim_attribute_full_type namespaced_name '.' TOK_CONNECT '=' connect_rhs

prim_attribute_time_samples::=
      prim_attribute_full_type namespaced_name '.' TOK_TIME_SAMPLES '=' time_samples_rhs

prim_attribute::=
      prim_attribute_fallback
    | prim_attribute_default
    | prim_attribute_connect
    | prim_attribute_time_samples

connect_rhs::=
      TOK_NONE
    | connect_item
    | '[' newlines_opt ']'
    | '[' newlines_opt connect_list listsep_opt ']'

connect_list::=
      connect_item
    | connect_list listsep connect_item

connect_item::=
      prim_or_property_scene_path

time_samples_rhs::=
      '{' newlines_opt time_sample_list '}'

time_sample_list::=
      /*%empty*/
    | time_sample_list_int listsep_opt

time_sample_list_int::=
      time_sample
    | time_sample_list_int listsep time_sample

time_sample::=
      extended_number ':' typed_value
    | extended_number ':' TOK_NONE

attribute_metadata_list_opt::=
      /*%empty*/
    | '(' newlines_opt ')'
    | '(' newlines_opt attribute_metadata_list stmtsep_opt ')'

attribute_metadata_list::=
      attribute_metadata
    | attribute_metadata_list stmtsep attribute_metadata

attribute_metadata_key::=
      identifier
    | TOK_CUSTOMDATA
    | TOK_SYMMETRYARGUMENTS

attribute_metadata::=
      TOK_STRING
    | attribute_metadata_key '=' metadata_value
    | TOK_DELETE identifier '=' metadata_listop_list
    | TOK_ADD identifier '=' metadata_listop_list
    | TOK_PREPEND identifier '=' metadata_listop_list
    | TOK_APPEND identifier '=' metadata_listop_list
    | TOK_REORDER identifier '=' metadata_listop_list
    | TOK_DOC '=' TOK_STRING
    | TOK_PERMISSION '=' identifier
    | TOK_DISPLAYUNIT '=' identifier
    | TOK_SYMMETRYFUNCTION '=' identifier
    | TOK_SYMMETRYFUNCTION '='

attribute_assignment_opt::=
      /*%empty*/
    | '=' attribute_value

attribute_value::=
      typed_value
    | TOK_NONE

typed_dictionary::=
      '{' newlines_opt typed_dictionary_list_opt '}'

typed_dictionary_list_opt::=
      /*%empty*/
    | typed_dictionary_list stmtsep_opt

typed_dictionary_list::=
      typed_dictionary_element
    | typed_dictionary_list stmtsep typed_dictionary_element

typed_dictionary_element::=
      dictionary_value_type dictionary_key '=' typed_value
    | TOK_DICTIONARY dictionary_key '=' typed_dictionary

dictionary_key::=
      TOK_STRING
    | name

dictionary_value_type::=
      dictionary_value_scalar_type
    | dictionary_value_shaped_type

dictionary_value_scalar_type::=
      identifier

dictionary_value_shaped_type::=
      identifier '[' ']'

string_dictionary::=
      '{' newlines_opt string_dictionary_list_opt '}'

string_dictionary_list_opt::=
      /*%empty*/
    | string_dictionary_list listsep_opt

string_dictionary_list::=
      string_dictionary_element
    | string_dictionary_list listsep string_dictionary_element

string_dictionary_element::=
      TOK_STRING ':' TOK_STRING

metadata_listop_list::=
      TOK_NONE
    | typed_value_list

metadata_value::=
      typed_dictionary
    | typed_value
    | TOK_NONE

typed_value::=
      typed_value_atomic
    | typed_value_tuple
    | typed_value_list
    | '[' ']'
    | TOK_PATHREF

typed_value_atomic::=
      TOK_NUMBER
    | TOK_STRING
    | identifier
    | TOK_ASSETREF

typed_value_list::=
      '[' typed_value_list_int ']'

typed_value_list_int::=
      newlines_opt typed_value_list_items listsep_opt

typed_value_list_items::=
      typed_value_list_item
    | typed_value_list_items listsep typed_value_list_item

typed_value_list_item::=
      typed_value_atomic
    | typed_value_list
    | typed_value_tuple

typed_value_tuple::=
      '(' typed_value_tuple_int ')'

typed_value_tuple_int::=
      newlines_opt typed_value_tuple_items listsep_opt

typed_value_tuple_items::=
      typed_value_tuple_item
    | typed_value_tuple_items listsep typed_value_tuple_item

typed_value_tuple_item::=
      typed_value_atomic
    | typed_value_tuple

prim_relationship_type::=
      TOK_REL
    | TOK_CUSTOM TOK_REL
    | TOK_CUSTOM TOK_VARYING TOK_REL
    | TOK_VARYING TOK_REL

prim_relationship_time_samples::=
      prim_relationship_type namespaced_name '.' TOK_TIME_SAMPLES '=' time_samples_rhs

prim_relationship_default::=
      prim_relationship_type namespaced_name '.' TOK_DEFAULT '=' TOK_PATHREF

prim_relationship::=
      prim_relationship_type namespaced_name relationship_assignment_opt relationship_metadata_list_opt
    | TOK_DELETE prim_relationship_type namespaced_name relationship_assignment_opt
    | TOK_ADD prim_relationship_type namespaced_name relationship_assignment_opt
    | TOK_PREPEND prim_relationship_type namespaced_name relationship_assignment_opt
    | TOK_APPEND prim_relationship_type namespaced_name relationship_assignment_opt
    | TOK_REORDER prim_relationship_type namespaced_name relationship_assignment_opt
    | prim_relationship_type namespaced_name '[' TOK_PATHREF ']'
    | prim_relationship_time_samples
    | prim_relationship_default

relationship_metadata_list_opt::=
      /*%empty*/
    | '(' newlines_opt ')'
    | '(' newlines_opt relationship_metadata_list stmtsep_opt ')'

relationship_metadata_list::=
      relationship_metadata
    | relationship_metadata_list stmtsep relationship_metadata

relationship_metadata_key::=
      identifier
    | TOK_CUSTOMDATA
    | TOK_SYMMETRYARGUMENTS

relationship_metadata::=
      TOK_STRING
    | relationship_metadata_key '=' metadata_value
    | TOK_DELETE identifier '=' metadata_listop_list
    | TOK_ADD identifier '=' metadata_listop_list
    | TOK_PREPEND identifier '=' metadata_listop_list
    | TOK_APPEND identifier '=' metadata_listop_list
    | TOK_REORDER identifier '=' metadata_listop_list
    | TOK_DOC '=' TOK_STRING
    | TOK_PERMISSION '=' identifier
    | TOK_SYMMETRYFUNCTION '=' identifier
    | TOK_SYMMETRYFUNCTION '='

relationship_assignment_opt::=
      /*%empty*/
    | '=' relationship_rhs

relationship_rhs::=
      relationship_target
    | TOK_NONE
    | '[' newlines_opt ']'
    | '[' newlines_opt relationship_target_list listsep_opt ']'

relationship_target_list::=
      relationship_target
    | relationship_target_list listsep relationship_target

relationship_target::=
      TOK_PATHREF

prim_path_opt::=
      /*%empty*/
    | prim_path

prim_path::=
      TOK_PATHREF

prim_or_property_scene_path::=
      TOK_PATHREF

name::=
      identifier
    | keyword

namespaced_name::=
      TOK_IDENTIFIER
    | TOK_NAMESPACED_IDENTIFIER
    | keyword

identifier::=
      TOK_IDENTIFIER
    | TOK_CXX_NAMESPACED_IDENTIFIER

extended_number::=
      TOK_NUMBER
    | TOK_IDENTIFIER

stmtsep_opt::=
      /*%empty*/
    | stmtsep

stmtsep::=
      ';' newlines_opt
    | newlines

listsep_opt::=
      newlines_opt
    | listsep

listsep::=
      ',' newlines_opt

newlines_opt::=
      /*%empty*/
    | newlines

newlines::=
      TOK_NL
    | newlines TOK_NL

//Tokens

TOK_ADD ::= "add"
TOK_APPEND ::= "append"
TOK_CLASS ::= "class"
TOK_CONFIG ::= "config"
TOK_CONNECT ::= "connect"
TOK_CUSTOM ::= "custom"
TOK_CUSTOMDATA ::= "customData"
TOK_DEFAULT ::= "default"
TOK_DEF ::= "def"
TOK_DELETE ::= "delete"
TOK_DICTIONARY ::= "dictionary"
TOK_DISPLAYUNIT ::= "displayUnit"
TOK_DOC ::= "doc"
TOK_INHERITS ::= "inherits"
TOK_KIND ::= "kind"
TOK_NAMECHILDREN ::= "nameChildren"
TOK_NONE ::= "None"
TOK_OFFSET ::= "offset"
TOK_OVER ::= "over"
TOK_PAYLOAD ::= "payload"
TOK_PERMISSION ::= "permission"
TOK_PREFIX_SUBSTITUTIONS ::= "prefixSubstitutions"
TOK_PREPEND ::= "prepend"
TOK_PROPERTIES ::= "properties"
TOK_REFERENCES ::= "references"
TOK_RELOCATES ::= "relocates"
TOK_REL ::= "rel"
TOK_REORDER ::= "reorder"
TOK_ROOTPRIMS ::= "rootPrims"
TOK_SCALE ::= "scale"
TOK_SUBLAYERS ::= "subLayers"
TOK_SUFFIX_SUBSTITUTIONS ::= "suffixSubstitutions"
TOK_SPECIALIZES ::= "specializes"
TOK_SYMMETRYARGUMENTS ::= "symmetryArguments"
TOK_SYMMETRYFUNCTION ::= "symmetryFunction"
TOK_TIME_SAMPLES ::= "timeSamples"
TOK_UNIFORM ::= "uniform"
TOK_VARIANTSET ::= "variantSet"
TOK_VARIANTSETS ::= "variantSets"
TOK_VARIANTS ::= "variants"
TOK_VARYING ::= "varying"

TOK_ABSTRACT ::= "abstract"
TOK_RENAMES ::= "renames"
jesschimein commented 7 months ago

Filed as internal issue #USD-9487