Working expr statements
This commit is contained in:
@@ -30,6 +30,7 @@ pub enum BinaryOp {
|
||||
pub enum Expression {
|
||||
Literal(Literal),
|
||||
Path(ExprPath),
|
||||
Statement(Box<Statement>),
|
||||
Fix {
|
||||
initial: Box<Expression>,
|
||||
prefixes: Vec<Prefix>,
|
||||
|
||||
@@ -3,13 +3,11 @@ use serde::Serialize;
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Default)]
|
||||
pub struct Block(pub Vec<Spanned<Statement>>);
|
||||
pub struct Block(pub Vec<Spanned<Expression>>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum Statement {
|
||||
Expression(Expression),
|
||||
Block(Block),
|
||||
|
||||
VarDecl(VarDeclStmt),
|
||||
Assign {
|
||||
target: Expression,
|
||||
|
||||
@@ -342,8 +342,8 @@ block = {
|
||||
"{" ~ (statement | unexpected_statement)* ~ "}"
|
||||
}
|
||||
|
||||
statement = {
|
||||
(expr | basic_stmt_left_recurse) ~ semicolon
|
||||
statement = _{
|
||||
((expr | basic_stmt_left_recurse) ~ semicolon)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
@@ -117,6 +117,12 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Expression {
|
||||
Rule::static_path => ast_expr!(Expression::Path(pair.try_into())),
|
||||
Rule::literal => ast_expr!(Expression::Literal(pair.try_into())),
|
||||
Rule::expr_path => ast_expr!(Expression::Path(pair.try_into())),
|
||||
Rule::statement => ast_expr!(Expression::Statement(
|
||||
pair.try_into().get_map(Box::new).map(Box::new)
|
||||
)),
|
||||
Rule::basic_stmt => ast_expr!(Expression::Statement(
|
||||
pair.try_into().get_map(Box::new).map(Box::new)
|
||||
)),
|
||||
|
||||
_ => AstError::bug_unimplemented(pair),
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Statement {
|
||||
let mut inner = pair.clone().into_inner();
|
||||
|
||||
match rule {
|
||||
Rule::statement => Statement::try_from(inner.next().unwrap()),
|
||||
Rule::statement | Rule::basic_stmt => Statement::try_from(inner.next().unwrap()),
|
||||
|
||||
Rule::block => ast_expr!(Statement::Block(pair.try_into())),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user