aboutsummaryrefslogtreecommitdiff
path: root/tools/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-30 16:02:13 +0100
committerAleksey Kladov <[email protected]>2018-07-30 16:02:13 +0100
commit60e8a845cafb9630caa034b886368160a12dcd64 (patch)
treeb72110591d851266ba5cd4b81a72c50021589b4f /tools/src
parent7fb7cfc2d1cd2781a20e4034b12384566d13c728 (diff)
simplify codegen
Diffstat (limited to 'tools/src')
-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> {