Show more useful information in parse tracing

This commit is contained in:
greg 2017-09-15 16:40:16 -07:00
parent 5ecd28d057
commit 565461e1db
1 changed files with 3 additions and 3 deletions

View File

@ -443,7 +443,7 @@ macro_rules! parse_method {
($name:ident, $self:ident, $type:ty, $body:tt) => { ($name:ident, $self:ident, $type:ty, $body:tt) => {
fn $name(&mut $self) -> $type { fn $name(&mut $self) -> $type {
let next_token = $self.peek(); let next_token = $self.peek();
let record = ParseRecord(format!("Token: {:?}", next_token)); let record = ParseRecord(format!("production {}, Token: {:?}", stringify!($name), next_token));
$self.parse_record.push(record); $self.parse_record.push(record);
$body $body
} }
@ -482,7 +482,7 @@ impl Parser {
Ok(AST(statements)) Ok(AST(statements))
}); });
fn statement(&mut self) -> ParseResult<Statement> { parse_method!(statement, self, ParseResult<Statement>, {
//TODO handle error recovery here //TODO handle error recovery here
match self.peek() { match self.peek() {
Keyword(Alias) => self.type_alias().map(|alias| { Statement::Declaration(alias) }), Keyword(Alias) => self.type_alias().map(|alias| { Statement::Declaration(alias) }),
@ -490,7 +490,7 @@ impl Parser {
Keyword(Func)=> self.func_declaration().map(|func| { Statement::Declaration(func) }), Keyword(Func)=> self.func_declaration().map(|func| { Statement::Declaration(func) }),
_ => self.expression().map(|expr| { Statement::Expression(expr) } ), _ => self.expression().map(|expr| { Statement::Expression(expr) } ),
} }
} });
fn type_alias(&mut self) -> ParseResult<Declaration> { fn type_alias(&mut self) -> ParseResult<Declaration> {
expect!(self, Keyword(Alias), "Expected 'alias'"); expect!(self, Keyword(Alias), "Expected 'alias'");