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