Kill match keyword + data structures

And add new unified keywords
This commit is contained in:
greg 2018-06-19 00:07:28 -07:00
parent ba319a7bc3
commit ba4cd9da39
3 changed files with 7 additions and 13 deletions

View File

@ -94,7 +94,6 @@ pub enum ExpressionType {
indexers: Vec<Expression>, indexers: Vec<Expression>,
}, },
IfExpression(Box<Expression>, Block, Option<Block>), IfExpression(Box<Expression>, Block, Option<Block>),
MatchExpression(Box<Expression>, Vec<MatchArm>),
WhileExpression { WhileExpression {
condition: Option<Box<Expression>>, condition: Option<Box<Expression>>,
body: Block, body: Block,
@ -121,12 +120,3 @@ pub enum ForBody {
MonadicReturn(Expression), MonadicReturn(Expression),
StatementBlock(Block), StatementBlock(Block),
} }
#[derive(Debug, PartialEq, Clone)]
pub struct MatchArm {
pub pat: Pattern,
pub expr: Expression,
}
#[derive(Debug, PartialEq, Clone)]
pub struct Pattern(pub Rc<String>);

View File

@ -542,7 +542,7 @@ impl Parser {
LParen => self.paren_expr(), LParen => self.paren_expr(),
LSquareBracket => self.list_expr(), LSquareBracket => self.list_expr(),
Keyword(Kw::If) => self.if_expr(), Keyword(Kw::If) => self.if_expr(),
Keyword(Kw::Match) => self.match_expr(), //Keyword(Kw::Match) => self.match_expr(),
Keyword(Kw::For) => self.for_expr(), Keyword(Kw::For) => self.for_expr(),
Keyword(Kw::While) => self.while_expr(), Keyword(Kw::While) => self.while_expr(),
Identifier(_) => self.identifier_expr(), Identifier(_) => self.identifier_expr(),
@ -642,6 +642,7 @@ impl Parser {
Ok(delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict)) Ok(delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict))
}); });
/*
parse_method!(match_expr(&mut self) -> ParseResult<Expression> { parse_method!(match_expr(&mut self) -> ParseResult<Expression> {
expect!(self, Keyword(Kw::Match)); expect!(self, Keyword(Kw::Match));
let expr = { let expr = {
@ -669,6 +670,7 @@ impl Parser {
let identifier = self.identifier()?; let identifier = self.identifier()?;
Ok(Pattern(identifier)) Ok(Pattern(identifier))
}); });
*/
parse_method!(while_expr(&mut self) -> ParseResult<Expression> { parse_method!(while_expr(&mut self) -> ParseResult<Expression> {
use self::ExpressionType::*; use self::ExpressionType::*;

View File

@ -45,7 +45,8 @@ impl fmt::Display for TokenType {
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum Kw { pub enum Kw {
If, Else, If, Then, Else,
Is,
Func, Func,
For, While, For, While,
Match, Match,
@ -61,11 +62,12 @@ lazy_static! {
static ref KEYWORDS: HashMap<&'static str, Kw> = static ref KEYWORDS: HashMap<&'static str, Kw> =
hashmap! { hashmap! {
"if" => Kw::If, "if" => Kw::If,
"then" => Kw::Then,
"else" => Kw::Else, "else" => Kw::Else,
"is" => Kw::Is,
"fn" => Kw::Func, "fn" => Kw::Func,
"for" => Kw::For, "for" => Kw::For,
"while" => Kw::While, "while" => Kw::While,
"match" => Kw::Match,
"var" => Kw::Var, "var" => Kw::Var,
"const" => Kw::Const, "const" => Kw::Const,
"let" => Kw::Let, "let" => Kw::Let,