1// A Lark grammar for the XDR specification language based on 2// https://tools.ietf.org/html/rfc4506 Section 6.3 3 4declaration : "opaque" identifier "[" value "]" -> fixed_length_opaque 5 | "opaque" identifier "<" [ value ] ">" -> variable_length_opaque 6 | "string" identifier "<" [ value ] ">" -> string 7 | type_specifier identifier "[" value "]" -> fixed_length_array 8 | type_specifier identifier "<" [ value ] ">" -> variable_length_array 9 | type_specifier "*" identifier -> optional_data 10 | type_specifier identifier -> basic 11 | "void" -> void 12 13value : decimal_constant 14 | hexadecimal_constant 15 | octal_constant 16 | identifier 17 18constant : decimal_constant | hexadecimal_constant | octal_constant 19 20type_specifier : unsigned_hyper 21 | unsigned_long 22 | unsigned_int 23 | unsigned_short 24 | hyper 25 | long 26 | int 27 | short 28 | float 29 | double 30 | quadruple 31 | bool 32 | enum_type_spec 33 | struct_type_spec 34 | union_type_spec 35 | identifier 36 37unsigned_hyper : "unsigned" "hyper" 38unsigned_long : "unsigned" "long" 39unsigned_int : "unsigned" "int" 40unsigned_short : "unsigned" "short" 41hyper : "hyper" 42long : "long" 43int : "int" 44short : "short" 45float : "float" 46double : "double" 47quadruple : "quadruple" 48bool : "bool" 49 50enum_type_spec : "enum" enum_body 51 52enum_body : "{" ( identifier "=" value ) ( "," identifier "=" value )* "}" 53 54struct_type_spec : "struct" struct_body 55 56struct_body : "{" ( declaration ";" )+ "}" 57 58union_type_spec : "union" union_body 59 60union_body : switch_spec "{" case_spec+ [ default_spec ] "}" 61 62switch_spec : "switch" "(" declaration ")" 63 64case_spec : ( "case" value ":" )+ declaration ";" 65 66default_spec : "default" ":" declaration ";" 67 68constant_def : "const" identifier "=" value ";" 69 70type_def : "typedef" declaration ";" -> typedef 71 | "enum" identifier enum_body ";" -> enum 72 | "struct" identifier struct_body ";" -> struct 73 | "union" identifier union_body ";" -> union 74 75specification : definition* 76 77definition : constant_def 78 | type_def 79 | program_def 80 | pragma_def 81 | passthru_def 82 83passthru_def : PASSTHRU 84 85// 86// RPC program definitions not specified in RFC 4506 87// 88 89program_def : "program" identifier "{" version_def+ "}" "=" constant ";" 90 91version_def : "version" identifier "{" procedure_def+ "}" "=" constant ";" 92 93procedure_def : type_specifier identifier "(" type_specifier ")" "=" constant ";" 94 95pragma_def : "pragma" directive identifier [ identifier ] ";" 96 97directive : big_endian_directive 98 | exclude_directive 99 | header_directive 100 | pages_directive 101 | public_directive 102 | skip_directive 103 104big_endian_directive : "big_endian" 105exclude_directive : "exclude" 106header_directive : "header" 107pages_directive : "pages" 108public_directive : "public" 109skip_directive : "skip" 110 111// 112// XDR language primitives 113// 114 115identifier : /([a-z]|[A-Z])(_|[a-z]|[A-Z]|[0-9])*/ 116 117decimal_constant : /[\+-]?(0|[1-9][0-9]*)/ 118hexadecimal_constant : /0x([a-f]|[A-F]|[0-9])+/ 119octal_constant : /0[0-7]+/ 120 121PASSTHRU : /%.*/ 122 123%import common.C_COMMENT 124%ignore C_COMMENT 125 126%import common.WS 127%ignore WS 128