incremental reparse

This commit is contained in:
Aleksey Kladov 2018-08-25 14:45:17 +03:00
parent 5211e7d977
commit c3e5987c43
5 changed files with 104 additions and 13 deletions

View file

@ -2,7 +2,6 @@ mod event;
mod input;
use {
grammar,
lexer::Token,
parser_api::Parser,
parser_impl::{
@ -27,12 +26,16 @@ pub(crate) trait Sink<'a> {
}
/// Parse a sequence of tokens into the representative node tree
pub(crate) fn parse<'a, S: Sink<'a>>(text: &'a str, tokens: &[Token]) -> S::Tree {
pub(crate) fn parse_with<'a, S: Sink<'a>>(
text: &'a str,
tokens: &[Token],
parser: fn(&mut Parser),
) -> S::Tree {
let events = {
let input = input::ParserInput::new(text, tokens);
let parser_impl = ParserImpl::new(&input);
let mut parser_api = Parser(parser_impl);
grammar::file(&mut parser_api);
parser(&mut parser_api);
parser_api.0.into_events()
};
let mut sink = S::new(text);