Make = a keyword

This commit is contained in:
greg 2015-08-08 00:27:40 -07:00
parent 72b26755a7
commit e870d8172a
2 changed files with 9 additions and 9 deletions

View File

@ -112,13 +112,11 @@ fn statement(tokens: &mut Tokens) -> ParseResult {
fn let_expression(tokens: &mut Tokens) -> ParseResult { fn let_expression(tokens: &mut Tokens) -> ParseResult {
expect!(Keyword(Kw::Let), tokens); expect!(Keyword(Kw::Let), tokens);
if let Some(&Identifier(ref name)) = tokens.next() { if let Some(&Identifier(ref name)) = tokens.next() {
if let Some(&Identifier(ref s)) = tokens.next() { if let Some(&Keyword(Kw::Assign)) = tokens.next() {
if s == "=" { if let Ok(expr) = expression(tokens) {
if let Ok(expr) = expression(tokens) { return Ok(
return Ok( AST::Binding(name.clone(),
AST::Binding(name.clone(), Box::new(expr)));
Box::new(expr)));
}
} }
} }
} }
@ -160,7 +158,7 @@ fn if_expression(tokens: &mut Tokens) -> ParseResult {
expect!(Keyword(Kw::End), tokens); expect!(Keyword(Kw::End), tokens);
Ok( AST::IfStatement( Ok(AST::IfStatement(
Box::new(if_clause), Box::new(if_clause),
Box::new(then_clause), Box::new(then_clause),
else_clause.map(|ast| Box::new(ast)) else_clause.map(|ast| Box::new(ast))

View File

@ -21,7 +21,8 @@ pub enum Kw {
End, End,
Let, Let,
Fn, Fn,
Null Null,
Assign
} }
pub fn tokenize(input: &str) -> Vec<Token> { pub fn tokenize(input: &str) -> Vec<Token> {
@ -106,6 +107,7 @@ fn handle_identifier(identifier: String) -> Token {
"end" => Kw::End, "end" => Kw::End,
"fn" => Kw::Fn, "fn" => Kw::Fn,
"null" => Kw::Null, "null" => Kw::Null,
"=" => Kw::Assign,
_ => return Token::Identifier(identifier) _ => return Token::Identifier(identifier)
}; };