New abstraction layer in Schala-lang parser
Just for manipulating tokens
This commit is contained in:
parent
37070a6b3e
commit
f883512882
@ -35,7 +35,7 @@ pub struct ParseRecord {
|
||||
}
|
||||
|
||||
pub struct Parser {
|
||||
tokens: Peekable<IntoIter<Token>>,
|
||||
token_handler: TokenHandler,
|
||||
parse_record: Vec<ParseRecord>,
|
||||
parse_level: u32,
|
||||
restrictions: ParserRestrictions,
|
||||
@ -45,14 +45,14 @@ struct ParserRestrictions {
|
||||
no_struct_literal: bool
|
||||
}
|
||||
|
||||
impl Parser {
|
||||
pub fn new(initial_input: Vec<Token>) -> Parser {
|
||||
Parser {
|
||||
tokens: initial_input.into_iter().peekable(),
|
||||
parse_record: vec![],
|
||||
parse_level: 0,
|
||||
restrictions: ParserRestrictions { no_struct_literal: false }
|
||||
struct TokenHandler {
|
||||
tokens: Peekable<IntoIter<Token>>,
|
||||
}
|
||||
|
||||
impl TokenHandler {
|
||||
fn new(tokens: Vec<Token>) -> TokenHandler {
|
||||
let tokens = tokens.into_iter().peekable();
|
||||
TokenHandler { tokens }
|
||||
}
|
||||
|
||||
fn peek(&mut self) -> TokenType {
|
||||
@ -64,6 +64,27 @@ impl Parser {
|
||||
fn next(&mut self) -> TokenType {
|
||||
self.tokens.next().map(|ref t| { t.token_type.clone() }).unwrap_or(TokenType::EOF)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parser {
|
||||
pub fn new(initial_input: Vec<Token>) -> Parser {
|
||||
Parser {
|
||||
token_handler: TokenHandler::new(initial_input),
|
||||
parse_record: vec![],
|
||||
parse_level: 0,
|
||||
restrictions: ParserRestrictions { no_struct_literal: false }
|
||||
}
|
||||
}
|
||||
|
||||
fn peek(&mut self) -> TokenType {
|
||||
self.token_handler.peek()
|
||||
}
|
||||
fn peek_with_token_offset(&mut self) -> Token {
|
||||
self.token_handler.peek_with_token_offset()
|
||||
}
|
||||
fn next(&mut self) -> TokenType {
|
||||
self.token_handler.next()
|
||||
}
|
||||
|
||||
pub fn parse(&mut self) -> ParseResult<AST> {
|
||||
self.program()
|
||||
|
Loading…
Reference in New Issue
Block a user