Add "production" line to parse debug output

And also add a .next() in the parser that should've been there
This commit is contained in:
greg 2019-10-02 03:38:18 -07:00
parent 28056b1f89
commit 904d5c4431
2 changed files with 9 additions and 2 deletions

View File

@ -825,6 +825,7 @@ impl Parser {
let lhs = self.prefix_expr()?;
let ref next = self.token_handler.peek_kind();
Ok(if let Some(op) = BinOp::from_sigil_token(next) {
self.token_handler.next();
Discriminator::BinOp(lhs, op)
} else {
Discriminator::Simple(lhs)

View File

@ -127,12 +127,18 @@ fn format_parse_error(error: parsing::ParseError, handle: &mut Schala) -> String
let line_num_digits = format!("{}", line_num).chars().count();
let space_padding = " ".repeat(line_num_digits);
let production = match error.production_name {
Some(n) => format!("\n(from production \"{}\")", n),
None => "".to_string()
};
format!(r#"
{error_msg}
{error_msg}{production}
{space_padding} |
{line_num} | {}
{space_padding} | {}
"#, line_from_program, location_pointer, error_msg=error.msg, space_padding=space_padding, line_num=line_num)
"#, line_from_program, location_pointer, error_msg=error.msg, space_padding=space_padding, line_num=line_num, production=production
)
}
fn symbol_table(input: ast::AST, handle: &mut Schala, comp: Option<&mut PassDebugArtifact>) -> Result<ast::AST, String> {