// 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 | 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 = { Ident ~ "damn " ~ Type } Ident = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* } // If, Else If, Else IfKwd = _{ "is" } ElseIfKwd = _{ "but" } ElseKwd = _{ "isn\'t" } 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 | Call | Term } Literal = _{ Array | Number | String | Boolean | Null } Term = _{ Literal | Ident | "(" ~ Expr ~ ")" } // Possible values, in order of matching complexity: // (Type...,) >> Ident // Ident >> Ident // Ident // Example: // (Number >> Array,) >> Array // (String, Number,) >> Dictionary // Number TGeneric = _{ (Type ~ ",")+ } Type = { ("(" ~ TGeneric ~ ")" | Ident) ~ ">>" ~ Ident | Ident } // Throw, Try, Catch Throw = { "shoot " ~ Expr } Catch = { "wall" ~ Ident? ~ Block } Try = { "test" ~ Block } TryCatch = { Try ~ Catch } // Modules ImportKwd = _{ "weneed" | "bringme" } ImportPath = _{ Ident ~ ("." ~ Ident)* } Import = { ImportKwd ~ "r/" ~ ImportPath } // Modifiers AccessibilityModifier = { "bar " } // Variables VariableMods = { AccessibilityModifier* } VariableKwd = _{ "meth" } 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 = { "⊕" } Modulus = { "⨊" } // Other Assignment = _{ "∑" } Negation = { "¡" } UnaryOperator = { Add | Subtract | Negation } ConditionalOperator = { Equality | Inequality | GreaterThan | GreaterThanOrEqual | LessThan | LessThanOrEqual } MathOperator = { Add | Subtract | Multiply | Divide | XOR | Modulus } // Class ClassKwd = _{ "school " } Class = { ClassKwd ~ Ident ~ Block } // Types // haha char* String = ${ Quote ~ Char* ~ Quote } // not type 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 } Array = { "[" ~ (Expr ~ ",")* ~ "]" } /// Only for syntax errors in array accesses. not an actual type 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 = _{ "\"" | "\'" }