feat: add get name support

上级 a614fb51
......@@ -119,10 +119,18 @@ impl Grammar {
}
if is_first_line {
let scope_list = ScopeListElement::default();
// self.get_rule(self.root_id.clone());
// let scope_list = ScopeListElement::new(
// None, );
// let scope_list = ScopeListElement::default();
let _root_scope_name = self.get_rule(self.root_id.clone())
.get_name(None, None);
let mut root_scope_name = String::from("unknown");
if let Some(name) = _root_scope_name {
root_scope_name = name
}
let scope_list = ScopeListElement::new(
None,
root_scope_name
);
let mut state = StackElement::new(
None,
self.root_id.clone(),
......@@ -135,6 +143,8 @@ impl Grammar {
);
current_state = state;
} else {
is_first_line = false;
}
let format_line_text = format!("{:?}\n", line_text);
......@@ -185,7 +195,7 @@ impl Grammar {
let r = self.match_rule(line_text.clone(), is_first_line, line_pos, prev_state, anchor_position);
if let None = r {
_stop = true;
return None
return None;
}
let capture_result = r.unwrap();
......
......@@ -5,26 +5,26 @@ use std::collections::hash_map::RandomState;
pub struct ScopeListElement {
pub parent: Option<Box<ScopeListElement>>,
pub scope: String,
pub metadata: i32,
// pub metadata: i32,
}
impl ScopeListElement {
pub fn new(parent: Option<Box<ScopeListElement>>, scope: String, metadata: i32) -> Self {
pub fn new(parent: Option<Box<ScopeListElement>>, scope: String) -> Self {
ScopeListElement {
parent,
scope,
metadata,
// metadata,
}
}
pub fn generate_scopes(&self) -> HashMap<i32, String> {
let mut result = HashMap::new();
let mut resultLen = 0;
let mut result_len = 0;
let mut scope_list = self.clone();
let mut is_scope_list_none = false;
while !is_scope_list_none {
result.insert(resultLen, scope_list.scope.clone());
result.insert(result_len, scope_list.scope.clone());
match scope_list.parent {
None => {
is_scope_list_none = true
......@@ -44,7 +44,7 @@ impl Default for ScopeListElement {
ScopeListElement {
parent: None,
scope: "".to_string(),
metadata: 0,
// metadata: 0,
}
}
}
......@@ -3,6 +3,7 @@ use crate::rule::{CompiledRule, RegExpSourceList, Rule};
use core::fmt;
use dyn_clone::{clone_trait_object, DynClone};
use scie_scanner::scanner::scanner::IOnigCaptureIndex;
use crate::support::regex_source::RegexSource;
pub trait AbstractRule: DynClone + erased_serde::Serialize {
fn id(&self) -> i32;
......@@ -12,8 +13,17 @@ pub trait AbstractRule: DynClone + erased_serde::Serialize {
}
// todo: add support for this;
fn get_rule(&self) -> Rule;
fn get_name(&self, line_text: Option<String>, capture_indices: Option<Vec<IOnigCaptureIndex>>) -> String {
String::from("")
fn get_name(&self, line_text: Option<String>, capture_indices: Option<Vec<IOnigCaptureIndex>>) -> Option<String> {
let name = self.get_rule()._name.clone();
let has_captures = RegexSource::has_captures(name.clone());
if let None = capture_indices {
return name
}
if !has_captures || name == None || line_text == None {
return name
}
return Some(String::from(""));
}
fn has_missing_pattern(&self) -> bool {
false
......
use regex::Regex;
use scie_scanner::scanner::scanner::IOnigCaptureIndex;
pub struct RegexSource {}
......@@ -10,13 +11,17 @@ impl RegexSource {
match regex_source {
None => {
false
},
}
Some(source) => {
let re = Regex::new(capturing_regex_source).unwrap();
re.is_match(source.as_str())
},
}
}
}
pub fn replace_captures(regex_source: String, capture_source: String, capture_indices: Vec<IOnigCaptureIndex>) -> String {
String::from("")
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册