aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/src/main.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/tools/src/main.rs b/tools/src/main.rs
index 3290d1dce..7d7b2afc0 100644
--- a/tools/src/main.rs
+++ b/tools/src/main.rs
@@ -6,7 +6,7 @@ extern crate tera;
6extern crate walkdir; 6extern crate walkdir;
7extern crate tools; 7extern crate tools;
8 8
9use std::{collections::HashSet, fs, path::Path}; 9use std::{collections::{HashSet, HashMap}, fs, path::Path};
10use clap::{App, Arg, SubCommand}; 10use clap::{App, Arg, SubCommand};
11use tools::{collect_tests, Test}; 11use tools::{collect_tests, Test};
12 12
@@ -63,9 +63,26 @@ fn update(path: &Path, contents: &str, verify: bool) -> Result<()> {
63fn get_kinds() -> Result<String> { 63fn get_kinds() -> Result<String> {
64 let grammar = grammar()?; 64 let grammar = grammar()?;
65 let template = fs::read_to_string(SYNTAX_KINDS_TEMPLATE)?; 65 let template = fs::read_to_string(SYNTAX_KINDS_TEMPLATE)?;
66 let ret = tera::Tera::one_off(&template, &grammar, false) 66 let mut tera = tera::Tera::default();
67 tera.add_raw_template("grammar", &template)
67 .map_err(|e| format_err!("template error: {:?}", e))?; 68 .map_err(|e| format_err!("template error: {:?}", e))?;
68 Ok(ret) 69 tera.register_global_function("concat", Box::new(concat));
70 let ret = tera.render("grammar", &grammar)
71 .map_err(|e| format_err!("template error: {:?}", e))?;
72 return Ok(ret);
73
74 fn concat(args: HashMap<String, tera::Value>) -> tera::Result<tera::Value> {
75 let mut elements = Vec::new();
76 for &key in ["a", "b", "c"].iter() {
77 let val = match args.get(key) {
78 Some(val) => val,
79 None => continue,
80 };
81 let val = val.as_array().unwrap();
82 elements.extend(val.iter().cloned());
83 }
84 Ok(tera::Value::Array(elements))
85 }
69} 86}
70 87
71fn grammar() -> Result<ron::value::Value> { 88fn grammar() -> Result<ron::value::Value> {