mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
simiplify
This commit is contained in:
parent
d52ee59a71
commit
773ad2edb3
2 changed files with 10 additions and 11 deletions
|
@ -143,18 +143,17 @@ impl Parse<SourceFile> {
|
||||||
pub use crate::ast::SourceFile;
|
pub use crate::ast::SourceFile;
|
||||||
|
|
||||||
impl SourceFile {
|
impl SourceFile {
|
||||||
fn new(green: GreenNode) -> SourceFile {
|
pub fn parse(text: &str) -> Parse<SourceFile> {
|
||||||
let root = SyntaxNode::new_root(green);
|
let (green, mut errors) = parsing::parse_text(text);
|
||||||
|
let root = SyntaxNode::new_root(green.clone());
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
validation::validate_block_structure(&root);
|
validation::validate_block_structure(&root);
|
||||||
}
|
}
|
||||||
assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE);
|
|
||||||
SourceFile::cast(root).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse(text: &str) -> Parse<SourceFile> {
|
errors.extend(validation::validate(&root));
|
||||||
let (green, mut errors) = parsing::parse_text(text);
|
|
||||||
errors.extend(validation::validate(&SourceFile::new(green.clone())));
|
assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE);
|
||||||
Parse { green, errors: Arc::new(errors), _ty: PhantomData }
|
Parse { green, errors: Arc::new(errors), _ty: PhantomData }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,16 +5,16 @@ mod field_expr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
algo::visit::{visitor_ctx, VisitorCtx},
|
algo::visit::{visitor_ctx, VisitorCtx},
|
||||||
ast, AstNode, SourceFile, SyntaxError,
|
ast, SyntaxError,
|
||||||
SyntaxKind::{BYTE, BYTE_STRING, CHAR, STRING},
|
SyntaxKind::{BYTE, BYTE_STRING, CHAR, STRING},
|
||||||
SyntaxNode, TextUnit, T,
|
SyntaxNode, TextUnit, T,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use unescape::EscapeError;
|
pub(crate) use unescape::EscapeError;
|
||||||
|
|
||||||
pub(crate) fn validate(file: &SourceFile) -> Vec<SyntaxError> {
|
pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
|
||||||
let mut errors = Vec::new();
|
let mut errors = Vec::new();
|
||||||
for node in file.syntax().descendants() {
|
for node in root.descendants() {
|
||||||
let _ = visitor_ctx(&mut errors)
|
let _ = visitor_ctx(&mut errors)
|
||||||
.visit::<ast::Literal, _>(validate_literal)
|
.visit::<ast::Literal, _>(validate_literal)
|
||||||
.visit::<ast::Block, _>(block::validate_block_node)
|
.visit::<ast::Block, _>(block::validate_block_node)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue