Adapted parser and ast with grammar

This commit is contained in:
2026-05-17 02:30:03 +02:00
parent 020eebdaba
commit 50c98cf5f7
2 changed files with 119 additions and 69 deletions
+37 -36
View File
@@ -487,25 +487,11 @@ postfix = {
// PREFIX EXPRESSIONS
// ------------------------------------------------------
deref_px = {
"*"
}
mut_ref_px = {
"&" ~ mutable
}
ref_px = {
"&"
}
new_px = {
"new"
}
not_px = {
"!"
}
deref_px = { "*" }
mut_ref_px = { "&" ~ mutable }
ref_px = { "&" }
new_px = { "new" }
not_px = { "!" }
prefix = {
deref_px
@@ -516,30 +502,45 @@ prefix = {
}
// ------------------------------------------------------
// OPERATORS
// OPERATORS (Named individually for Pratt Parser configuration)
// ------------------------------------------------------
bin_op = {
"<="
| ">="
| "=="
| "!="
| "&&"
| "||"
| "+"
| "-"
| "*"
| "/"
| "%"
| "<"
| ">"
lte = { "<=" }
gte = { ">=" }
eq = { "==" }
neq = { "!=" }
and = { "&&" }
or = { "||" }
add = { "+" }
sub = { "-" }
mul = { "*" }
div = { "/" }
rem = { "%" }
lt = { "<" }
gt = { ">" }
bin_op = _{
lte
| gte
| eq
| neq
| and
| or
| add
| sub
| mul
| div
| rem
| lt
| gt
}
// ------------------------------------------------------
// EXPRESSIONS
// ------------------------------------------------------
// Top-level entry point for expressions
expr = { term ~ (bin_op ~ term)* }
// A term is anything that acts as a single unit in an operation
term = _{ prefix* ~ primary ~ postfix* }
// A term handles your Prefix and Postfix combinations around a core Primary
term = { prefix* ~ primary ~ postfix* }