Skip to content

Instantly share code, notes, and snippets.

@donovanhide
Created October 13, 2015 13:03
Show Gist options
  • Save donovanhide/7bbe51925a065e762056 to your computer and use it in GitHub Desktop.
Save donovanhide/7bbe51925a065e762056 to your computer and use it in GitHub Desktop.
package main
type XDR Peg {
}
CompilationUnit <- Specification EOT
Declaration <- (TypeSpecifier Identifier) / (TypeSpecifier Identifier LBRK Value RBRK) / (TypeSpecifier Identifier LT Value? GT) / (OPAQUE Identifier LBRK Value RBRK) / (OPAQUE Identifier LT Value? GT) / (STRING Identifier LT Value? GT) / (TypeSpecifier STAR Identifier) / VOID
Value <- Constant / Identifier
Constant <- DecimalConstant / HexadecimalConstant / OctalConstant
TypeSpecifier <- (UNSIGNED? INT) / (UNSIGNED? HYPER) / FLOAT / DOUBLE / QUADRUPLE / BOOL / EnumTypeSpec / StructTypeSpec / UnionTypeSpec / Identifier
EnumTypeSpec <- ENUM EnumBody
EnumBody <- LWING (Identifier EQ Value) (COMMA Identifier EQ Value)* RWING
StructTypeSpec <- STRUCT StructBody
StructBody <- LWING (Declaration SEMI)+ RWING
UnionTypeSpec <- UNION UnionBody
UnionBody <- SWITCH LPAR Declaration RPAR LWING CaseSpec+ (DEFAULT COLON Declaration SEMI)? RWING
CaseSpec <- (CASE Value COLON)+ Declaration SEMI
ConstantDef <- CONST Identifier EQ Constant SEMI
TypeDef <- ((TYPEDEF Declaration) / (ENUM Identifier EnumBody) / (STRUCT Identifier StructBody) / (UNION Identifier UnionBody)) SEMI
Definition <- TypeDef / ConstantDef
Specification <- Definition*
DecimalConstant <- [1-9][0-9]*
HexadecimalConstant <- HexPrefix HexDigit+
OctalConstant <- '0' [0-7]*
HexPrefix <- '0x' / '0X'
HexDigit <- [a-f] / [A-F] / [0-9]
BOOL <- 'bool' !IdChar Spacing
CASE <- 'case' !IdChar Spacing
CONST <- 'const' !IdChar Spacing
DEFAULT <- 'default' !IdChar Spacing
DOUBLE <- 'double' !IdChar Spacing
ENUM <- 'enum' !IdChar Spacing
FLOAT <- 'float' !IdChar Spacing
HYPER <- 'hyper' !IdChar Spacing
INT <- 'int' !IdChar Spacing
QUADRUPLE <- 'quadruple' !IdChar Spacing
STRUCT <- 'struct' !IdChar Spacing
SWITCH <- 'switch' !IdChar Spacing
STRING <- 'string' !IdChar Spacing
TYPEDEF <- 'typedef' !IdChar Spacing
OPAQUE <- 'opaque' !IdChar Spacing
UNION <- 'union' !IdChar Spacing
UNSIGNED <- 'unsigned' !IdChar Spacing
VOID <- 'void' !IdChar Spacing
COLON <- ':' Spacing
COMMA <- ',' Spacing
EQ <- '=' Spacing
LBRK <- '[' Spacing
RBRK <- ']' Spacing
LPAR <- '(' Spacing
RPAR <- ')' Spacing
LWING <- '{' Spacing
RWING <- '}' Spacing
LT <- '<' Spacing
GT <- '>' Spacing
STAR <- '*' Spacing
SEMI <- ';' Spacing
EOT <- !.
Spacing <- (WhiteSpace / LongComment / LineComment / Pragma)*
WhiteSpace <- [ \n\r\t]
LongComment <- '/*' (!'*/'.)* '*/'
LineComment <- '//' (!'\n' .)*
Pragma <- '#' (!'\n' .)*
Keyword <- 'bool'/'case'/'const'/'default'/ 'double'/'quadruple'/'enum'/'float'/'hyper'/'int'/'opaque'/'string'/'struct'/'switch'/'typedef'/'union'/'unsigned'/'void'
Identifier <- !Keyword IdNondigit IdChar* Spacing
IdNondigit <- [a-z] / [A-Z] / [_]
IdChar <- [a-z] / [A-Z] / [0-9] / [_]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment