|
| 1 | +
|
| 2 | +newline = "\r\n" | "\n" | "\r" ; (*CRLF for windows, LF for unix and macos X, CR for Mac up through version 9*) |
| 3 | +letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" |
| 4 | + | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" |
| 5 | + | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" |
| 6 | + | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"; |
| 7 | +
|
| 8 | +digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; |
| 9 | +
|
| 10 | +characters = "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "-" | "_" | "=" |
| 11 | + | "+" | "[" | "]" | "{" | "}" | ";" | ":" | "'" | "\"" | "," | "." | "<" | ">" |
| 12 | + | "/" | "?" | "\\" | "|" | "`" | "~" | " "; |
| 13 | +
|
| 14 | +space = " " | "\t" |
| 15 | + |
| 16 | +Comment = { ( "///" | "//" ) { letter | digit | characters } newline }; |
| 17 | +
|
| 18 | +(*------------------ identifier.rs ----------------------*) |
| 19 | +Identifier = (letter | "$" | "_" ) { letter | digit | "_"}; |
| 20 | +
|
| 21 | +ExternalIdentifier = Identifier { "::" Identifier }; |
| 22 | +
|
| 23 | +(* todo: typed identifier *) |
| 24 | +
|
| 25 | +(*------------------ types.rs ----------------------*) |
| 26 | +
|
| 27 | +(*todo: BasicType EBNF is different from the implementation*) |
| 28 | +TypeName = { "*" } ( BasicType | ArrayType | ClosureType | TupleType ) ; |
| 29 | +BasicType = ExternalIdentifier GenericParamDef?; |
| 30 | +ArrayType = "[" TypeName "]"; |
| 31 | +GenericTypeDef = "<" { "|" Identifier ( ":" MultiTrait )? } ">"; |
| 32 | +GenericParamDef = "<" TypeName { "|" TypeName } ">"; |
| 33 | +(*todo: support FunctionDef in the future*) |
| 34 | +TraitDef = "pub"? "trait" Identifier GenericTypeDef? ( ":" TypeAdd )? "{" {FunctionDef} "}"; |
| 35 | +TypeAdd = TypeName { "+" TypeName }; |
| 36 | +MultiTrait = TypeAdd; |
| 37 | +TupleType = "(" (TypeName { "," TypeName })? ")"; |
| 38 | +ClosureType = "|" TypeName {"," TypeName} "|=>" TypeName; |
0 commit comments