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,8 +112,7 @@ fn statement(tokens: &mut Tokens) -> ParseResult {
fn let_expression(tokens: &mut Tokens) -> ParseResult {
expect!(Keyword(Kw::Let), tokens);
if let Some(&Identifier(ref name)) = tokens.next() {
if let Some(&Identifier(ref s)) = tokens.next() {
if s == "=" {
if let Some(&Keyword(Kw::Assign)) = tokens.next() {
if let Ok(expr) = expression(tokens) {
return Ok(
AST::Binding(name.clone(),
@ -121,7 +120,6 @@ fn let_expression(tokens: &mut Tokens) -> ParseResult {
}
}
}
}
return Err("Bad parse in let_expression()".to_string());
}
@ -160,7 +158,7 @@ fn if_expression(tokens: &mut Tokens) -> ParseResult {
expect!(Keyword(Kw::End), tokens);
Ok( AST::IfStatement(
Ok(AST::IfStatement(
Box::new(if_clause),
Box::new(then_clause),
else_clause.map(|ast| Box::new(ast))

View File

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