flattern module structure

This commit is contained in:
Aleksey Kladov 2019-02-20 22:52:32 +03:00
parent 2acb21e8f7
commit cce23fddba
5 changed files with 30 additions and 14 deletions

View File

@ -2,14 +2,20 @@
mod token_set;
mod builder;
mod lexer;
mod parser_impl;
mod event;
mod input;
mod parser_api;
mod grammar;
mod reparsing;
use crate::{
SyntaxError, SyntaxKind, SmolStr,
parsing::builder::GreenBuilder,
parsing::{
builder::GreenBuilder,
input::ParserInput,
event::EventProcessor,
parser_api::Parser,
},
syntax_node::GreenNode,
};
@ -19,9 +25,22 @@ pub(crate) use self::reparsing::incremental_reparse;
pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
let tokens = tokenize(&text);
let (green, errors) =
parser_impl::parse_with(GreenBuilder::new(), text, &tokens, grammar::root);
(green, errors)
parse_with(GreenBuilder::new(), text, &tokens, grammar::root)
}
fn parse_with<S: TreeSink>(
tree_sink: S,
text: &str,
tokens: &[Token],
f: fn(&mut Parser),
) -> S::Tree {
let mut events = {
let input = ParserInput::new(text, &tokens);
let mut p = Parser::new(&input);
f(&mut p);
p.finish()
};
EventProcessor::new(tree_sink, text, tokens, &mut events).process().finish()
}
/// `TreeSink` abstracts details of a particular syntax tree implementation.

View File

@ -20,7 +20,7 @@ use crate::{
},
parsing::{
lexer::Token,
parser_impl::TreeSink,
TreeSink,
},
};
@ -113,7 +113,7 @@ impl<'a, S: TreeSink> EventProcessor<'a, S> {
}
/// Generate the syntax tree with the control of events.
pub(super) fn process(mut self) -> S {
pub(crate) fn process(mut self) -> S {
let mut forward_parents = Vec::new();
for i in 0..self.events.len() {

View File

@ -1,8 +1,7 @@
use crate::{
SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit,
parsing::{
TokenPos,
parser_impl::TokenSource,
TokenPos, TokenSource,
lexer::Token,
},
};

View File

@ -8,7 +8,7 @@ use crate::{
parsing::{
TokenSource, TokenPos,
token_set::TokenSet,
parser_impl::event::Event,
event::Event,
},
};

View File

@ -4,8 +4,7 @@ use crate::{
syntax_node::{GreenNode, SyntaxNode},
syntax_error::SyntaxError,
parsing::{
grammar,
parser_impl,
grammar, parse_with,
builder::GreenBuilder,
parser_api::Parser,
lexer::{tokenize, Token},
@ -62,8 +61,7 @@ fn reparse_block<'node>(
if !is_balanced(&tokens) {
return None;
}
let (green, new_errors) =
parser_impl::parse_with(GreenBuilder::new(), &text, &tokens, reparser);
let (green, new_errors) = parse_with(GreenBuilder::new(), &text, &tokens, reparser);
Some((node, green, new_errors))
}