1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::{Parse, SmolStr, SyntaxKind};
use rslint_errors::Diagnostic;
use rslint_rowan::{GreenNodeBuilder, Language};
pub use rslint_rowan::GreenNode;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct JsLanguage;
impl Language for JsLanguage {
type Kind = SyntaxKind;
fn kind_from_raw(raw: rslint_rowan::SyntaxKind) -> SyntaxKind {
SyntaxKind::from(raw.0)
}
fn kind_to_raw(kind: SyntaxKind) -> rslint_rowan::SyntaxKind {
rslint_rowan::SyntaxKind(kind.into())
}
}
pub type SyntaxNode = rslint_rowan::SyntaxNode<JsLanguage>;
pub type SyntaxToken = rslint_rowan::SyntaxToken<JsLanguage>;
pub type SyntaxElement = rslint_rowan::SyntaxElement<JsLanguage>;
pub type SyntaxNodeChildren = rslint_rowan::SyntaxNodeChildren<JsLanguage>;
pub type SyntaxElementChildren = rslint_rowan::SyntaxElementChildren<JsLanguage>;
pub use rslint_rowan::{Direction, NodeOrToken};
#[derive(Default, Debug)]
pub struct SyntaxTreeBuilder {
errors: Vec<Diagnostic>,
inner: GreenNodeBuilder<'static>,
}
impl SyntaxTreeBuilder {
pub(crate) fn finish_raw(self) -> (GreenNode, Vec<Diagnostic>) {
let green = self.inner.finish();
(green, self.errors)
}
pub fn finish(self) -> Parse<SyntaxNode> {
let (green, errors) = self.finish_raw();
Parse::new(green, errors)
}
pub fn token(&mut self, kind: SyntaxKind, text: SmolStr) {
let kind = JsLanguage::kind_to_raw(kind);
self.inner.token(kind, text)
}
pub fn start_node(&mut self, kind: SyntaxKind) {
let kind = JsLanguage::kind_to_raw(kind);
self.inner.start_node(kind)
}
pub fn finish_node(&mut self) {
self.inner.finish_node()
}
pub fn error(&mut self, error: Diagnostic) {
self.errors.push(error)
}
}