Extract libeditor

This commit is contained in:
Aleksey Kladov
2018-08-01 10:40:07 +03:00
parent b9189ed2db
commit 966e9db2b8
15 changed files with 138 additions and 50 deletions
+1 -1
View File
@@ -76,7 +76,7 @@ pub(crate) enum Event {
},
}
pub(super) fn process(builder: &mut impl Sink, tokens: &[Token], events: Vec<Event>) {
pub(super) fn process<'a>(builder: &mut impl Sink<'a>, tokens: &[Token], events: Vec<Event>) {
let mut idx = 0;
let mut holes = Vec::new();
+4 -4
View File
@@ -14,10 +14,10 @@
use SyntaxKind::{self, EOF, TOMBSTONE};
pub(crate) trait Sink {
pub(crate) trait Sink<'a> {
type Tree;
fn new(text: String) -> Self;
fn new(text: &'a str) -> Self;
fn leaf(&mut self, kind: SyntaxKind, len: TextUnit);
fn start_internal(&mut self, kind: SyntaxKind);
@@ -27,9 +27,9 @@ pub(crate) trait Sink {
}
/// Parse a sequence of tokens into the representative node tree
pub(crate) fn parse<S: Sink>(text: String, tokens: &[Token]) -> S::Tree {
pub(crate) fn parse<'a, S: Sink<'a>>(text: &'a str, tokens: &[Token]) -> S::Tree {
let events = {
let input = input::ParserInput::new(&text, tokens);
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);