|
| 1 | +``` |
| 2 | +binding = NAME [':' type] |
| 3 | +bindings = binding {',' binding} |
| 4 | +
|
| 5 | +typebinding = 'type' NAME ['<' generictypeswithdefaults '>'] '=' type |
| 6 | +
|
| 7 | +path = '@' [NAME] |
| 8 | + | path '/' NAME |
| 9 | +import = 'import' binding '=' path |
| 10 | +export = 'export' bindings '=' exprs |
| 11 | +
|
| 12 | +-- we could just pick one, i guess? |
| 13 | +fnword = 'fn' | 'function' |
| 14 | +
|
| 15 | +block = {stat [';'] NEWLINE} [expr] |
| 16 | +stat = var '=' expr |
| 17 | + | var compoundop expr |
| 18 | + | 'while' expr 'do' block 'end' |
| 19 | + | 'repeat' block 'until' expr |
| 20 | + | 'for' bindings 'in' exprs 'do' block 'end' |
| 21 | + | fnword funcname ['<' generictypes '>'] '(' [parameters] ')' [ ':' type] block 'end' |
| 22 | + | 'module' binding 'do' properties 'end' |
| 23 | + | 'local' bindings '=' exprs |
| 24 | + | ['export'] typebinding |
| 25 | + | import | export |
| 26 | + | expr |
| 27 | + | 'break' | 'continue' |
| 28 | + | 'return' [expr] |
| 29 | +
|
| 30 | +varroot = NAME | '(' expr ')' |
| 31 | +varsuffix = [':' NAME] '(' [exprs] ')' | '.' NAME | '[' expr ']' |
| 32 | +var = varroot {varsuffix} |
| 33 | +vars = var {',' var} |
| 34 | +
|
| 35 | +expr = unop expr { binop expr } |
| 36 | + | 'do' block 'end' |
| 37 | + | 'if' expr 'then' block {'elseif' expr 'then' block} ['else' block] 'end' |
| 38 | + | fnword ['<' generictypes '>'] '(' [parameters] ')' [ ':' type] block 'end' |
| 39 | + | simpleexpr '::' type |
| 40 | + | simpleexpr |
| 41 | +simpleexpr = var |
| 42 | + | literal |
| 43 | +exprs = expr {separator expr} [separator] |
| 44 | +separator = ',' | ';' |
| 45 | +
|
| 46 | +literal = NUMBER |
| 47 | + | STRING |
| 48 | + | 'nil' |
| 49 | + | 'true' |
| 50 | + | 'false' |
| 51 | + | table |
| 52 | + | array |
| 53 | +literals = literal {',' literal} |
| 54 | +
|
| 55 | +array = '[' [exprs] ']' |
| 56 | +table = '{' [properties] '}' |
| 57 | +properties = property {separator property} [separator] |
| 58 | +property = '[' expr ']' '=' expr |
| 59 | + | NAME '=' expr |
| 60 | + | typebinding |
| 61 | +
|
| 62 | +compoundop :: '+=' | '-=' | '*=' | '/=' | '//=' | '%=' | '^=' | '..=' |
| 63 | +binop = '+' | '-' | '*' | '/' | '//' | '^' | '%' | '..' | '<' | '<=' | '>' | '>=' | '==' | '~=' | 'and' | 'or' |
| 64 | +unop = '-' | 'not' | '#' |
| 65 | +
|
| 66 | +type = [simpletype {'?'}] {'|' simpletype {'?'}} |
| 67 | + | [simpletype {'?'}] {'&' simpletype {'?'}} |
| 68 | +types = type {',' type} |
| 69 | +
|
| 70 | +generictype = NAME |
| 71 | +generictypes = generictype {',' generictype} |
| 72 | +generictypewithdefault = generictype ['=' type] |
| 73 | +generictypeswithdefaults = generictypewithdefault {',' generictypeswithdefaults} |
| 74 | +
|
| 75 | +tabletype = '{' [proplist] '}' |
| 76 | +propertytypes = propertytypeorindexer {separator propertytypeorindexer} [separator] |
| 77 | +propertytype = NAME ':' type |
| 78 | +indexer = '[' type ']' ':' type |
| 79 | +propertytypeorindexer = ['read' | 'write'] (propertytype | indexer) |
| 80 | + | 'type' NAME ['<' generictypes '>'] |
| 81 | +proplist = propertytypeorindexer {',' propertytypeorindexer} |
| 82 | +
|
| 83 | +singleton = STRING | 'true' | 'false' |
| 84 | +simpletype = 'nil' |
| 85 | + | singleton |
| 86 | + | 'boolean' |
| 87 | + | 'string' |
| 88 | + | 'number' |
| 89 | + | '(' types ')' |
| 90 | + | ['<' generictypes '>'] '(' types ')' '->' type |
| 91 | + | tabletype |
| 92 | + | '[' type ']' |
| 93 | +``` |
0 commit comments