diff options
author | Aleksey Kladov <[email protected]> | 2018-07-30 19:58:49 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-07-30 19:58:49 +0100 |
commit | ac0d8c48f7a277d4a43448fe7dd4279383bc53f0 (patch) | |
tree | 5fe6d1f761f15d1e2d63fc4e9be0c16e2f0b3d93 /src/ast.rs | |
parent | 6fc66c4ee667da871ea1f0c8b48b5e9b7373a187 (diff) |
JS plugin
Diffstat (limited to 'src/ast.rs')
-rw-r--r-- | src/ast.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ast.rs b/src/ast.rs new file mode 100644 index 000000000..3a9287466 --- /dev/null +++ b/src/ast.rs | |||
@@ -0,0 +1,30 @@ | |||
1 | use std::sync::Arc; | ||
2 | use {SyntaxNode, TreeRoot, SyntaxRoot, SyntaxNodeRef}; | ||
3 | |||
4 | #[derive(Debug)] | ||
5 | pub struct File<R: TreeRoot = Arc<SyntaxRoot>> { | ||
6 | syntax: SyntaxNode<R> | ||
7 | } | ||
8 | |||
9 | impl File<Arc<SyntaxRoot>> { | ||
10 | pub fn parse(text: &str) -> Self { | ||
11 | File { syntax: ::parse(text.to_owned()) } | ||
12 | } | ||
13 | } | ||
14 | |||
15 | impl<R: TreeRoot> File<R> { | ||
16 | pub fn syntax(&self) -> SyntaxNode<R> { | ||
17 | self.syntax.clone() | ||
18 | } | ||
19 | |||
20 | pub fn for_each_node(&self, mut f: impl FnMut(SyntaxNodeRef)) { | ||
21 | let syntax = self.syntax(); | ||
22 | let syntax = syntax.borrow(); | ||
23 | go(syntax, &mut f); | ||
24 | |||
25 | fn go(syntax: SyntaxNodeRef, f: &mut FnMut(SyntaxNodeRef)) { | ||
26 | f(syntax); | ||
27 | syntax.children().into_iter().for_each(f) | ||
28 | } | ||
29 | } | ||
30 | } | ||