Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
70 lines (57 sloc)
2.42 KB
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
# -*- 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 <- !{ .* } . |