aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-24 17:27:30 +0100
committerAleksey Kladov <[email protected]>2018-08-24 17:27:30 +0100
commit7edab6ae6b4c5d0c411e88f10e923b91dca31de3 (patch)
tree4c17856285f568c56adb7c02024ef80e821dd367 /crates/libsyntax2/src/lib.rs
parent4d293003964c8f9fabadb1ceb77eab29c0438de3 (diff)
nodes for blocks
Diffstat (limited to 'crates/libsyntax2/src/lib.rs')
-rw-r--r--crates/libsyntax2/src/lib.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs
index 53ae18988..d3ecbe470 100644
--- a/crates/libsyntax2/src/lib.rs
+++ b/crates/libsyntax2/src/lib.rs
@@ -53,5 +53,31 @@ pub use {
53 53
54pub fn parse(text: &str) -> SyntaxNode { 54pub fn parse(text: &str) -> SyntaxNode {
55 let tokens = tokenize(&text); 55 let tokens = tokenize(&text);
56 parser_impl::parse::<yellow::GreenBuilder>(text, &tokens) 56 let res = parser_impl::parse::<yellow::GreenBuilder>(text, &tokens);
57 validate_block_structure(res.borrowed());
58 res
59}
60
61fn validate_block_structure(root: SyntaxNodeRef) {
62 let mut stack = Vec::new();
63 for node in algo::walk::preorder(root) {
64 match node.kind() {
65 SyntaxKind::L_CURLY => {
66 stack.push(node)
67 }
68 SyntaxKind::R_CURLY => {
69 if let Some(pair) = stack.pop() {
70 assert_eq!(node.parent(), pair.parent());
71 assert!(
72 node.next_sibling().is_none() && pair.prev_sibling().is_none(),
73 "floating curlys at {:?}\nfile:\n{}\nerror:\n{}\n",
74 node,
75 root.text(),
76 node.text(),
77 );
78 }
79 }
80 _ => (),
81 }
82 }
57} 83}