mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-14 22:35:11 +00:00
introduce hacks module
This commit is contained in:
parent
aa1788dc71
commit
bfc263f1f9
6 changed files with 34 additions and 51 deletions
|
@ -5,7 +5,7 @@ mod reparsing;
|
|||
|
||||
use rowan::TextRange;
|
||||
|
||||
use crate::{syntax_node::GreenNode, AstNode, SyntaxError, SyntaxNode, SyntaxTreeBuilder};
|
||||
use crate::{syntax_node::GreenNode, SyntaxError, SyntaxTreeBuilder};
|
||||
|
||||
pub(crate) use crate::parsing::reparsing::incremental_reparse;
|
||||
|
||||
|
@ -17,26 +17,6 @@ pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
|
|||
(node, errors)
|
||||
}
|
||||
|
||||
/// Returns `text` parsed as a `T` provided there are no parse errors.
|
||||
pub(crate) fn parse_text_as<T: AstNode>(
|
||||
text: &str,
|
||||
entry_point: parser::ParserEntryPoint,
|
||||
) -> Result<T, ()> {
|
||||
let lexed = parser::LexedStr::new(text);
|
||||
if lexed.errors().next().is_some() {
|
||||
return Err(());
|
||||
}
|
||||
let parser_input = lexed.to_input();
|
||||
let parser_output = parser::parse(&parser_input, entry_point);
|
||||
let (node, errors, eof) = build_tree(lexed, parser_output, true);
|
||||
|
||||
if !errors.is_empty() || !eof {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
SyntaxNode::new_root(node).first_child().and_then(T::cast).ok_or(())
|
||||
}
|
||||
|
||||
pub(crate) fn build_tree(
|
||||
lexed: parser::LexedStr<'_>,
|
||||
parser_output: parser::Output,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue