Change 'input' to 'tokens'
just to be consistent
This commit is contained in:
parent
8fcc850d77
commit
42719dc2f2
@ -66,19 +66,19 @@ pub fn parse(input: Vec<Token>) -> ParseResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn statements(input: &mut Tokens) -> ParseResult {
|
fn statements(tokens: &mut Tokens) -> ParseResult {
|
||||||
|
|
||||||
let mut statements = Vec::new();
|
let mut statements = Vec::new();
|
||||||
|
|
||||||
let initial_statement = statement(input);
|
let initial_statement = statement(tokens);
|
||||||
match initial_statement {
|
match initial_statement {
|
||||||
ParseResult::Ok(ast) => {
|
ParseResult::Ok(ast) => {
|
||||||
statements.push(ast);
|
statements.push(ast);
|
||||||
loop {
|
loop {
|
||||||
let lookahead = input.peek().map(|i| i.clone());
|
let lookahead = tokens.peek().map(|i| i.clone());
|
||||||
if let Some(&Separator) = lookahead {
|
if let Some(&Separator) = lookahead {
|
||||||
input.next();
|
tokens.next();
|
||||||
if let ParseResult::Ok(ast_next) = statement(input) {
|
if let ParseResult::Ok(ast_next) = statement(tokens) {
|
||||||
statements.push(ast_next);
|
statements.push(ast_next);
|
||||||
} else {
|
} else {
|
||||||
return ParseResult::Err("bad thing happened".to_string());
|
return ParseResult::Err("bad thing happened".to_string());
|
||||||
@ -96,19 +96,19 @@ fn statements(input: &mut Tokens) -> ParseResult {
|
|||||||
return ParseResult::Ok(AST::Statements(statements));
|
return ParseResult::Ok(AST::Statements(statements));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn statement(input: &mut Tokens) -> ParseResult {
|
fn statement(tokens: &mut Tokens) -> ParseResult {
|
||||||
match input.peek().map(|i| i.clone()) {
|
match tokens.peek().map(|i| i.clone()) {
|
||||||
Some(&Keyword(Kw::Let)) => let_expression(input),
|
Some(&Keyword(Kw::Let)) => let_expression(tokens),
|
||||||
_ => expression(input)
|
_ => expression(tokens)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn let_expression(input: &mut Tokens) -> ParseResult {
|
fn let_expression(tokens: &mut Tokens) -> ParseResult {
|
||||||
expect!(Keyword(Kw::Let), input);
|
expect!(Keyword(Kw::Let), tokens);
|
||||||
if let Some(&Identifier(ref name)) = input.next() {
|
if let Some(&Identifier(ref name)) = tokens.next() {
|
||||||
if let Some(&Identifier(ref s)) = input.next() {
|
if let Some(&Identifier(ref s)) = tokens.next() {
|
||||||
if s == "=" {
|
if s == "=" {
|
||||||
if let ParseResult::Ok(rhs) = rhs(input) {
|
if let ParseResult::Ok(rhs) = rhs(tokens) {
|
||||||
return ParseResult::Ok(
|
return ParseResult::Ok(
|
||||||
AST::Binding(name.clone(),
|
AST::Binding(name.clone(),
|
||||||
Box::new(rhs)));
|
Box::new(rhs)));
|
||||||
@ -120,35 +120,35 @@ fn let_expression(input: &mut Tokens) -> ParseResult {
|
|||||||
return ParseResult::Err("Bad parse in let_expression()".to_string());
|
return ParseResult::Err("Bad parse in let_expression()".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expression(input: &mut Tokens) -> ParseResult {
|
fn expression(tokens: &mut Tokens) -> ParseResult {
|
||||||
let lookahead = input.peek().map(|i| i.clone());
|
let lookahead = tokens.peek().map(|i| i.clone());
|
||||||
match lookahead {
|
match lookahead {
|
||||||
Some(&Keyword(Kw::If)) => {
|
Some(&Keyword(Kw::If)) => {
|
||||||
if_expression(input)
|
if_expression(tokens)
|
||||||
},
|
},
|
||||||
_ => rhs(input)
|
_ => rhs(tokens)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn if_expression(input: &mut Tokens) -> ParseResult {
|
fn if_expression(tokens: &mut Tokens) -> ParseResult {
|
||||||
|
|
||||||
expect!(Keyword(Kw::If), input);
|
expect!(Keyword(Kw::If), tokens);
|
||||||
let if_clause = match expression(input) {
|
let if_clause = match expression(tokens) {
|
||||||
err@ParseResult::Err(_) => return err,
|
err@ParseResult::Err(_) => return err,
|
||||||
ParseResult::Ok(ast) => ast
|
ParseResult::Ok(ast) => ast
|
||||||
};
|
};
|
||||||
|
|
||||||
expect!(Keyword(Kw::Then), input);
|
expect!(Keyword(Kw::Then), tokens);
|
||||||
|
|
||||||
let then_clause = match expression(input) {
|
let then_clause = match expression(tokens) {
|
||||||
err@ParseResult::Err(_) => return err,
|
err@ParseResult::Err(_) => return err,
|
||||||
ParseResult::Ok(ast) => ast
|
ParseResult::Ok(ast) => ast
|
||||||
};
|
};
|
||||||
|
|
||||||
let else_clause = match input.peek().map(|i| i.clone()) {
|
let else_clause = match tokens.peek().map(|i| i.clone()) {
|
||||||
Some(&Keyword(Kw::Else)) => {
|
Some(&Keyword(Kw::Else)) => {
|
||||||
input.next();
|
tokens.next();
|
||||||
match expression(input) {
|
match expression(tokens) {
|
||||||
err@ParseResult::Err(_) => return err,
|
err@ParseResult::Err(_) => return err,
|
||||||
ParseResult::Ok(ast) => Some(ast)
|
ParseResult::Ok(ast) => Some(ast)
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ fn if_expression(input: &mut Tokens) -> ParseResult {
|
|||||||
_ => None
|
_ => None
|
||||||
};
|
};
|
||||||
|
|
||||||
expect!(Keyword(Kw::End), input);
|
expect!(Keyword(Kw::End), tokens);
|
||||||
|
|
||||||
ParseResult::Ok( AST::IfStatement(
|
ParseResult::Ok( AST::IfStatement(
|
||||||
Box::new(if_clause),
|
Box::new(if_clause),
|
||||||
@ -165,8 +165,8 @@ fn if_expression(input: &mut Tokens) -> ParseResult {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rhs(input: &mut Tokens) -> ParseResult {
|
fn rhs(tokens: &mut Tokens) -> ParseResult {
|
||||||
let next = input.next();
|
let next = tokens.next();
|
||||||
if let Some(&Identifier(ref value)) = next {
|
if let Some(&Identifier(ref value)) = next {
|
||||||
return ParseResult::Ok(AST::Name(value.clone()));
|
return ParseResult::Ok(AST::Name(value.clone()));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user