Top level as statement #103
This commit is contained in:
@@ -33,6 +33,7 @@ impl GenMist for Statement {
|
||||
cg.add("unsafe ");
|
||||
block.gen_mist(ctx, cg);
|
||||
}
|
||||
Statement::TopLevel(tl) => tl.gen_mist(ctx, cg),
|
||||
Statement::Block(block) => block.gen_mist(ctx, cg),
|
||||
Statement::VarDecl(VarDeclStmt { decl, init }) => {
|
||||
if decl.type_.is_some() {
|
||||
|
||||
@@ -31,13 +31,14 @@ impl GenRust for Block {
|
||||
impl GenRust for Statement {
|
||||
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||
match self {
|
||||
Statement::TopLevel(tl) => tl.gen_rust(ctx, cg),
|
||||
Statement::Block(block) => block.gen_rust(ctx, cg),
|
||||
|
||||
Statement::UnsafeBlock(block) => {
|
||||
cg.add("unsafe ");
|
||||
block.gen_rust(ctx, cg);
|
||||
}
|
||||
|
||||
Statement::Block(block) => block.gen_rust(ctx, cg),
|
||||
|
||||
Statement::VarDecl(VarDeclStmt { decl, init }) => {
|
||||
cg.add("let ");
|
||||
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 {
|
||||
UnsafeBlock(Block),
|
||||
Block(Block),
|
||||
TopLevel(Box<TopLevel>),
|
||||
If {
|
||||
initial: StatementBranch,
|
||||
else_if: Vec<StatementBranch>,
|
||||
|
||||
@@ -24,6 +24,7 @@ keyword = {
|
||||
| "class"
|
||||
| "trait"
|
||||
| "impl"
|
||||
| "use"
|
||||
| "pub"
|
||||
| "mut"
|
||||
| "let"
|
||||
@@ -389,6 +390,7 @@ statement_list = {
|
||||
statement = _{
|
||||
control_flow
|
||||
| (expr ~ semicolon)
|
||||
| top_level
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
@@ -129,6 +129,7 @@ impl GetMutability for Block {
|
||||
impl GetMutability for Statement {
|
||||
fn get_mutability(&self) -> Vec<Identifier> {
|
||||
match self {
|
||||
Statement::TopLevel(_) => Vec::new(),
|
||||
Statement::Block(body) | Statement::UnsafeBlock(body) => body.get_mutability(),
|
||||
Statement::If {
|
||||
initial,
|
||||
|
||||
Reference in New Issue
Block a user