diff --git a/scie-grammar/src/grammar/grammar/mod.rs b/scie-grammar/src/grammar/grammar/mod.rs index b11fec0f5fc9177fcd9489426015d1a89ecda004..60358d2174d87133074ef8e94792e1d247ff1450 100644 --- a/scie-grammar/src/grammar/grammar/mod.rs +++ b/scie-grammar/src/grammar/grammar/mod.rs @@ -223,9 +223,7 @@ return 0; // todo: fixed it // assert_eq!(grammar.rule_id2desc.len(), 162); - let j = serde_json::to_string(&grammar.rule_id2desc).unwrap(); - let mut file = File::create("program.json").unwrap(); - file.write_all(j.as_bytes()); + // debug_output(&grammar, String::from("program.json")); } #[test] @@ -238,11 +236,22 @@ GitHub 漫游指南- a Chinese ebook on how to build a good project on Github. E let grammar = to_grammar("test-cases/first-mate/fixtures/text.json", code); assert_eq!(grammar.rule_id2desc.len(), 8); + } + + fn debug_output(grammar: &Grammar, path: String) { let j = serde_json::to_string(&grammar.rule_id2desc).unwrap(); - let mut file = File::create("program.json").unwrap(); + let mut file = File::create(path).unwrap(); file.write_all(j.as_bytes()); } + #[test] + fn should_build_json_grammar() { + let code = "{}"; + let grammar = to_grammar("test-cases/first-mate/fixtures/json.json", code); + assert_eq!(grammar.rule_id2desc.len(), 22); + debug_output(&grammar, String::from("program.json")); + } + fn to_grammar(grammar_path: &str, code: &str) -> Grammar { let path = Path::new(grammar_path); let mut file = File::open(path).unwrap(); diff --git a/scie-grammar/src/rule/mod.rs b/scie-grammar/src/rule/mod.rs index cd017ace8a4be59b5be9afb8a4054efa09aee4a7..6461d2e2d71b8e03afd9a6610479574be949b924 100644 --- a/scie-grammar/src/rule/mod.rs +++ b/scie-grammar/src/rule/mod.rs @@ -237,6 +237,7 @@ impl AbstractRule for BeginEndRule { #[derive(Clone, Debug, Serialize)] pub struct CaptureRule { pub rule: Rule, + pub retokenize_captured_with_rule_id: i32 } impl CaptureRule { @@ -248,10 +249,11 @@ impl CaptureRule { id: 0, name: None, content_name: None - } + }, + retokenize_captured_with_rule_id: 0 } } - pub fn new(location: Option, id: i32, name: Option, content_name: Option) -> Self { + pub fn new(location: Option, id: i32, name: Option, content_name: Option, retokenize_captured_with_rule_id: i32) -> Self { CaptureRule { rule: Rule { _type: String::from("CaptureRule"), @@ -260,6 +262,7 @@ impl CaptureRule { name, content_name, }, + retokenize_captured_with_rule_id } } } diff --git a/scie-grammar/src/rule/rule_factory.rs b/scie-grammar/src/rule/rule_factory.rs index 0d91e8be3943438ce4c5f1204ef2500ec320d88b..0f035d5d0e2d882c08d027fe82fe08d22383e0be 100644 --- a/scie-grammar/src/rule/rule_factory.rs +++ b/scie-grammar/src/rule/rule_factory.rs @@ -57,12 +57,7 @@ impl RuleFactory { pub fn create_capture_rule(helper: &mut Grammar, location: Option, name: Option, content_name: Option, retokenizeCapturedWithRuleId: i32) -> Box { let id = helper.register_id(); - let rule = CaptureRule::new( - location, - id, - name, - content_name, - ); + let rule = CaptureRule::new(location, id, name, content_name, retokenizeCapturedWithRuleId); helper.register_rule(Box::from(rule)); return helper.get_rule(id); }