From 85c42fba1291f1cc41fb7bfec63117895b394fc5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 4 Feb 2018 16:46:26 +0300 Subject: Support contextual tokens --- tools/src/bin/gen.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tools') 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() { #[derive(Deserialize)] struct Grammar { keywords: Vec, + contextual_keywords: Vec, tokens: Vec, nodes: Vec, } @@ -38,10 +39,9 @@ impl Grammar { acc.push_str("use tree::SyntaxInfo;\n"); acc.push_str("\n"); - let syntax_kinds: Vec = self.keywords - .iter() - .map(|kw| kw_token(kw)) - .chain(self.tokens.iter().cloned()) + let syntax_kinds: Vec =self.tokens.iter().cloned() + .chain(self.keywords.iter().map(|kw| kw_token(kw))) + .chain(self.contextual_keywords.iter().map(|kw| kw_token(kw))) .chain(self.nodes.iter().cloned()) .collect(); @@ -86,6 +86,7 @@ impl Grammar { // fn ident_to_keyword acc.push_str("pub(crate) fn ident_to_keyword(ident: &str) -> Option {\n"); acc.push_str(" match ident {\n"); + // NB: no contextual_keywords here! for kw in self.keywords.iter() { write!(acc, " {:?} => Some({}),\n", kw, kw_token(kw)).unwrap(); } -- cgit v1.2.3 From 351107d0b143e2c3497bd0f424f0d76bc51df0c0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 4 Feb 2018 17:06:43 +0300 Subject: Reformat --- tools/src/bin/gen.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/src/bin/gen.rs b/tools/src/bin/gen.rs index c71e6da73..7cb164316 100644 --- a/tools/src/bin/gen.rs +++ b/tools/src/bin/gen.rs @@ -39,7 +39,9 @@ impl Grammar { acc.push_str("use tree::SyntaxInfo;\n"); acc.push_str("\n"); - let syntax_kinds: Vec =self.tokens.iter().cloned() + let syntax_kinds: Vec = self.tokens + .iter() + .cloned() .chain(self.keywords.iter().map(|kw| kw_token(kw))) .chain(self.contextual_keywords.iter().map(|kw| kw_token(kw))) .chain(self.nodes.iter().cloned()) -- cgit v1.2.3