Increment and decrement via ++ or --
This commit is contained in:
@@ -46,7 +46,7 @@ pub class Application {
|
||||
void tick(self mut*) {
|
||||
self.logger.info("tick");
|
||||
|
||||
self.ticks += 1;
|
||||
self.ticks++;
|
||||
|
||||
var task = task::create_task("background-job");
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ pub mod event;
|
||||
void main() {
|
||||
var mut app_instance = new app::Application("mist-app");
|
||||
|
||||
i++;
|
||||
|
||||
// greeting::register(&mut app_instance);
|
||||
// statistics::register(&mut app_instance);
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@ pub enum Statement {
|
||||
Return(Option<Expression>),
|
||||
Break,
|
||||
Continue,
|
||||
|
||||
Increment(Expression),
|
||||
Decrement(Expression),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@@ -324,6 +324,8 @@ statement = _{
|
||||
| continue_stmt
|
||||
| block
|
||||
| var_decl_statement
|
||||
| increment_statement
|
||||
| decrement_statement
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
@@ -354,6 +356,14 @@ assign_statement = {
|
||||
expr ~ "=" ~ expr ~ semicolon
|
||||
}
|
||||
|
||||
increment_statement = {
|
||||
expr ~ "++" ~ semicolon
|
||||
}
|
||||
|
||||
decrement_statement = {
|
||||
expr ~ "--" ~ semicolon
|
||||
}
|
||||
|
||||
compound_assign = {
|
||||
"+="
|
||||
| "-="
|
||||
|
||||
@@ -114,6 +114,14 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
|
||||
})
|
||||
}
|
||||
|
||||
Rule::increment_statement => {
|
||||
ast_expr!(Statement::Increment(inner.next().unwrap().try_into()))
|
||||
}
|
||||
|
||||
Rule::decrement_statement => {
|
||||
ast_expr!(Statement::Decrement(inner.next().unwrap().try_into()))
|
||||
}
|
||||
|
||||
Rule::unexpected_statement => {
|
||||
return Err(AstError {
|
||||
span: pair.as_span(),
|
||||
|
||||
@@ -713,6 +713,9 @@ impl ToRust for Statement {
|
||||
|
||||
Statement::Break => cg.add_indentedln("break;"),
|
||||
Statement::Continue => cg.add_indentedln("continue;"),
|
||||
|
||||
Statement::Increment(e) => cg.add(&format!("{}+=1;", e.get_rust())),
|
||||
Statement::Decrement(e) => cg.add(&format!("{}-=1;", e.get_rust())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user