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>,
},
IfExpression(Box<Expression>, Block, Option<Block>),
MatchExpression(Box<Expression>, Vec<MatchArm>),
WhileExpression {
condition: Option<Box<Expression>>,
body: Block,
@ -121,12 +120,3 @@ pub enum ForBody {
MonadicReturn(Expression),
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(),
LSquareBracket => self.list_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::While) => self.while_expr(),
Identifier(_) => self.identifier_expr(),
@ -642,6 +642,7 @@ impl Parser {
Ok(delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict))
});
/*
parse_method!(match_expr(&mut self) -> ParseResult<Expression> {
expect!(self, Keyword(Kw::Match));
let expr = {
@ -669,6 +670,7 @@ impl Parser {
let identifier = self.identifier()?;
Ok(Pattern(identifier))
});
*/
parse_method!(while_expr(&mut self) -> ParseResult<Expression> {
use self::ExpressionType::*;

View File

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