Skip to content
Permalink
d2393dbe1e
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
67 lines (53 sloc) 2.24 KB
// Grammar for Lua 5.1.x, based on the description at
// http://www.lua.org/manual/5.1/manual.html#8
//
// Operator precedence is described at:
// http://www.lua.org/manual/5.1/manual.html#2.5.6
//
// Please note that this grammar does not work with Gazelle yet, since it
// relies on features of Gazelle that aren't finished yet (most notably
// operator precedence parsing).
Name: /[:alpha:_][:alnum:_]* ~
(and|break|do|else|elseif|end|false|for|function|if|in|
local|nil|not|or|repeat|return|then|true|until|while)/
Number: /[0-9]* (\. [0-9]+)? ([Ee] [+-]? [0-9]+)? | 0x[0-9A-Fa-f]+/;
chunk -> (stat ";"?) * (laststat ";"?) ? ;
block -> chunk;
stat -> assign | funccall | do | while | repeat | if | for | funcdef |
localfunc | localvars;
assign -> varlist "=" explist;
funccall -> functioncall;
do -> "do" block "end";
while -> "while" exp "do" block "end";
repeat -> "repeat" block "until" exp;
if -> "if" exp "then" block ("elseif" exp "then" block)* ("else" block)? "end";
for -> "for" Name "=" exp "," exp ("," exp)? "do" block "end";
funcdef -> "function" funcname funcbody;
localfunc -> "local" "function" Name funcbody;
localvars -> "local" namelist ("=" explist)?
laststat -> "return" explist? | "break"
funcname -> Name +(.) (":" Name)?
varlist -> var +(,)
var -> Name | prefixexp "[" exp "]" | prefixexp "." Name
namelist -> Name +(,)
exp -> "nil" | "false" | "true" | Number | string | "..." | function |
prefixexp | tableconstructor | @expr(ops)
// All of the operators, listed by precedence.
@oplist ops: 2< "or",
2< "and",
2< "<" | 2< ">" | 2< "<=" | 2< ">=" | 2< "~=" | 2< "==",
2> "..",
2< "+" | < "-",
2< "*" | < "/" | < "%",
1< "not" | 1< "#" | 1< "-",
2> "^";
prefixexp -> var | functioncall | "(" exp ")"
functioncall -> prefixexp args | prefixexp ":" Name args
args -> "(" explist? ")" | tableconstructor | String
function -> "function" funcbody
funcbody -> "(" parlist? ")" block "end"
parlist -> namelist "," "..." | "..."
tableconstructor -> "{" fieldlist? "}"
fieldlist -> field +(fieldsep) fieldsep?
field -> "[" exp "]" "=" exp | Name "=" exp | exp
fieldsep: /[,;]/