Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
# -*- Mode: peg; -*-
Module <- { "Module" ({ Statement+ } / Statement)? }
Code <- { "Code" ({ Statement+ } / Statement)? }
CodeSingle <- { "Code" { "Statement" Expression } }
FunCode <- CodeSingle / Code
# Statements & Expression Types
Statement <- { "Statement" (Assignment / IfStm / WhileStm / ForStm / TryStm / ThrowStm / Function / ReturnStm / ExprStm / Break / Continue) }
Assignment <- { "Assignment" { Expression (Store / StoreLex) } }
ExprStm <- Expression
WhileStm <- { "WhileStm" { Expression Code } }
ForStm <- { "ForStm" { Store Expression Code } }
Break <- "break"
Continue <- "continue"
IfStm <- { "IfStm" { Expression Code Code? } }
ThrowStm <- { "ThrowStm" Expression }
ReturnStm <- { "ReturnStm" Expression }
TryStm <- { "TryStm" { Code CatchStm } }
CatchStm <- { "CatchStm" { Load Store Code } }
Expression <- Attribute / Logical / BinOp / Comparison / Call / Access / Lambda / Load / Unary / Value
# Logical Operators
Logical <- { "Logical" { Expression (LogicalTwo / LogicalMult) } }
LogicalTwo <- { LogicalOp LogicalRd }
LogicalMult<- { { LogicalOp LogicalRd }+ }
LogicalOp <- Atom
LogicalRd <- Expression
BinOp <- { "BinOp" Expression Atom Expression }
Comparison <- { "Comparison" Expression Atom Expression }
Unary <- { "Unary" { Atom Expression } }
Attribute <- { "Attribute" { Expression (LoadAttr / MethodCall)+ } }
LoadAttr <- { "LoadAttr" Atom }
LoadMethod <- { "LoadMethod" Atom }
MethodCall <- { "MethodCall" { LoadMethod CallParams } }
ScopeId <- { "ScopeId" Atom }
Lambda <- { "Lambda" { Params FunCode } }
/ { "Lambda" { ScopeId Params FunCode } }
Function <- { "Function" { Atom Params FunCode } }
/ { "Function" { ScopeId Atom Params FunCode } }
# Callable Parameter rules
Params <- { "Params" { Param+ }? }
Param <- { "Param" Atom }
# Call Site rules
Call <- { "Call" { Expression CallParams } }
CallParams <- { Expression+ }?
# Child access
Access <- { "Access" { Expression (Expression / Slice) } }
Slice <- { "Slice" { Expression Expression } }
# Value rules
Value <- { "Value" (Number / String / Boolean / List / Null) }
Number <- { "Number" Atom }
String <- { "String" Atom }
Boolean <- { "BOOL" Atom }
List <- { "List" { Expression* }? }
Null <- "null"
Load <- { "Load" Atom }
Store <- { "Store" Atom }
StoreLex <- { "StoreLex" Atom }
Atom <- !{ .* } .