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) { let ast = match parsing::parse(tokens) {
Ok(ast) => { Ok(ast) => {
if options.debug_parse { if options.debug_parse {
output.add_artifact(TraceArtifact::new("Recursive descent calls:", format!("{:?}", "OI")));
output.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast))); output.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast)));
} }
ast ast

View File

@ -333,13 +333,16 @@ impl ParseError {
pub type ParseResult<T> = Result<T, ParseError>; pub type ParseResult<T> = Result<T, ParseError>;
pub struct ParseRecord(String);
struct Parser { struct Parser {
tokens: TokenIter, tokens: TokenIter,
parse_record: Vec<ParseRecord>,
} }
impl Parser { impl Parser {
fn new(input: Vec<Token>) -> 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 { 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 { impl Parser {
/*
fn program(&mut self) -> ParseResult<AST> { fn program(&mut self) -> ParseResult<AST> {
let mut statements = Vec::new(); let mut statements = Vec::new();
loop { loop {
@ -450,6 +465,21 @@ impl Parser {
} }
Ok(AST(statements)) 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> { fn statement(&mut self) -> ParseResult<Statement> {
//TODO handle error recovery here //TODO handle error recovery here