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