File Index
Files and directories
Sign in
FILE

xdr.lark

File preview with syntax highlighting.

linux-6.19.14/tools/net/sunrpc/xdrgen/grammars/xdr.lark PLAIN TEXT
  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                        | hyper
 24                        | long
 25                        | int
 26                        | float
 27                        | double
 28                        | quadruple
 29                        | bool
 30                        | enum_type_spec
 31                        | struct_type_spec
 32                        | union_type_spec
 33                        | identifier
 34
 35unsigned_hyper          : "unsigned" "hyper"
 36unsigned_long           : "unsigned" "long"
 37unsigned_int            : "unsigned" "int"
 38hyper                   : "hyper"
 39long                    : "long"
 40int                     : "int"
 41float                   : "float"
 42double                  : "double"
 43quadruple               : "quadruple"
 44bool                    : "bool"
 45
 46enum_type_spec          : "enum" enum_body
 47
 48enum_body               : "{" ( identifier "=" value ) ( "," identifier "=" value )* "}"
 49
 50struct_type_spec        : "struct" struct_body
 51
 52struct_body             : "{" ( declaration ";" )+ "}"
 53
 54union_type_spec         : "union" union_body
 55
 56union_body              : switch_spec "{" case_spec+ [ default_spec ] "}"
 57
 58switch_spec             : "switch" "(" declaration ")"
 59
 60case_spec               : ( "case" value ":" )+ declaration ";"
 61
 62default_spec            : "default" ":" declaration ";"
 63
 64constant_def            : "const" identifier "=" value ";"
 65
 66type_def                : "typedef" declaration ";"                -> typedef
 67                        | "enum" identifier enum_body ";"          -> enum
 68                        | "struct" identifier struct_body ";"      -> struct
 69                        | "union" identifier union_body ";"        -> union
 70
 71specification           : definition*
 72
 73definition              : constant_def
 74                        | type_def
 75                        | program_def
 76                        | pragma_def
 77
 78//
 79// RPC program definitions not specified in RFC 4506
 80//
 81
 82program_def             : "program" identifier "{" version_def+ "}" "=" constant ";"
 83
 84version_def             : "version" identifier "{" procedure_def+ "}" "=" constant ";"
 85
 86procedure_def           : type_specifier identifier "(" type_specifier ")" "=" constant ";"
 87
 88pragma_def              : "pragma" directive identifier [ identifier ] ";"
 89
 90directive               : big_endian_directive
 91                        | exclude_directive
 92                        | header_directive
 93                        | pages_directive
 94                        | public_directive
 95                        | skip_directive
 96
 97big_endian_directive    : "big_endian"
 98exclude_directive       : "exclude"
 99header_directive        : "header"
100pages_directive         : "pages"
101public_directive        : "public"
102skip_directive          : "skip"
103
104//
105// XDR language primitives
106//
107
108identifier              : /([a-z]|[A-Z])(_|[a-z]|[A-Z]|[0-9])*/
109
110decimal_constant        : /[\+-]?(0|[1-9][0-9]*)/
111hexadecimal_constant    : /0x([a-f]|[A-F]|[0-9])+/
112octal_constant          : /0[0-7]+/
113
114PASSTHRU                : "%" | "%" /.+/
115%ignore PASSTHRU
116
117%import common.C_COMMENT
118%ignore C_COMMENT
119
120%import common.WS
121%ignore WS
~/ Read-only file preview.