Fix everything if-refactor-related save reduced_ast

This commit is contained in:
greg 2019-10-10 14:38:48 -07:00
parent 3bca82a8c8
commit 8d3639ab8e
5 changed files with 14 additions and 8 deletions

View File

@ -21,7 +21,7 @@ pub trait ASTVisitor: Sized {
fn named_struct(&mut self, _name: &QualifiedName, _fields: &Vec<(Rc<String>, Expression)>) {}
fn call(&mut self, _f: &Expression, _arguments: &Vec<InvocationArgument>) {}
fn index(&mut self, _indexee: &Expression, _indexers: &Vec<Expression>) {}
fn if_expression(&mut self, _discrim: &Discriminator, _body: &IfExpressionBody) {}
fn if_expression(&mut self, _discrim: Option<&Expression>, _body: &IfExpressionBody) {}
fn while_expression(&mut self, _condition: Option<&Expression>, _body: &Block) {}
fn for_expression(&mut self, _enumerators: &Vec<Enumerator>, _body: &ForBody) {}
fn lambda(&mut self, _params: &Vec<FormalParam>, _type_anno: Option<&TypeIdentifier>, _body: &Block) {}

View File

@ -2,7 +2,7 @@
use std::rc::Rc;
use crate::ast::*;
use crate::ast::visitor::ASTVisitor;
use std::ops::Deref;
use crate::util::deref_optional_box;
pub fn ast<V: ASTVisitor>(v: &mut V, ast: &AST) {
v.ast(ast);
@ -143,8 +143,8 @@ fn expression_kind<V: ASTVisitor>(v: &mut V, expression_kind: &ExpressionKind) {
v.index(indexee, indexers);
index(v, indexee, indexers);
},
IfExpression { discriminator, body } => v.if_expression(discriminator, body),
WhileExpression { condition, body } => v.while_expression(condition.as_ref().map(|b: &Box<Expression>| Deref::deref(b)), body),
IfExpression { discriminator, body } => v.if_expression(deref_optional_box(discriminator), body),
WhileExpression { condition, body } => v.while_expression(deref_optional_box(condition), body),
ForExpression { enumerators, body } => v.for_expression(enumerators, body),
Lambda { params , type_anno, body } => {
v.lambda(params, type_anno.as_ref(), body);

View File

@ -825,9 +825,9 @@ impl Parser {
#[recursive_descent_method]
fn if_expr_body(&mut self) -> ParseResult<IfExpressionBody> {
match self.token_handler.peek_kind() {
Keyword(Kw::Then) => self.simple_conditional()?,
Keyword(Kw::Is) => self.simple_pattern_match()? ,
_ => self.cond_block()?
Keyword(Kw::Then) => self.simple_conditional(),
Keyword(Kw::Is) => self.simple_pattern_match(),
_ => self.cond_block(),
}
}

View File

@ -5,6 +5,7 @@ use ena::unify::{UnifyKey, InPlaceUnificationTable, UnificationTable, EqUnifyVal
use crate::ast::*;
use crate::util::ScopeStack;
use crate::util::deref_optional_box;
#[derive(Debug, Clone, PartialEq)]
@ -318,7 +319,7 @@ impl<'a> TypeContext<'a> {
StringLiteral(_) => ty!(StringT),
PrefixExp(op, expr) => self.prefix(op, expr)?,
BinExp(op, lhs, rhs) => self.binexp(op, lhs, rhs)?,
IfExpression { discriminator, body } => self.if_expr(&*discriminator, &**body)?,
IfExpression { discriminator, body } => self.if_expr(deref_optional_box(discriminator), &**body)?,
Value(val) => self.handle_value(val)?,
Call { box ref f, arguments } => self.call(f, arguments)?,
Lambda { params, type_anno, body } => self.lambda(params, type_anno, body)?,

View File

@ -1,6 +1,11 @@
use std::collections::HashMap;
use std::hash::Hash;
use std::cmp::Eq;
use std::ops::Deref;
pub fn deref_optional_box<T>(x: &Option<Box<T>>) -> Option<&T> {
x.as_ref().map(|b: &Box<T>| Deref::deref(b))
}
#[derive(Default, Debug)]
pub struct ScopeStack<'a, T: 'a, V: 'a> where T: Hash + Eq {