// Main rule Program = _{ SOI ~ Statements? ~ EOI } // Comment and whitespace COMMENT = _{ ("#*" ~ (!"*#" ~ ANY)* ~ "*#") | ("#" ~ (!NEWLINE ~ ANY)*) } WHITESPACE = _{ " " | "\t" } // Fundimental Language Components /// Represents any amount of statements seperated by a NEWLINE Statements = _{ NEWLINE* ~ (Statement ~ NEWLINE+)* ~ Statement? } Statement = { Loop | Break | Function | Call | TryCatch | Throw | Import | Module | Variable | AssignmentStatement | IfBlock | Class | Return } // Loops LoopKwd = _{ "repeatdatshid" } Loop = { LoopKwd ~ Block } Break = { "sthu" } // Functions FunctionKwd = _{ "callmeonmycellphone " } Function = { FunctionMods ~ FunctionKwd ~ Declaration ~ FunctionArgs ~ Block } FunctionMod = { "debug " | AccessibilityModifier } FunctionMods = { FunctionMod* } FunctionArg = _{ Declaration ~ "," } FunctionArgs = { "(" ~ FunctionArg* ~ ")" } Return = { "spez " ~ Expr } // Identifiers and Declarations Declaration = { TypedIdent | Ident } Ident = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* } // If, Else If, Else IfKwd = _{ "is" } ElseIfKwd = _{ "but" } ElseKwd = _{ "isnt" } If = { IfKwd ~ Expr ~ Block } ElseIf = { ElseIfKwd ~ Expr ~ Block } Else = { ElseKwd ~ Block } IfBlock = { If ~ ElseIf* ~ Else? } // Calls Call = { "call " ~ Ident ~ CallArgs? } CallArg = _{ Expr ~ "," } CallArgs = { "(" ~ CallArg* ~ ")" } // Exprs ConditionalExpr = { Term ~ (ConditionalOperator ~ Term)+ } BinaryExpr = { Term ~ (MathOperator ~ Term)+ } IndexExpr = { Term ~ "[" ~ Index ~ "]" } Index = { BinaryExpr | UNumber | String | Ident | "(" ~ Index ~ ")" } Expr = { ConditionalExpr | BinaryExpr | IndexExpr | Term } Literal = _{ Number | String | Foolean | Boolean | Null } Term = _{ Literal | Call | Ident | "(" ~ Expr ~ ")" } // Types TypedIdentKwd = _{ "damn " } TypedIdent = _{ Ident ~ TypedIdentKwd ~ Type } TypeArray = { "[]" } Type = { Ident ~ TypeArray? } // Throw, Try, Catch Throw = { "shoot " ~ Expr } Catch = { "wall" ~ Ident? ~ Block } Try = { "test" ~ Block } TryCatch = { Try ~ Catch } // Modules ImportKwd = _{ "weneed" | "bringme" } ModuleKwd = _{ "subreddit" } Module = { ModuleKwd ~ "r/" ~ Ident } Import = { ImportKwd ~ String } // Modifiers AccessibilityModifier = { "bar " } // Variables VariableKwd = _{ "meth" } VariableMods = { AccessibilityModifier* } Variable = { VariableMods ~ VariableKwd ~ Declaration ~ Assignment ~ Expr } AssignmentStatement = { Ident ~ Assignment ~ Expr } // Operators // Conditional Equality = { "⅀" } Inequality = { "≠" } GreaterThan = { ">" } GreaterThanOrEqual = { "⋝" } LessThan = { "<" } LessThanOrEqual = { "⋜" } // Math Add = { "⨋" } /// Not U+2012 (figure dash) but U+2013 (en dash) Subtract = { "–" } Multiply = { "⋇" } Divide = { "⎲" } XOR = { "⊕" } // Other Assignment = _{ "∑" } Negation = { "¡" } UnaryOperator = { Add | Subtract | Negation } ConditionalOperator = { Equality | Inequality | GreaterThan | GreaterThanOrEqual | LessThan | LessThanOrEqual } MathOperator = { Add | Subtract | Multiply | Divide | XOR } // Class ClassKwd = _{ "school " } Class = { ClassKwd ~ Ident ~ Block } // Primitives String = ${ Quote ~ StringContent ~ Quote } StringContent = _{ Char* } Char = _{ !("\"" | "\\") ~ ANY | "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t") | "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4}) | "\\" ~ ("x" ~ ASCII_HEX_DIGIT{2}) } Sign = _{ Add | Subtract } Magnitude = { (ASCII_DIGIT+ ~ ".")? ~ ASCII_DIGIT+ } Number = ${ Sign? ~ Magnitude } /// Only for syntax errors ( constant indexes ), must convert to the "Number" type of the AST UNumber = ${ Add? ~ Magnitude } Null = { "wat" } True = { "Yup" } False = { "Nope" } Boolean = { True | False } FooleanNull = { "Dunno" } FooleanIOFalure = { "Huh" } FooleanRandom = { "Yeet" } Foolean = { True | False | FooleanNull | FooleanIOFalure | FooleanRandom } // Misc Block = { "{" ~ Statements? ~ "}" } Quote = _{ "\"" | "\'" }