Top level as statement #103
This commit is contained in:
@@ -33,6 +33,7 @@ impl GenMist for Statement {
|
|||||||
cg.add("unsafe ");
|
cg.add("unsafe ");
|
||||||
block.gen_mist(ctx, cg);
|
block.gen_mist(ctx, cg);
|
||||||
}
|
}
|
||||||
|
Statement::TopLevel(tl) => tl.gen_mist(ctx, cg),
|
||||||
Statement::Block(block) => block.gen_mist(ctx, cg),
|
Statement::Block(block) => block.gen_mist(ctx, cg),
|
||||||
Statement::VarDecl(VarDeclStmt { decl, init }) => {
|
Statement::VarDecl(VarDeclStmt { decl, init }) => {
|
||||||
if decl.type_.is_some() {
|
if decl.type_.is_some() {
|
||||||
|
|||||||
@@ -31,13 +31,14 @@ impl GenRust for Block {
|
|||||||
impl GenRust for Statement {
|
impl GenRust for Statement {
|
||||||
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||||
match self {
|
match self {
|
||||||
|
Statement::TopLevel(tl) => tl.gen_rust(ctx, cg),
|
||||||
|
Statement::Block(block) => block.gen_rust(ctx, cg),
|
||||||
|
|
||||||
Statement::UnsafeBlock(block) => {
|
Statement::UnsafeBlock(block) => {
|
||||||
cg.add("unsafe ");
|
cg.add("unsafe ");
|
||||||
block.gen_rust(ctx, cg);
|
block.gen_rust(ctx, cg);
|
||||||
}
|
}
|
||||||
|
|
||||||
Statement::Block(block) => block.gen_rust(ctx, cg),
|
|
||||||
|
|
||||||
Statement::VarDecl(VarDeclStmt { decl, init }) => {
|
Statement::VarDecl(VarDeclStmt { decl, init }) => {
|
||||||
cg.add("let ");
|
cg.add("let ");
|
||||||
decl.gen_rust(ctx, cg);
|
decl.gen_rust(ctx, cg);
|
||||||
|
|||||||
@@ -119,3 +119,15 @@ impl From<Path> for ExprPath {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Expression {
|
||||||
|
pub fn is_semicolon_required(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Statement(v) => match &**v {
|
||||||
|
Statement::TopLevel(_) => false,
|
||||||
|
_ => true,
|
||||||
|
},
|
||||||
|
_ => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ pub struct Block {
|
|||||||
pub enum Statement {
|
pub enum Statement {
|
||||||
UnsafeBlock(Block),
|
UnsafeBlock(Block),
|
||||||
Block(Block),
|
Block(Block),
|
||||||
|
TopLevel(Box<TopLevel>),
|
||||||
If {
|
If {
|
||||||
initial: StatementBranch,
|
initial: StatementBranch,
|
||||||
else_if: Vec<StatementBranch>,
|
else_if: Vec<StatementBranch>,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ keyword = {
|
|||||||
| "class"
|
| "class"
|
||||||
| "trait"
|
| "trait"
|
||||||
| "impl"
|
| "impl"
|
||||||
|
| "use"
|
||||||
| "pub"
|
| "pub"
|
||||||
| "mut"
|
| "mut"
|
||||||
| "let"
|
| "let"
|
||||||
@@ -389,6 +390,7 @@ statement_list = {
|
|||||||
statement = _{
|
statement = _{
|
||||||
control_flow
|
control_flow
|
||||||
| (expr ~ semicolon)
|
| (expr ~ semicolon)
|
||||||
|
| top_level
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ impl GetMutability for Block {
|
|||||||
impl GetMutability for Statement {
|
impl GetMutability for Statement {
|
||||||
fn get_mutability(&self) -> Vec<Identifier> {
|
fn get_mutability(&self) -> Vec<Identifier> {
|
||||||
match self {
|
match self {
|
||||||
|
Statement::TopLevel(_) => Vec::new(),
|
||||||
Statement::Block(body) | Statement::UnsafeBlock(body) => body.get_mutability(),
|
Statement::Block(body) | Statement::UnsafeBlock(body) => body.get_mutability(),
|
||||||
Statement::If {
|
Statement::If {
|
||||||
initial,
|
initial,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
use std::fmt;
|
||||||
println!("running common tests...");
|
println!("running common tests...");
|
||||||
common::test_package();
|
common::test_package();
|
||||||
common::expr_test::run_tests();
|
common::expr_test::run_tests();
|
||||||
|
|||||||
Reference in New Issue
Block a user