aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/lib.rs')
-rw-r--r--crates/libsyntax2/src/lib.rs38
1 files changed, 3 insertions, 35 deletions
diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs
index 7a30f5d38..d955c01e7 100644
--- a/crates/libsyntax2/src/lib.rs
+++ b/crates/libsyntax2/src/lib.rs
@@ -66,7 +66,9 @@ impl File {
66 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> File { 66 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> File {
67 let root = SyntaxRoot::new(green, errors); 67 let root = SyntaxRoot::new(green, errors);
68 let root = SyntaxNode::new_owned(root); 68 let root = SyntaxNode::new_owned(root);
69 validate_block_structure(root.borrowed()); 69 if cfg!(debug_assertions) {
70 utils::validate_block_structure(root.borrowed());
71 }
70 File { root } 72 File { root }
71 } 73 }
72 pub fn parse(text: &str) -> File { 74 pub fn parse(text: &str) -> File {
@@ -112,40 +114,6 @@ impl File {
112 } 114 }
113} 115}
114 116
115#[cfg(not(debug_assertions))]
116fn validate_block_structure(_: SyntaxNodeRef) {}
117
118#[cfg(debug_assertions)]
119fn validate_block_structure(root: SyntaxNodeRef) {
120 let mut stack = Vec::new();
121 for node in algo::walk::preorder(root) {
122 match node.kind() {
123 SyntaxKind::L_CURLY => {
124 stack.push(node)
125 }
126 SyntaxKind::R_CURLY => {
127 if let Some(pair) = stack.pop() {
128 assert_eq!(
129 node.parent(),
130 pair.parent(),
131 "\nunpaired curleys:\n{}\n{}\n",
132 root.text(),
133 utils::dump_tree(root),
134 );
135 assert!(
136 node.next_sibling().is_none() && pair.prev_sibling().is_none(),
137 "\nfloating curlys at {:?}\nfile:\n{}\nerror:\n{}\n",
138 node,
139 root.text(),
140 node.text(),
141 );
142 }
143 }
144 _ => (),
145 }
146 }
147}
148
149#[derive(Debug, Clone)] 117#[derive(Debug, Clone)]
150pub struct AtomEdit { 118pub struct AtomEdit {
151 pub delete: TextRange, 119 pub delete: TextRange,