Cleaned up AST

This commit is contained in:
2026-05-17 06:00:26 +02:00
parent dd647afd59
commit e89f5e805c
6 changed files with 15 additions and 38 deletions
+1 -3
View File
@@ -90,6 +90,4 @@ pub struct ExprPathSegment {
}
#[derive(Debug, Clone, Serialize)]
pub struct ExprPath {
pub segments: Vec<ExprPathSegment>,
}
pub struct ExprPath(pub Vec<ExprPathSegment>);
-4
View File
@@ -12,10 +12,6 @@ pub enum Statement {
VarDecl(VarDeclStmt),
Assign {
target: Expression,
value: Expression,
},
CompoundAssign {
target: Expression,
compound: String,
value: Expression,
+9 -13
View File
@@ -314,7 +314,6 @@ statement = _{
expr_stmt
| match_stmt
| assign_statement
| compound_assign_statement
| if_stmt
| while_stmt
| c_for_stmt
@@ -352,10 +351,6 @@ var_decl_statement = {
var_decl ~ ("=" ~ expr)? ~ semicolon
}
assign_statement = {
expr ~ "=" ~ expr ~ semicolon
}
increment_statement = {
expr ~ "++" ~ semicolon
}
@@ -365,7 +360,8 @@ decrement_statement = {
}
compound_assign = {
"+="
"="
| "+="
| "-="
| "/="
| "%="
@@ -376,7 +372,7 @@ compound_assign = {
| ">>="
}
compound_assign_statement = {
assign_statement = {
expr ~ compound_assign ~ expr ~ semicolon
}
@@ -517,12 +513,12 @@ postfix = {
// PREFIX EXPRESSIONS
// ------------------------------------------------------
deref_px = { "*" }
mut_ref_px = { "&" ~ mutable }
ref_px = { "&" }
new_px = { "new" ~ generics? }
not_px = { "!" }
neg_px = { "-" }
deref_px = { "*" }
mut_ref_px = { "&" ~ mutable }
ref_px = { "&" }
new_px = { "new" ~ generics? }
not_px = { "!" }
neg_px = { "-" }
prefix = {
deref_px
+1 -3
View File
@@ -193,9 +193,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ExprPath {
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
ast_ensure!(pair, Rule::expr_path => {
ast_expr!(ExprPath {
segments: collect_recovered(pair.into_inner()),
})
ast_expr!(ExprPath(collect_recovered(pair.into_inner())))
})
}
}
+2 -9
View File
@@ -90,6 +90,8 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
Rule::assign_statement => ast_expr!(Statement::Assign {
target: inner.next().unwrap().try_into(),
compound: Ok(inner.next().unwrap().as_str().trim().to_string())
as AstResult<'_, String>,
value: inner.next().unwrap().try_into(),
}),
Rule::match_stmt => ast_expr!(Statement::Match(
@@ -105,15 +107,6 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
.collect::<AstResult<'a, Vec<_>>>(),
)),
Rule::compound_assign_statement => {
ast_expr!(Statement::CompoundAssign {
target: inner.next().unwrap().try_into(),
compound: Ok(inner.next().unwrap().as_str().trim().to_string())
as AstResult<'_, String>,
value: inner.next().unwrap().try_into(),
})
}
Rule::increment_statement => {
ast_expr!(Statement::Increment(inner.next().unwrap().try_into()))
}