Improve Grammar documentation (#315)

This commit is contained in:
JohnnyMorganz 2022-01-20 16:27:19 +00:00 committed by GitHub
parent 49ce5096a4
commit 4e5ff99582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -7,8 +7,6 @@ classes: wide
This is the complete syntax grammar for Luau in EBNF. More information about the terminal nodes String and Number
is available in the [syntax section](syntax).
> Note: this grammar is currently missing type pack syntax for generic arguments
```ebnf
chunk = block
block = {stat [';']} [laststat [';']]
@ -24,12 +22,12 @@ stat = varlist '=' explist |
'function' funcname funcbody |
'local' 'function' NAME funcbody |
'local' bindinglist ['=' explist] |
['export'] 'type' NAME ['<' GenericTypeList '>'] '=' Type
['export'] 'type' NAME ['<' GenericTypeParameterList '>'] '=' Type
laststat = 'return' [explist] | 'break' | 'continue'
funcname = NAME {'.' NAME} [':' NAME]
funcbody = '(' [parlist] ')' [':' ReturnType] block 'end'
funcbody = ['<' GenericTypeParameterList '>'] '(' [parlist] ')' [':' ReturnType] block 'end'
parlist = bindinglist [',' '...'] | '...'
explist = {exp ','} exp
@ -60,19 +58,27 @@ unop = '-' | 'not' | '#'
SimpleType =
'nil' |
NAME ['.' NAME] [ '<' TypeList '>' ] |
SingletonType |
NAME ['.' NAME] [ '<' [TypeParams] '>' ] |
'typeof' '(' exp ')' |
TableType |
FunctionType
SingletonType = STRING | 'true' | 'false'
Type =
SimpleType ['?'] |
SimpleType ['|' Type] |
SimpleType ['&' Type]
GenericTypeList = NAME ['...'] {',' NAME ['...']}
GenericTypePackParameter = NAME '...' ['=' (TypePack | VariadicTypePack | GenericTypePack)]
GenericTypeParameterList = NAME ['=' Type] [',' GenericTypeParameterList] | GenericTypePackParameter {',' GenericTypePackParameter}
TypeList = Type [',' TypeList] | '...' Type
ReturnType = Type | '(' TypeList ')'
TypeParams = (Type | TypePack | VariadicTypePack | GenericTypePack) [',' TypeParams]
TypePack = '(' [TypeList] ')'
GenericTypePack = NAME '...'
VariadicTypePack = '...' Type
ReturnType = Type | TypePack
TableIndexer = '[' Type ']' ':' Type
TableProp = NAME ':' Type
TablePropOrIndexer = TableProp | TableIndexer