refactor: extract debug output method

上级 895f9340
......@@ -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();
......
......@@ -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<ILocation>, id: i32, name: Option<String>, content_name: Option<String>) -> Self {
pub fn new(location: Option<ILocation>, id: i32, name: Option<String>, content_name: Option<String>, 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
}
}
}
......
......@@ -57,12 +57,7 @@ impl RuleFactory {
pub fn create_capture_rule(helper: &mut Grammar, location: Option<ILocation>, name: Option<String>, content_name: Option<String>, retokenizeCapturedWithRuleId: i32) -> Box<dyn AbstractRule> {
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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册