feat: fix stack element issues

上级 ec19ab29
......@@ -9,6 +9,7 @@ use crate::rule::{
};
use crate::rule::rule_factory::RuleFactory;
use crate::grammar::line_tokens::{LineTokens, TokenTypeMatcher};
use crate::grammar::grammar::scope_list_element::ScopeListElement;
pub mod scope_list_element;
pub mod scope_metadata;
......@@ -103,7 +104,7 @@ impl Grammar {
fn tokenize(
&mut self,
line_text: String,
prev_state: Option<StackElement>,
mut prev_state: Option<StackElement>,
emit_binary_tokens: bool,
) {
if self.root_id.clone() == -1 {
......@@ -125,13 +126,18 @@ impl Grammar {
}
}
if is_first_line {
let scope_list = ScopeListElement::default();
prev_state = Some(StackElement::new(None, self.root_id.clone(), -1, -1, false, None, scope_list.clone(), scope_list.clone()))
}
let format_line_text = format!("{:?}\n", line_text);
let line_tokens = LineTokens::new(emit_binary_tokens, line_text, self._token_type_matchers.clone());
self.tokenize_string(
format_line_text.parse().unwrap(),
is_first_line,
0,
prev_state,
prev_state.unwrap(),
line_tokens,
true,
)
......@@ -142,7 +148,7 @@ impl Grammar {
line_text: String,
is_first_line: bool,
line_pos: i32,
prev_state: Option<StackElement>,
prev_state: StackElement,
line_tokens: LineTokens,
check_while_conditions: bool,
) {
......@@ -161,9 +167,8 @@ impl Grammar {
);
}
if let Some(stack) = prev_state {
self.match_rule_or_injections(line_text, is_first_line, line_pos, stack.clone(), anchor_position);
}
self.match_rule_or_injections(line_text, is_first_line, line_pos, prev_state, anchor_position);
}
pub fn check_while_conditions(
......@@ -171,13 +176,11 @@ impl Grammar {
line_text: String,
is_first_line: bool,
line_pos: i32,
_stack: Option<StackElement>,
_stack: StackElement,
line_tokens: LineTokens,
) {
let mut anchor_position = -1;
if let Some(stack) = _stack {
if stack.begin_rule_captured_eol { anchor_position = 0 }
};
if _stack.begin_rule_captured_eol { anchor_position = 0 }
// let while_rules = vec![];
}
......
......@@ -18,8 +18,8 @@ pub struct StackElement {
}
impl StackElement {
pub fn null() -> StackElement {
StackElement {
pub fn null() -> Self {
Self {
parent: None,
depth: 0,
rule_id: 0,
......@@ -32,10 +32,25 @@ impl StackElement {
}
}
pub fn pop(&self) -> Option<Box<StackElement>> {
self.clone().parent
}
pub fn get_rule(&self, grammar: &mut Grammar) -> Box<dyn AbstractRule> {
grammar.get_rule(self.rule_id)
}
pub fn new(parent: Option<Box<StackElement>>, rule_id: i32, enter_pos: i32, anchor_pos: i32, begin_rule_captured_eol: bool, end_rule: Option<String>, name_scopes_list: ScopeListElement, content_name_scopes_list: ScopeListElement) -> Self {
StackElement {
parent,
// todo: this.depth = (this.parent ? this.parent.depth + 1 : 1);
depth: 1,
rule_id,
enter_pos,
anchor_pos,
begin_rule_captured_eol,
end_rule,
name_scopes_list,
content_name_scopes_list
}
}
}
......@@ -23,9 +23,6 @@ mod tests {
#[test]
fn should_run() {
let grammar = parse_raw_grammar(String::from("hello"), Some(String::from("world.json")));
assert_eq!(
format!("{:?}", grammar.unwrap().location),
"ILocatable { textmate_location: None }"
);
assert_eq!(format!("{:?}", grammar.unwrap().location), "None");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册