-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Alexander McCord <11488393+alexmccord@users.noreply.github.com> Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
- Loading branch information
1 parent
71adace
commit 2e6a209
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ pages: | |
url: /profile | ||
- title: Library | ||
url: /library | ||
- title: Grammar | ||
url: /grammar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
permalink: /grammar | ||
title: Grammar | ||
toc: true | ||
--- | ||
|
||
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 ::= {stat [`;']} [laststat [`;']] | ||
block ::= chunk | ||
stat ::= varlist `=' explist | | ||
var compoundop exp | | ||
functioncall | | ||
do block end | | ||
while exp do block end | | ||
repeat block until exp | | ||
if exp then block {elseif exp then block} [else block] end | | ||
for binding `=' exp `,' exp [`,' exp] do block end | | ||
for bindinglist in explist do block end | | ||
function funcname funcbody | | ||
local function NAME funcbody | | ||
local bindinglist [`=' explist] | | ||
[export] type NAME [`<' GenericTypeList `>'] `=' Type | ||
laststat ::= return [explist] | break | continue | ||
funcname ::= NAME {`.' NAME} [`:' NAME] | ||
funcbody ::= `(' [parlist] `)' [`:' ReturnType] block end | ||
parlist ::= bindinglist [`,' `...'] | `...' | ||
explist ::= {exp `,'} exp | ||
namelist ::= NAME {`,' NAME} | ||
binding ::= NAME [`:' TypeAnnotation] | ||
bindinglist ::= binding [`,' bindinglist] (* equivalent of Lua 5.1 `namelist`, except with optional type annotations *) | ||
var ::= NAME | prefixexp `[' exp `]' | prefixexp `.' Name | ||
varlist ::= var {`,' var} | ||
prefixexp ::= var | functioncall | `(' exp `)' | ||
functioncall ::= prefixexp funcargs | prefixexp `:' NAME funcargs | ||
exp ::= (asexp | unop exp) { binop exp } | ||
ifelseexp ::= if exp then exp {elseif exp then exp} else exp | ||
asexp ::= simpleexp [`::' Type] | ||
simpleexp ::= NUMBER | STRING | nil | true | false | `...' | tableconstructor | function body | prefixexp | ifelseexp | ||
funcargs ::= `(' [explist] `)' | tableconstructor | STRING | ||
tableconstructor ::= `{' [fieldlist] `}' | ||
fieldlist ::= field {fieldsep field} [fieldsep] | ||
field ::= `[' exp `]' `=' exp | NAME `=' exp | exp | ||
fieldsep ::= `,' | `;' | ||
compoundop :: `+=' | `-=' | `*=' | `/=' | `%=' | `^=' | `..=' | ||
binop ::= `+' | `-' | `*' | `/' | `^' | `%' | `..' | `<' | `<=' | `>' | `>=' | `==' | `~=' | and | or | ||
unop ::= `-' | not | `#' | ||
SimpleType ::= | ||
nil | | ||
NAME[`.' NAME] [ `<' TypeList `>' ] | | ||
`typeof' `(' exp `)' | | ||
TableType | | ||
FunctionType | ||
Type ::= | ||
SimpleType [`?`] | | ||
SimpleType [`|` Type] | | ||
SimpleType [`&` Type] | ||
GenericTypeList ::= NAME [`...'] {`,' NAME [`...']} | ||
TypeList ::= Type [`,' TypeList] | ...Type | ||
ReturnType ::= Type | `(' TypeList `)' | ||
TableIndexer ::= `[' Type `]' `:' Type | ||
TableProp ::= NAME `:' Type | ||
TablePropOrIndexer ::= TableProp | TableIndexer | ||
PropList ::= TablePropOrIndexer {fieldsep TablePropOrIndexer} [fieldsep] | ||
TableType ::= `{' PropList `}' | ||
FunctionType ::= [`<' GenericTypeList `>'] `(' [TypeList] `)' `->` ReturnType | ||
``` |