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

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