Renamed init function in parser
This commit is contained in:
parent
fd0e7012ac
commit
c1698d9b25
|
@ -453,7 +453,7 @@ impl ExecEnv {
|
|||
});
|
||||
}
|
||||
|
||||
let stmts = crate::parser::Parser::new(&code).init()?;
|
||||
let stmts = crate::parser::Parser::new(&code).parse()?;
|
||||
self.eval_stmts(&stmts)?;
|
||||
}
|
||||
}
|
||||
|
@ -697,7 +697,7 @@ mod tests {
|
|||
|
||||
// We can assume there won't be any syntax errors in the
|
||||
// interpreter tests.
|
||||
let ast = parser.init().unwrap();
|
||||
let ast = parser.parse().unwrap();
|
||||
env.eval_stmts(&ast).map(|()| Value::Nul)
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ impl<'source> Parser<'source> {
|
|||
/// Start parsing tokens
|
||||
///
|
||||
/// Loops trough lexer, parses statements, returns AST
|
||||
pub fn init(&mut self) -> Result<Block, Error> {
|
||||
pub fn parse(&mut self) -> Result<Block, Error> {
|
||||
let mut ast = vec![];
|
||||
while let Some(token) = self.lexer.next() {
|
||||
match token {
|
||||
|
@ -36,7 +36,7 @@ impl<'source> Parser<'source> {
|
|||
|
||||
// T-Dark block (replace `lang` with `script`)
|
||||
Token::TDark => ast.extend(self.tdark_flow()?),
|
||||
token => ast.push(self.parse(token)?),
|
||||
token => ast.push(self.parse_stmt(token)?),
|
||||
}
|
||||
}
|
||||
Ok(ast)
|
||||
|
@ -62,7 +62,7 @@ impl<'source> Parser<'source> {
|
|||
///
|
||||
/// This function will route to corresponding flow functions
|
||||
/// which may advance the lexer iterator
|
||||
fn parse(&mut self, token: Token) -> Result<Spanned<Stmt>, Error> {
|
||||
fn parse_stmt(&mut self, token: Token) -> Result<Spanned<Stmt>, Error> {
|
||||
let start = self.lexer.span().start;
|
||||
|
||||
match token {
|
||||
|
@ -349,7 +349,7 @@ impl<'source> Parser<'source> {
|
|||
match self.checked_next()? {
|
||||
Token::RightCurly => break,
|
||||
Token::TDark => block.extend(self.tdark_flow()?),
|
||||
t => block.push(self.parse(t)?),
|
||||
t => block.push(self.parse_stmt(t)?),
|
||||
}
|
||||
}
|
||||
Ok(block)
|
||||
|
@ -650,7 +650,7 @@ mod tests {
|
|||
span: 0..24,
|
||||
}];
|
||||
|
||||
let ast = Parser::new(code).init().unwrap();
|
||||
let ast = Parser::new(code).parse().unwrap();
|
||||
assert_eq!(ast, expected);
|
||||
}
|
||||
|
||||
|
@ -671,7 +671,7 @@ mod tests {
|
|||
span: 0..11,
|
||||
}];
|
||||
|
||||
let ast = Parser::new(code).init().unwrap();
|
||||
let ast = Parser::new(code).parse().unwrap();
|
||||
assert_eq!(ast, expected);
|
||||
}
|
||||
|
||||
|
@ -705,7 +705,7 @@ mod tests {
|
|||
span: 0..56,
|
||||
}];
|
||||
|
||||
let ast = Parser::new(code).init().unwrap();
|
||||
let ast = Parser::new(code).parse().unwrap();
|
||||
assert_eq!(ast, expected);
|
||||
}
|
||||
|
||||
|
@ -736,7 +736,7 @@ mod tests {
|
|||
span: 9..34,
|
||||
}];
|
||||
|
||||
let ast = Parser::new(code).init().unwrap();
|
||||
let ast = Parser::new(code).parse().unwrap();
|
||||
assert_eq!(ast, expected);
|
||||
}
|
||||
|
||||
|
@ -782,7 +782,7 @@ mod tests {
|
|||
span: 0..39,
|
||||
}];
|
||||
|
||||
let ast = Parser::new(code).init().unwrap();
|
||||
let ast = Parser::new(code).parse().unwrap();
|
||||
assert_eq!(ast, expected);
|
||||
}
|
||||
|
||||
|
@ -815,7 +815,7 @@ mod tests {
|
|||
span: 0..41,
|
||||
}];
|
||||
|
||||
let ast = Parser::new(code).init().unwrap();
|
||||
let ast = Parser::new(code).parse().unwrap();
|
||||
assert_eq!(ast, expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ fn main() {
|
|||
|
||||
// Parse & evaluate
|
||||
let mut parser = Parser::new(&source);
|
||||
if let Err(e) = parser.init().and_then(|ast| {
|
||||
if let Err(e) = parser.parse().and_then(|ast| {
|
||||
if ast_print {
|
||||
println!("{:#?}", ast);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ pub fn repl(ast_print: bool) {
|
|||
None => readline.to_owned(),
|
||||
};
|
||||
|
||||
partial = match Parser::new(&partial_data).init().and_then(|ast| {
|
||||
partial = match Parser::new(&partial_data).parse().and_then(|ast| {
|
||||
if ast_print {
|
||||
println!("{:#?}", &ast);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue