feat: find the error testcases for scanner

上级 825df695
...@@ -526,6 +526,10 @@ impl Grammar { ...@@ -526,6 +526,10 @@ impl Grammar {
let mut rule = stack.get_rule(self); let mut rule = stack.get_rule(self);
let rule_info = rule.clone().get_rule_instance(); let rule_info = rule.clone().get_rule_instance();
if rule.get_rule().id == 36 {
println!("{:?}", line_pos);
}
let mut rule_scanner; let mut rule_scanner;
match rule_info { match rule_info {
RuleEnum::BeginEndRule(mut begin_end_rule) => { RuleEnum::BeginEndRule(mut begin_end_rule) => {
......
...@@ -111,9 +111,9 @@ impl Scanner { ...@@ -111,9 +111,9 @@ impl Scanner {
} }
pub fn str_vec_to_string<I, T>(iter: I) -> Vec<String> pub fn str_vec_to_string<I, T>(iter: I) -> Vec<String>
where where
I: IntoIterator<Item = T>, I: IntoIterator<Item=T>,
T: Into<String>, T: Into<String>,
{ {
iter.into_iter().map(Into::into).collect() iter.into_iter().map(Into::into).collect()
} }
...@@ -358,4 +358,23 @@ mod tests { ...@@ -358,4 +358,23 @@ mod tests {
assert_eq!(4, onig_match.capture_indices[0].start); assert_eq!(4, onig_match.capture_indices[0].start);
assert_eq!(4, onig_match.capture_indices[0].end); assert_eq!(4, onig_match.capture_indices[0].end);
} }
#[test]
fn should_return_correct_index_when_for_markdown() {
let origin = vec!["^", "\\\n", "%|\\*", "(^[ \t]+)?(?=#)", "(\\$?\\$)[@%<?^+*]", "\\$?\\$\\("];
let _rules = vec![-1, 37, 38, 2, 12, 14];
let debug_regex = str_vec_to_string(origin);
let mut scanner = Scanner::new(debug_regex);
let result = scanner.find_next_match_sync(
String::from(
"%.o: %.c $(DEPS)
",
),
4,
);
let onig_match = result.unwrap();
assert_eq!(2, onig_match.index);
assert_eq!(5, onig_match.capture_indices[0].start);
assert_eq!(6, onig_match.capture_indices[0].end);
}
} }
...@@ -919,6 +919,11 @@ function matchRule(grammar, lineText, isFirstLine, linePos, stack, anchorPositio ...@@ -919,6 +919,11 @@ function matchRule(grammar, lineText, isFirstLine, linePos, stack, anchorPositio
console.log("matched rule id: " + ruleScanner.rules[r.index] + " from " + r.captureIndices[0].start + " to " + r.captureIndices[0].end); console.log("matched rule id: " + ruleScanner.rules[r.index] + " from " + r.captureIndices[0].start + " to " + r.captureIndices[0].end);
} }
} }
if(rule.id === 36) {
console.log(lineText, linePos, stack.depth);
console.log(JSON.stringify(ruleScanner));
console.log(JSON.stringify(r));
}
if (r) { if (r) {
let result = { let result = {
captureIndices: r.captureIndices, captureIndices: r.captureIndices,
...@@ -1147,8 +1152,9 @@ function _tokenizeString(grammar, lineText, isFirstLine, linePos, stack, lineTok ...@@ -1147,8 +1152,9 @@ function _tokenizeString(grammar, lineText, isFirstLine, linePos, stack, lineTok
} }
} }
if (captureIndices[0].end > linePos) { if (captureIndices[0].end > linePos) {
// Advance stream
linePos = captureIndices[0].end; linePos = captureIndices[0].end;
// Advance stream
console.log(linePos);
isFirstLine = false; isFirstLine = false;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册