Starting to add logic to track recursive descent calls

This commit is contained in:
greg 2017-09-15 04:23:39 -07:00
parent 5dd1cd79ff
commit 6c5dbac406
2 changed files with 32 additions and 1 deletions

View File

@ -34,6 +34,7 @@ impl ProgrammingLanguageInterface for Schala {
let ast = match parsing::parse(tokens) {
Ok(ast) => {
if options.debug_parse {
output.add_artifact(TraceArtifact::new("Recursive descent calls:", format!("{:?}", "OI")));
output.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast)));
}
ast

View File

@ -333,13 +333,16 @@ impl ParseError {
pub type ParseResult<T> = Result<T, ParseError>;
pub struct ParseRecord(String);
struct Parser {
tokens: TokenIter,
parse_record: Vec<ParseRecord>,
}
impl Parser {
fn new(input: Vec<Token>) -> Parser {
Parser { tokens: input.into_iter().peekable() }
Parser { tokens: input.into_iter().peekable(), parse_record: vec![] }
}
fn peek(&mut self) -> TokenType {
@ -435,7 +438,19 @@ impl Operation {
}
}
macro_rules! parse_method {
($name:ident, $self:ident, $type:ty, $body:tt) => {
fn $name(&mut $self) -> $type {
let next_token = $self.peek();
let record = ParseRecord(format!("Token: {:?}", next_token));
$self.parse_record.push(record);
$body
}
}
}
impl Parser {
/*
fn program(&mut self) -> ParseResult<AST> {
let mut statements = Vec::new();
loop {
@ -450,6 +465,21 @@ impl Parser {
}
Ok(AST(statements))
}
*/
parse_method!(program, self, ParseResult<AST>, {
let mut statements = Vec::new();
loop {
match self.peek() {
EOF => break,
Newline | Semicolon => {
self.next();
continue;
},
_ => statements.push(self.statement()?),
}
}
Ok(AST(statements))
});
fn statement(&mut self) -> ParseResult<Statement> {
//TODO handle error recovery here