mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 03:33:59 +00:00
flattern module structure
This commit is contained in:
parent
2acb21e8f7
commit
cce23fddba
@ -2,14 +2,20 @@
|
|||||||
mod token_set;
|
mod token_set;
|
||||||
mod builder;
|
mod builder;
|
||||||
mod lexer;
|
mod lexer;
|
||||||
mod parser_impl;
|
mod event;
|
||||||
|
mod input;
|
||||||
mod parser_api;
|
mod parser_api;
|
||||||
mod grammar;
|
mod grammar;
|
||||||
mod reparsing;
|
mod reparsing;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
SyntaxError, SyntaxKind, SmolStr,
|
SyntaxError, SyntaxKind, SmolStr,
|
||||||
parsing::builder::GreenBuilder,
|
parsing::{
|
||||||
|
builder::GreenBuilder,
|
||||||
|
input::ParserInput,
|
||||||
|
event::EventProcessor,
|
||||||
|
parser_api::Parser,
|
||||||
|
},
|
||||||
syntax_node::GreenNode,
|
syntax_node::GreenNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -19,9 +25,22 @@ pub(crate) use self::reparsing::incremental_reparse;
|
|||||||
|
|
||||||
pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
|
pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
|
||||||
let tokens = tokenize(&text);
|
let tokens = tokenize(&text);
|
||||||
let (green, errors) =
|
parse_with(GreenBuilder::new(), text, &tokens, grammar::root)
|
||||||
parser_impl::parse_with(GreenBuilder::new(), text, &tokens, grammar::root);
|
}
|
||||||
(green, errors)
|
|
||||||
|
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.
|
/// `TreeSink` abstracts details of a particular syntax tree implementation.
|
||||||
|
@ -20,7 +20,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
parsing::{
|
parsing::{
|
||||||
lexer::Token,
|
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.
|
/// 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();
|
let mut forward_parents = Vec::new();
|
||||||
|
|
||||||
for i in 0..self.events.len() {
|
for i in 0..self.events.len() {
|
@ -1,8 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit,
|
SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit,
|
||||||
parsing::{
|
parsing::{
|
||||||
TokenPos,
|
TokenPos, TokenSource,
|
||||||
parser_impl::TokenSource,
|
|
||||||
lexer::Token,
|
lexer::Token,
|
||||||
},
|
},
|
||||||
};
|
};
|
@ -8,7 +8,7 @@ use crate::{
|
|||||||
parsing::{
|
parsing::{
|
||||||
TokenSource, TokenPos,
|
TokenSource, TokenPos,
|
||||||
token_set::TokenSet,
|
token_set::TokenSet,
|
||||||
parser_impl::event::Event,
|
event::Event,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,8 +4,7 @@ use crate::{
|
|||||||
syntax_node::{GreenNode, SyntaxNode},
|
syntax_node::{GreenNode, SyntaxNode},
|
||||||
syntax_error::SyntaxError,
|
syntax_error::SyntaxError,
|
||||||
parsing::{
|
parsing::{
|
||||||
grammar,
|
grammar, parse_with,
|
||||||
parser_impl,
|
|
||||||
builder::GreenBuilder,
|
builder::GreenBuilder,
|
||||||
parser_api::Parser,
|
parser_api::Parser,
|
||||||
lexer::{tokenize, Token},
|
lexer::{tokenize, Token},
|
||||||
@ -62,8 +61,7 @@ fn reparse_block<'node>(
|
|||||||
if !is_balanced(&tokens) {
|
if !is_balanced(&tokens) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let (green, new_errors) =
|
let (green, new_errors) = parse_with(GreenBuilder::new(), &text, &tokens, reparser);
|
||||||
parser_impl::parse_with(GreenBuilder::new(), &text, &tokens, reparser);
|
|
||||||
Some((node, green, new_errors))
|
Some((node, green, new_errors))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user