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)] #[derive(Debug, Clone, Serialize)]
pub struct ExprPath { pub struct ExprPath(pub Vec<ExprPathSegment>);
pub segments: Vec<ExprPathSegment>,
}
-4
View File
@@ -12,10 +12,6 @@ pub enum Statement {
VarDecl(VarDeclStmt), VarDecl(VarDeclStmt),
Assign { Assign {
target: Expression,
value: Expression,
},
CompoundAssign {
target: Expression, target: Expression,
compound: String, compound: String,
value: Expression, value: Expression,
+3 -7
View File
@@ -314,7 +314,6 @@ statement = _{
expr_stmt expr_stmt
| match_stmt | match_stmt
| assign_statement | assign_statement
| compound_assign_statement
| if_stmt | if_stmt
| while_stmt | while_stmt
| c_for_stmt | c_for_stmt
@@ -352,10 +351,6 @@ var_decl_statement = {
var_decl ~ ("=" ~ expr)? ~ semicolon var_decl ~ ("=" ~ expr)? ~ semicolon
} }
assign_statement = {
expr ~ "=" ~ expr ~ semicolon
}
increment_statement = { increment_statement = {
expr ~ "++" ~ semicolon expr ~ "++" ~ semicolon
} }
@@ -365,7 +360,8 @@ decrement_statement = {
} }
compound_assign = { compound_assign = {
"+=" "="
| "+="
| "-=" | "-="
| "/=" | "/="
| "%=" | "%="
@@ -376,7 +372,7 @@ compound_assign = {
| ">>=" | ">>="
} }
compound_assign_statement = { assign_statement = {
expr ~ compound_assign ~ expr ~ semicolon expr ~ compound_assign ~ expr ~ semicolon
} }
+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> { fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
ast_ensure!(pair, Rule::expr_path => { ast_ensure!(pair, Rule::expr_path => {
ast_expr!(ExprPath { ast_expr!(ExprPath(collect_recovered(pair.into_inner())))
segments: 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 { Rule::assign_statement => ast_expr!(Statement::Assign {
target: inner.next().unwrap().try_into(), 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(), value: inner.next().unwrap().try_into(),
}), }),
Rule::match_stmt => ast_expr!(Statement::Match( 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<_>>>(), .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 => { Rule::increment_statement => {
ast_expr!(Statement::Increment(inner.next().unwrap().try_into())) ast_expr!(Statement::Increment(inner.next().unwrap().try_into()))
} }
+2 -6
View File
@@ -219,7 +219,7 @@ impl GetRust for [Prefix] {
impl GetRust for ExprPath { impl GetRust for ExprPath {
fn get_rust(&self) -> String { fn get_rust(&self) -> String {
self.segments self.0
.iter() .iter()
.map(ExprPathSegment::get_rust) .map(ExprPathSegment::get_rust)
.collect::<Vec<_>>() .collect::<Vec<_>>()
@@ -601,11 +601,7 @@ impl ToRust for Statement {
cg.add_indentedln(&format!("let {}{};", decl.get_rust(), init)); cg.add_indentedln(&format!("let {}{};", decl.get_rust(), init));
} }
Statement::Assign { target, value } => { Statement::Assign {
cg.add_indentedln(&format!("{} = {};", target.get_rust(), value.get_rust(),));
}
Statement::CompoundAssign {
target, target,
compound, compound,
value, value,