feat: add basic scope list element push

上级 80ebad51
......@@ -168,8 +168,8 @@ impl Grammar {
line_text: String,
origin_is_first: bool,
origin_line_pos: i32,
prev_state: &mut StackElement,
line_tokens: LineTokens,
stack: &mut StackElement,
mut line_tokens: LineTokens,
check_while_conditions: bool,
) -> Option<StackElement> {
let _line_length = line_text.len();
......@@ -183,7 +183,7 @@ impl Grammar {
line_text.clone(),
origin_is_first.clone(),
origin_line_pos.clone(),
prev_state.clone(),
stack.clone(),
line_tokens.clone(),
);
}
......@@ -192,7 +192,7 @@ impl Grammar {
let mut line_pos = origin_line_pos.clone();
let mut is_first_line = origin_is_first.clone();
while !_stop {
let r = self.match_rule(line_text.clone(), is_first_line, line_pos, prev_state, anchor_position);
let r = self.match_rule(line_text.clone(), is_first_line, line_pos, stack, anchor_position);
if let None = r {
_stop = true;
return None;
......@@ -205,7 +205,11 @@ impl Grammar {
println!("todo: matched the `end` for this rule => pop it");
} else {
let rule = self.get_rule(matched_rule_id);
line_tokens.produce(prev_state, capture_indices[0].start as i32)
line_tokens.produce(stack, capture_indices[0].start as i32);
let before_push = stack.clone();
let scope_name = rule.get_name(Some(line_text.clone()), Some(capture_indices.clone()));
// println!("{:?}", scope_name);
stack.content_name_scopes_list.push(self, scope_name);
}
if capture_indices[0].end > line_pos as usize {
......@@ -213,7 +217,7 @@ impl Grammar {
is_first_line = false;
}
}
Some(prev_state.clone())
Some(stack.clone())
}
pub fn check_while_conditions(
......@@ -267,7 +271,6 @@ impl Grammar {
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 {
let match_rule_result = MatchRuleResult {
......
use crate::grammar::{StackElement, ScopeListElement};
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct TokenTypeMatcher {}
......@@ -36,11 +37,11 @@ impl LineTokens {
}
}
pub fn produce(&self, stack: &mut StackElement, end_index: i32) {
self.produce_from_scopes(stack.content_name_scopes_list.clone(), end_index)
pub fn produce(&mut self, stack: &mut StackElement, end_index: i32) {
self.produce_from_scopes(&mut stack.content_name_scopes_list, end_index)
}
pub fn produce_from_scopes(&self, scopes_list: ScopeListElement, end_index: i32) {
pub fn produce_from_scopes(&mut self, scopes_list: &mut ScopeListElement, end_index: i32) {
if self._last_token_end_index > end_index {
return;
}
......@@ -49,6 +50,12 @@ impl LineTokens {
// let meta_data = scopes_list.metadata;
// }
let x = scopes_list.generate_scopes();
let scopes = scopes_list.generate_scopes();
self._tokens.push(IToken {
start_index: 0,
end_index,
scopes
});
self._last_token_end_index = end_index
}
}
use std::collections::HashMap;
use std::collections::hash_map::RandomState;
use crate::grammar::Grammar;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ScopeListElement {
......@@ -17,14 +18,13 @@ impl ScopeListElement {
}
}
pub fn generate_scopes(&self) -> HashMap<i32, String> {
let mut result = HashMap::new();
let mut result_len = 0;
pub fn generate_scopes(&self) -> Vec<String> {
let mut result = vec![];
let mut scope_list = self.clone();
let mut is_scope_list_none = false;
while !is_scope_list_none {
result.insert(result_len, scope_list.scope.clone());
result.push(scope_list.scope.clone());
match scope_list.parent {
None => {
is_scope_list_none = true
......@@ -35,8 +35,34 @@ impl ScopeListElement {
}
}
result.reverse();
return result.clone();
}
pub fn _push(origin_target: ScopeListElement, grammar: &mut Grammar, scopes: Vec<String>) -> ScopeListElement {
let mut target = origin_target.clone();
for scope in scopes {
target = ScopeListElement::new(Some(Box::new(target)), scope);
}
target
}
pub fn push(&self, grammar: &mut Grammar, scope: Option<String>) -> ScopeListElement {
if let None = scope {
return self.clone()
}
let scope_name = scope.clone().unwrap();
return match scope.iter().position(|s| s == " ") {
None => {
ScopeListElement::_push(self.clone(), grammar, vec![scope_name])
},
Some(_) => {
println!("todo: ScopeListElement push");
self.clone()
},
}
}
}
impl Default for ScopeListElement {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册