aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-02-04 13:46:26 +0000
committerAleksey Kladov <[email protected]>2018-02-04 13:46:26 +0000
commit85c42fba1291f1cc41fb7bfec63117895b394fc5 (patch)
treecda942a62d244f6352dd870cf4c4e68f739909b5 /tools
parent852543212ba5c68b3428a80187087cc641de612c (diff)
Support contextual tokens
Diffstat (limited to 'tools')
-rw-r--r--tools/src/bin/gen.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/tools/src/bin/gen.rs b/tools/src/bin/gen.rs
index 17cdea7a1..c71e6da73 100644
--- a/tools/src/bin/gen.rs
+++ b/tools/src/bin/gen.rs
@@ -20,6 +20,7 @@ fn main() {
20#[derive(Deserialize)] 20#[derive(Deserialize)]
21struct Grammar { 21struct Grammar {
22 keywords: Vec<String>, 22 keywords: Vec<String>,
23 contextual_keywords: Vec<String>,
23 tokens: Vec<String>, 24 tokens: Vec<String>,
24 nodes: Vec<String>, 25 nodes: Vec<String>,
25} 26}
@@ -38,10 +39,9 @@ impl Grammar {
38 acc.push_str("use tree::SyntaxInfo;\n"); 39 acc.push_str("use tree::SyntaxInfo;\n");
39 acc.push_str("\n"); 40 acc.push_str("\n");
40 41
41 let syntax_kinds: Vec<String> = self.keywords 42 let syntax_kinds: Vec<String> =self.tokens.iter().cloned()
42 .iter() 43 .chain(self.keywords.iter().map(|kw| kw_token(kw)))
43 .map(|kw| kw_token(kw)) 44 .chain(self.contextual_keywords.iter().map(|kw| kw_token(kw)))
44 .chain(self.tokens.iter().cloned())
45 .chain(self.nodes.iter().cloned()) 45 .chain(self.nodes.iter().cloned())
46 .collect(); 46 .collect();
47 47
@@ -86,6 +86,7 @@ impl Grammar {
86 // fn ident_to_keyword 86 // fn ident_to_keyword
87 acc.push_str("pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> {\n"); 87 acc.push_str("pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> {\n");
88 acc.push_str(" match ident {\n"); 88 acc.push_str(" match ident {\n");
89 // NB: no contextual_keywords here!
89 for kw in self.keywords.iter() { 90 for kw in self.keywords.iter() {
90 write!(acc, " {:?} => Some({}),\n", kw, kw_token(kw)).unwrap(); 91 write!(acc, " {:?} => Some({}),\n", kw, kw_token(kw)).unwrap();
91 } 92 }