rust-analyzer/crates/ra_syntax/src/parsing.rs

30 lines
795 B
Rust
Raw Normal View History

2019-02-21 12:24:42 +00:00
//! Lexing, bridging to ra_parser (which does the actual parsing) and
//! incremental reparsing.
mod lexer;
2019-02-23 13:07:29 +00:00
mod text_token_source;
mod text_tree_sink;
mod reparsing;
use crate::{syntax_node::GreenNode, SyntaxError};
use text_token_source::TextTokenSource;
use text_tree_sink::TextTreeSink;
pub use lexer::*;
pub(crate) use self::reparsing::incremental_reparse;
pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
let (tokens, lexer_errors) = tokenize(&text);
let mut token_source = TextTokenSource::new(text, &tokens);
let mut tree_sink = TextTreeSink::new(text, &tokens);
2019-05-25 12:31:53 +00:00
ra_parser::parse(&mut token_source, &mut tree_sink);
let (tree, mut parser_errors) = tree_sink.finish();
parser_errors.extend(lexer_errors);
(tree, parser_errors)
}