mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
nodes for blocks
This commit is contained in:
parent
4d29300396
commit
7edab6ae6b
122 changed files with 1743 additions and 1535 deletions
|
@ -53,5 +53,31 @@ pub use {
|
|||
|
||||
pub fn parse(text: &str) -> SyntaxNode {
|
||||
let tokens = tokenize(&text);
|
||||
parser_impl::parse::<yellow::GreenBuilder>(text, &tokens)
|
||||
let res = parser_impl::parse::<yellow::GreenBuilder>(text, &tokens);
|
||||
validate_block_structure(res.borrowed());
|
||||
res
|
||||
}
|
||||
|
||||
fn validate_block_structure(root: SyntaxNodeRef) {
|
||||
let mut stack = Vec::new();
|
||||
for node in algo::walk::preorder(root) {
|
||||
match node.kind() {
|
||||
SyntaxKind::L_CURLY => {
|
||||
stack.push(node)
|
||||
}
|
||||
SyntaxKind::R_CURLY => {
|
||||
if let Some(pair) = stack.pop() {
|
||||
assert_eq!(node.parent(), pair.parent());
|
||||
assert!(
|
||||
node.next_sibling().is_none() && pair.prev_sibling().is_none(),
|
||||
"floating curlys at {:?}\nfile:\n{}\nerror:\n{}\n",
|
||||
node,
|
||||
root.text(),
|
||||
node.text(),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue