Cleanup TypeAnnotation definition

This commit is contained in:
JohnnyMorganz 2021-12-02 11:48:51 +00:00
parent 219ab146b1
commit de50a36404

View file

@ -19,7 +19,7 @@ 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 `>'] `=' typeannotation [export] type Name [`<' GenericTypeList `>'] `=' TypeAnnotation
laststat ::= return [explist] | break | continue laststat ::= return [explist] | break | continue
@ -29,14 +29,14 @@ parlist ::= bindinglist [`,' `...'] | `...'
explist ::= {exp `,'} exp explist ::= {exp `,'} exp
namelist ::= Name {`,' Name} namelist ::= Name {`,' Name}
binding ::= Name [`:' typeannotation] binding ::= Name [`:' TypeAnnotation]
bindinglist ::= (binding | `...') [`,' bindinglist] bindinglist ::= (binding | `...') [`,' bindinglist]
subexpr ::= (asexp | unop subexpr) { binop subexpr } subexpr ::= (asexp | unop subexpr) { binop subexpr }
ifelseexp ::= if exp then exp {elseif exp then exp} else exp ifelseexp ::= if exp then exp {elseif exp then exp} else exp
prefixexp ::= NAME | '(' expr ')' prefixexp ::= NAME | '(' expr ')'
primaryexp ::= prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } primaryexp ::= prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs }
asexp ::= simpleexp [`::' typeannotation] asexp ::= simpleexp [`::' TypeAnnotation]
simpleexp ::= NUMBER | STRING | NIL | true | false | ... | constructor | FUNCTION body | primaryexp | ifelseexp simpleexp ::= NUMBER | STRING | NIL | true | false | ... | constructor | FUNCTION body | primaryexp | ifelseexp
funcargs ::= `(' [explist] `)' | tableconstructor | String funcargs ::= `(' [explist] `)' | tableconstructor | String
@ -49,14 +49,17 @@ fieldlist ::= field {fieldsep field} [fieldsep]
field ::= `[' exp `]' `=' exp | Name `=' exp | exp field ::= `[' exp `]' `=' exp | Name `=' exp | exp
fieldsep ::= `,' | `;' fieldsep ::= `,' | `;'
typeannotation ::= SimpleTypeAnnotation ::=
nil | nil |
Name[`.' Name] [`<' namelist `>'] | Name[`.' Name] [ `<' TypeAnnotation [`,' ...] `>' ] |
`{' [PropList] `}' | `typeof' `(' expr `)' |
`(' [TypeList] `)' `->` ReturnType `{' [PropList] `}' |
`typeof` typeannotation FunctionTypeAnnotation
typeannotation ::= nil | Name[`.' Name] [ `<' typeannotation [`,' ...] `>' ] | `typeof' `(' expr `)' | `{' [PropList] `}' | [`<' GenericTypeList `>'] `(' [TypeList] `)' `->` ReturnType TypeAnnotation ::=
SimpleTypeAnnotation [`?`] |
SimpleTypeAnnotation [`|` TypeAnnotation] |
SimpleTypeAnnotation [`&` TypeAnnotation]
GenericTypeList ::= NAME [`...'] {`,' NAME} GenericTypeList ::= NAME [`...'] {`,' NAME}
TypeList ::= TypeAnnotation [`,' TypeList] | ...TypeAnnotation TypeList ::= TypeAnnotation [`,' TypeList] | ...TypeAnnotation
@ -67,5 +70,4 @@ TablePropOrIndexer ::= TableProp | TableIndexer
PropList ::= TablePropOrIndexer {fieldsep TablePropOrIndexer} [fieldsep] PropList ::= TablePropOrIndexer {fieldsep TablePropOrIndexer} [fieldsep]
TableTypeAnnotation ::= `{' PropList `}' TableTypeAnnotation ::= `{' PropList `}'
FunctionTypeAnnotation ::= [`<' GenericTypeList `>'] `(' [TypeList] `)' `->` ReturnType FunctionTypeAnnotation ::= [`<' GenericTypeList `>'] `(' [TypeList] `)' `->` ReturnType
``` ```