Changing what method to call to start parsing

This commit is contained in:
greg 2018-10-20 15:41:09 -07:00
parent 6b42f8b8de
commit d7baf065fb
3 changed files with 16 additions and 6 deletions

View File

@ -445,7 +445,7 @@ mod eval_tests {
fn parse(tokens: Vec<Token>) -> ParseResult<AST> {
let mut parser = ::parsing::Parser::new(tokens);
parser.program()
parser.parse()
}
macro_rules! all_output {

View File

@ -102,7 +102,7 @@ fn parsing(handle: &mut Schala, input: Vec<tokenizing::Token>, comp: Option<&mut
Some(parser) => parser
};
let ast = parser.program();
let ast = parser.parse();
let trace = parser.format_parse_trace();
comp.map(|comp| {

View File

@ -46,9 +46,9 @@ struct ParserRestrictions {
}
impl Parser {
pub fn new(input: Vec<Token>) -> Parser {
pub fn new(initial_input: Vec<Token>) -> Parser {
Parser {
tokens: input.into_iter().peekable(),
tokens: initial_input.into_iter().peekable(),
parse_record: vec![],
parse_level: 0,
restrictions: ParserRestrictions { no_struct_literal: false }
@ -65,6 +65,16 @@ impl Parser {
self.tokens.next().map(|ref t| { t.token_type.clone() }).unwrap_or(TokenType::EOF)
}
pub fn parse(&mut self) -> ParseResult<AST> {
self.program()
}
/*
pub fn parse_with_new_tokens(&mut self, new_tokens: Vec<Token>) -> ParseResult<AST> {
}
*/
pub fn format_parse_trace(self) -> Vec<String> {
self.parse_record.into_iter().map(|r| {
let mut indent = String::new();
@ -252,7 +262,7 @@ enumerator := identifier '<-' expression | identifier '=' expression //TODO add
impl Parser {
//TODO make this a proper public interface
#[recursive_descent_method]
pub fn program(&mut self) -> ParseResult<AST> {
fn program(&mut self) -> ParseResult<AST> {
let mut statements = Vec::new();
loop {
match self.peek() {
@ -1063,7 +1073,7 @@ mod parse_tests {
fn parse(tokens: Vec<::tokenizing::Token>) -> ParseResult<AST> {
let mut parser = super::Parser::new(tokens);
parser.program()
parser.parse()
}
macro_rules! rc {