1 // A Lark grammar for the XDR specification language based on
2 // https://tools.ietf.org/html/rfc4506 Section 6.3
4 declaration : "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
13 value : decimal_constant
14 | hexadecimal_constant
18 constant : decimal_constant | hexadecimal_constant | octal_constant
20 type_specifier : unsigned_hyper
35 unsigned_hyper : "unsigned" "hyper"
36 unsigned_long : "unsigned" "long"
37 unsigned_int : "unsigned" "int"
43 quadruple : "quadruple"
46 enum_type_spec : "enum" enum_body
48 enum_body : "{" ( identifier "=" value ) ( "," identifier "=" value )* "}"
50 struct_type_spec : "struct" struct_body
52 struct_body : "{" ( declaration ";" )+ "}"
54 union_type_spec : "union" union_body
56 union_body : switch_spec "{" case_spec+ [ default_spec ] "}"
58 switch_spec : "switch" "(" declaration ")"
60 case_spec : ( "case" value ":" )+ declaration ";"
62 default_spec : "default" ":" declaration ";"
64 constant_def : "const" identifier "=" value ";"
66 type_def : "typedef" declaration ";" -> typedef
67 | "enum" identifier enum_body ";" -> enum
68 | "struct" identifier struct_body ";" -> struct
69 | "union" identifier union_body ";" -> union
71 specification : definition*
73 definition : constant_def
79 // RPC program definitions not specified in RFC 4506
82 program_def : "program" identifier "{" version_def+ "}" "=" constant ";"
84 version_def : "version" identifier "{" procedure_def+ "}" "=" constant ";"
86 procedure_def : type_specifier identifier "(" type_specifier ")" "=" constant ";"
88 pragma_def : "pragma" directive identifier [ identifier ] ";"
90 directive : big_endian_directive
97 big_endian_directive : "big_endian"
98 exclude_directive : "exclude"
99 header_directive : "header"
100 pages_directive : "pages"
101 public_directive : "public"
102 skip_directive : "skip"
105 // XDR language primitives
108 identifier : /([a-z]|[A-Z])(_|[a-z]|[A-Z]|[0-9])*/
110 decimal_constant : /[\+-]?(0|[1-9][0-9]*)/
111 hexadecimal_constant : /0x([a-f]|[A-F]|[0-9])+/
112 octal_constant : /0[0-7]+/
114 PASSTHRU : "%" | "%" /.+/
117 %import common.C_COMMENT