Cleaned up AST
This commit is contained in:
@@ -90,6 +90,4 @@ pub struct ExprPathSegment {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ExprPath {
|
||||
pub segments: Vec<ExprPathSegment>,
|
||||
}
|
||||
pub struct ExprPath(pub Vec<ExprPathSegment>);
|
||||
|
||||
@@ -12,10 +12,6 @@ pub enum Statement {
|
||||
|
||||
VarDecl(VarDeclStmt),
|
||||
Assign {
|
||||
target: Expression,
|
||||
value: Expression,
|
||||
},
|
||||
CompoundAssign {
|
||||
target: Expression,
|
||||
compound: String,
|
||||
value: Expression,
|
||||
|
||||
+9
-13
@@ -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
|
||||
|
||||
@@ -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())))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
|
||||
+2
-6
@@ -219,7 +219,7 @@ impl GetRust for [Prefix] {
|
||||
|
||||
impl GetRust for ExprPath {
|
||||
fn get_rust(&self) -> String {
|
||||
self.segments
|
||||
self.0
|
||||
.iter()
|
||||
.map(ExprPathSegment::get_rust)
|
||||
.collect::<Vec<_>>()
|
||||
@@ -601,11 +601,7 @@ impl ToRust for Statement {
|
||||
cg.add_indentedln(&format!("let {}{};", decl.get_rust(), init));
|
||||
}
|
||||
|
||||
Statement::Assign { target, value } => {
|
||||
cg.add_indentedln(&format!("{} = {};", target.get_rust(), value.get_rust(),));
|
||||
}
|
||||
|
||||
Statement::CompoundAssign {
|
||||
Statement::Assign {
|
||||
target,
|
||||
compound,
|
||||
value,
|
||||
|
||||
Reference in New Issue
Block a user