nodes for blocks

This commit is contained in:
Aleksey Kladov 2018-08-24 19:27:30 +03:00
parent 4d29300396
commit 7edab6ae6b
122 changed files with 1743 additions and 1535 deletions

View file

@ -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(),
);
}
}
_ => (),
}
}
}