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