mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
kill utils module
This commit is contained in:
parent
9be7426aae
commit
f7f99af0a6
10 changed files with 101 additions and 114 deletions
|
@ -5,7 +5,8 @@ mod string;
|
|||
mod block;
|
||||
|
||||
use crate::{
|
||||
SourceFile, SyntaxError, AstNode,
|
||||
SourceFile, SyntaxError, AstNode, SyntaxNode,
|
||||
SyntaxKind::{L_CURLY, R_CURLY},
|
||||
ast,
|
||||
algo::visit::{visitor_ctx, VisitorCtx},
|
||||
};
|
||||
|
@ -14,12 +15,40 @@ pub(crate) fn validate(file: &SourceFile) -> Vec<SyntaxError> {
|
|||
let mut errors = Vec::new();
|
||||
for node in file.syntax().descendants() {
|
||||
let _ = visitor_ctx(&mut errors)
|
||||
.visit::<ast::Byte, _>(self::byte::validate_byte_node)
|
||||
.visit::<ast::ByteString, _>(self::byte_string::validate_byte_string_node)
|
||||
.visit::<ast::Char, _>(self::char::validate_char_node)
|
||||
.visit::<ast::String, _>(self::string::validate_string_node)
|
||||
.visit::<ast::Block, _>(self::block::validate_block_node)
|
||||
.visit::<ast::Byte, _>(byte::validate_byte_node)
|
||||
.visit::<ast::ByteString, _>(byte_string::validate_byte_string_node)
|
||||
.visit::<ast::Char, _>(char::validate_char_node)
|
||||
.visit::<ast::String, _>(string::validate_string_node)
|
||||
.visit::<ast::Block, _>(block::validate_block_node)
|
||||
.accept(node);
|
||||
}
|
||||
errors
|
||||
}
|
||||
|
||||
pub(crate) fn validate_block_structure(root: &SyntaxNode) {
|
||||
let mut stack = Vec::new();
|
||||
for node in root.descendants() {
|
||||
match node.kind() {
|
||||
L_CURLY => stack.push(node),
|
||||
R_CURLY => {
|
||||
if let Some(pair) = stack.pop() {
|
||||
assert_eq!(
|
||||
node.parent(),
|
||||
pair.parent(),
|
||||
"\nunpaired curleys:\n{}\n{}\n",
|
||||
root.text(),
|
||||
root.debug_dump(),
|
||||
);
|
||||
assert!(
|
||||
node.next_sibling().is_none() && pair.prev_sibling().is_none(),
|
||||
"\nfloating curlys at {:?}\nfile:\n{}\nerror:\n{}\n",
|
||||
node,
|
||||
root.text(),
|
||||
node.text(),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue