feat: use scanner in realy codE

上级 6edd82ae
......@@ -5,6 +5,7 @@ use crate::grammar::{ScopeListElement, StackElement};
use crate::inter::{IRawGrammar, IRawRepository, IRawRepositoryMap, IRawRule};
use crate::rule::rule_factory::RuleFactory;
use crate::rule::{AbstractRule, EmptyRule, IGrammarRegistry, IRuleFactoryHelper, IRuleRegistry};
use scie_scanner::scanner::scanner::IOnigMatch;
pub struct IToken {
pub start_index: i32,
......@@ -214,14 +215,22 @@ impl Grammar {
line_pos: i32,
stack: StackElement,
anchor_position: i32,
) {
) -> Option<IOnigMatch> {
let mut rule = stack.get_rule(self);
let rule_scanner = rule.compile(
let mut rule_scanner = rule.compile(
self,
stack.end_rule,
is_first_line,
line_pos == anchor_position,
);
// rule_scanner.scanner
let r = rule_scanner.scanner.find_next_match_sync(line_text, line_pos);
if let Some(result) = r {
println!("{:?}", result);
Some(result)
} else {
None
}
}
pub fn tokenize_line(&mut self, line_text: String, prev_state: Option<StackElement>) {
......
use scie_scanner::scanner::scanner::Scanner;
#[derive(Clone, Debug, Serialize)]
pub struct CompiledRule {
pub debug_reg_exps: Vec<String>,
pub rules: Vec<i32>,
pub scanner: Box<Scanner>
}
impl CompiledRule {
pub fn new(debug_reg_exps: Vec<String>, rules: Vec<i32>) -> Self {
let mut scanner = Scanner::new(debug_reg_exps.clone());
CompiledRule {
debug_reg_exps,
rules,
scanner: Box::new(scanner)
}
}
}
......@@ -14,7 +14,7 @@ pub struct IOnigMatch {
pub capture_indices: Vec<IOnigCaptureIndex>,
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct Scanner {
pub index: usize,
pub patterns: Vec<String>,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册