Rename ExpressionType -> ExpressionKind

This commit is contained in:
greg 2019-02-21 01:26:51 -08:00
parent 6fba0cc5b4
commit 9fa0576547
4 changed files with 26 additions and 26 deletions

View File

@ -92,7 +92,7 @@ pub enum Variant {
}
#[derive(Debug, PartialEq, Clone)]
pub struct Expression(pub ExpressionType, pub Option<TypeIdentifier>);
pub struct Expression(pub ExpressionKind, pub Option<TypeIdentifier>);
#[derive(Debug, PartialEq, Clone)]
@ -108,7 +108,7 @@ pub struct TypeSingletonName {
}
#[derive(Debug, PartialEq, Clone)]
pub enum ExpressionType {
pub enum ExpressionKind {
NatLiteral(u64),
FloatLiteral(f64),
StringLiteral(Rc<String>),
@ -177,7 +177,7 @@ pub enum Guard {
#[derive(Debug, PartialEq, Clone)]
pub struct HalfExpr {
pub op: Option<BinOp>,
pub expr: ExpressionType,
pub expr: ExpressionKind,
}
#[derive(Debug, PartialEq, Clone)]
@ -193,7 +193,7 @@ pub enum Pattern {
pub enum PatternLiteral {
NumPattern {
neg: bool,
num: ExpressionType,
num: ExpressionKind,
},
StringPattern(Rc<String>),
BoolPattern(bool),

View File

@ -560,7 +560,7 @@ impl Parser {
None => unreachable!()
};
let rhs = self.precedence_expr(new_precedence)?;
lhs = Expression(ExpressionType::BinExp(operation, bx!(lhs.into()), bx!(rhs.into())), None);
lhs = Expression(ExpressionKind::BinExp(operation, bx!(lhs.into()), bx!(rhs.into())), None);
}
self.parse_level -= 1;
Ok(lhs)
@ -576,7 +576,7 @@ impl Parser {
};
let expr = self.primary()?;
Ok(Expression(
ExpressionType::PrefixExp(PrefixOp::from_sigil(sigil.as_str()), bx!(expr.into())),
ExpressionKind::PrefixExp(PrefixOp::from_sigil(sigil.as_str()), bx!(expr.into())),
None
))
},
@ -590,7 +590,7 @@ impl Parser {
while let LParen = self.token_handler.peek_kind() {
let arguments = delimited!(self, LParen, expression, Comma, RParen);
let arguments = arguments.into_iter().map(|s| Node::new(s)).collect();
expr = Expression(ExpressionType::Call { f: bx!(expr), arguments }, None); //TODO none is incorrect
expr = Expression(ExpressionKind::Call { f: bx!(expr), arguments }, None); //TODO none is incorrect
}
Ok(expr)
@ -601,7 +601,7 @@ impl Parser {
let primary = self.primary()?;
Ok(if let LSquareBracket = self.token_handler.peek_kind() {
let indexers = delimited!(self, LSquareBracket, expression, Comma, RSquareBracket);
Expression(ExpressionType::Index {
Expression(ExpressionKind::Index {
indexee: bx!(Expression(primary.0, None)),
indexers,
}, None)
@ -628,7 +628,7 @@ impl Parser {
#[recursive_descent_method]
fn list_expr(&mut self) -> ParseResult<Expression> {
let exprs = delimited!(self, LSquareBracket, expression, Comma, RSquareBracket);
Ok(Expression(ExpressionType::ListLiteral(exprs), None))
Ok(Expression(ExpressionKind::ListLiteral(exprs), None))
}
#[recursive_descent_method]
@ -645,7 +645,7 @@ impl Parser {
_ => None,
};
let body = self.nonempty_func_body()?;
Ok(Expression(ExpressionType::Lambda { params, type_anno, body }, None)) //TODO need to handle types somehow
Ok(Expression(ExpressionKind::Lambda { params, type_anno, body }, None)) //TODO need to handle types somehow
}
#[recursive_descent_method]
@ -660,7 +660,7 @@ impl Parser {
#[recursive_descent_method]
fn paren_expr(&mut self) -> ParseResult<Expression> {
use self::ExpressionType::*;
use self::ExpressionKind::*;
let old_struct_value = self.restrictions.no_struct_literal;
self.restrictions.no_struct_literal = false;
let output = {
@ -680,7 +680,7 @@ impl Parser {
#[recursive_descent_method]
fn identifier_expr(&mut self) -> ParseResult<Expression> {
use self::ExpressionType::*;
use self::ExpressionKind::*;
let identifier = self.identifier()?;
Ok(match self.token_handler.peek_kind() {
LCurlyBrace if !self.restrictions.no_struct_literal => {
@ -720,7 +720,7 @@ impl Parser {
_ => self.guard_block()?
});
Ok(Expression(ExpressionType::IfExpression { discriminator, body }, None))
Ok(Expression(ExpressionKind::IfExpression { discriminator, body }, None))
}
#[recursive_descent_method]
@ -920,7 +920,7 @@ impl Parser {
#[recursive_descent_method]
fn while_expr(&mut self) -> ParseResult<Expression> {
use self::ExpressionType::*;
use self::ExpressionKind::*;
expect!(self, Keyword(Kw::While));
let condition = {
self.restrictions.no_struct_literal = true;
@ -955,7 +955,7 @@ impl Parser {
vec![single_enum]
};
let body = Box::new(self.for_expr_body()?);
Ok(Expression(ExpressionType::ForExpression { enumerators, body }, None))
Ok(Expression(ExpressionKind::ForExpression { enumerators, body }, None))
}
#[recursive_descent_method]
@ -994,7 +994,7 @@ impl Parser {
#[recursive_descent_method]
fn literal(&mut self) -> ParseResult<Expression> {
use self::ExpressionType::*;
use self::ExpressionKind::*;
let tok = self.token_handler.peek();
match tok.get_kind() {
@ -1025,7 +1025,7 @@ impl Parser {
#[recursive_descent_method]
fn int_literal(&mut self) -> ParseResult<Expression> {
use self::ExpressionType::*;
use self::ExpressionKind::*;
let tok = self.token_handler.next();
match tok.get_kind() {
BinNumberSigil => {
@ -1044,7 +1044,7 @@ impl Parser {
#[recursive_descent_method]
fn float_literal(&mut self) -> ParseResult<Expression> {
use self::ExpressionType::*;
use self::ExpressionKind::*;
let tok = self.token_handler.peek();
let mut digits = self.digits()?;
if let Period = self.token_handler.peek_kind() {
@ -1123,7 +1123,7 @@ mod parse_tests {
use super::Signature;
use super::TypeIdentifier::*;
use super::TypeSingletonName;
use super::ExpressionType::*;
use super::ExpressionKind::*;
use super::Variant::*;
use super::ForBody::*;

View File

@ -120,7 +120,7 @@ fn reduce_block(block: &Block, symbol_table: &SymbolTable) -> Vec<Stmt> {
impl Expression {
fn reduce(&self, symbol_table: &SymbolTable) -> Expr {
use crate::ast::ExpressionType::*;
use crate::ast::ExpressionKind::*;
let ref input = self.0;
match input {
NatLiteral(n) => Expr::Lit(Lit::Nat(*n)),
@ -294,10 +294,10 @@ impl PatternLiteral {
match self {
NumPattern { neg, num } => {
let comparison = Expr::Lit(match (neg, num) {
(false, ExpressionType::NatLiteral(n)) => Lit::Nat(*n),
(false, ExpressionType::FloatLiteral(f)) => Lit::Float(*f),
(true, ExpressionType::NatLiteral(n)) => Lit::Int(-1*(*n as i64)),
(true, ExpressionType::FloatLiteral(f)) => Lit::Float(-1.0*f),
(false, ExpressionKind::NatLiteral(n)) => Lit::Nat(*n),
(false, ExpressionKind::FloatLiteral(f)) => Lit::Float(*f),
(true, ExpressionKind::NatLiteral(n)) => Lit::Int(-1*(*n as i64)),
(true, ExpressionKind::FloatLiteral(f)) => Lit::Float(-1.0*f),
_ => panic!("This should never happen")
});
let guard = Some(Expr::Call {

View File

@ -235,8 +235,8 @@ impl<'a> TypeContext<'a> {
}
}
fn expr_type(&mut self, expr: &ExpressionType) -> InferResult<Type> {
use self::ExpressionType::*;
fn expr_type(&mut self, expr: &ExpressionKind) -> InferResult<Type> {
use self::ExpressionKind::*;
Ok(match expr {
NatLiteral(_) => ty!(Nat),
BoolLiteral(_) => ty!(Bool),