fix: fix lints

上级 d6d879b9
......@@ -6,7 +6,9 @@ use crate::grammar::{MatchRuleResult, ScopeListElement, StackElement};
use crate::inter::{IRawGrammar, IRawRepository, IRawRepositoryMap, IRawRule};
use crate::rule::abstract_rule::RuleEnum;
use crate::rule::rule_factory::RuleFactory;
use crate::rule::{AbstractRule, EmptyRule, IGrammarRegistry, IRuleFactoryHelper, IRuleRegistry, BeginWhileRule};
use crate::rule::{
AbstractRule, BeginWhileRule, EmptyRule, IGrammarRegistry, IRuleFactoryHelper, IRuleRegistry,
};
use core::cmp;
use scie_scanner::scanner::scanner::{IOnigCaptureIndex, IOnigMatch};
use std::borrow::Borrow;
......@@ -247,9 +249,7 @@ impl Grammar {
// let before_push = stack.clone();
let scope_name =
rule.get_name(Some(line_text.clone()), Some(capture_indices.clone()));
let name_scopes_list = stack
.content_name_scopes_list
.push(self, scope_name);
let name_scopes_list = stack.content_name_scopes_list.push(self, scope_name);
let mut begin_rule_capture_eol = false;
if capture_indices[0].end == _line_length {
begin_rule_capture_eol = true;
......@@ -370,14 +370,11 @@ impl Grammar {
}
if capture.retokenize_captured_with_rule_id != 0 {
let scope_name = capture
.get_name(Some(line_text.clone()), Some(capture_indices.clone()));
let name_scopes_list =
stack.content_name_scopes_list.push(grammar, scope_name);
let content_name = capture.get_content_name(
Some(line_text.clone()),
Some(capture_indices.clone()),
);
let scope_name =
capture.get_name(Some(line_text.clone()), Some(capture_indices.clone()));
let name_scopes_list = stack.content_name_scopes_list.push(grammar, scope_name);
let content_name = capture
.get_content_name(Some(line_text.clone()), Some(capture_indices.clone()));
let content_name_scopes_list = name_scopes_list.push(grammar, content_name);
let mut stack_clone = stack.clone().push(
......@@ -462,7 +459,7 @@ impl Grammar {
}
match node.pop() {
None => { has_node = false }
None => has_node = false,
Some(n) => {
node = n;
}
......@@ -477,7 +474,9 @@ impl Grammar {
is_first_line,
allow_g,
);
let match_result = rule_scanner.scanner.find_next_match_sync(line_text.clone(), line_pos);
let match_result = rule_scanner
.scanner
.find_next_match_sync(line_text.clone(), line_pos);
match match_result {
None => {
stack = while_rule.stack.pop().unwrap();
......@@ -508,7 +507,8 @@ impl Grammar {
) {
let match_result =
self.match_rule(line_text, is_first_line, line_pos, stack, anchor_position);
if let Some(result) = match_result {} else {
if let Some(result) = match_result {
} else {
// None
};
// todo: get injections logic
......@@ -545,7 +545,11 @@ impl Grammar {
}
}
pub fn tokenize_line(&mut self, line_text: String, prev_state: Option<StackElement>) -> TokenizeResult {
pub fn tokenize_line(
&mut self,
line_text: String,
prev_state: Option<StackElement>,
) -> TokenizeResult {
self.tokenize(line_text, prev_state, false)
}
......@@ -592,8 +596,8 @@ mod tests {
use crate::grammar::Grammar;
use crate::inter::IRawGrammar;
use crate::rule::IRuleRegistry;
use crate::rule::abstract_rule::RuleEnum;
use crate::rule::IRuleRegistry;
#[test]
fn should_build_json_code() {
......@@ -654,7 +658,7 @@ OBJ = hellomake.o hellofunc.o
match grammar.rule_id2desc.get(&30).unwrap().get_rule_instance() {
RuleEnum::BeginEndRule(rule) => {
assert_eq!(rule._end.rule_id, -1);
},
}
_ => {
assert!(false);
}
......
......@@ -14,7 +14,7 @@ impl ScopeListElement {
let mut list_element = ScopeListElement {
parent,
scope,
stringify: String::from("")
stringify: String::from(""),
};
list_element.stringify = list_element.clone().stringify();
list_element
......@@ -75,7 +75,7 @@ impl Default for ScopeListElement {
ScopeListElement {
parent: None,
scope: "".to_string(),
stringify: "".to_string()
stringify: "".to_string(),
}
}
}
......@@ -30,16 +30,14 @@ impl StackElement {
end_rule: None,
name_scopes_list: Default::default(),
content_name_scopes_list: Default::default(),
stringify: "".to_string()
stringify: "".to_string(),
}
}
pub fn pop(&self) -> Option<StackElement> {
match self.parent.clone() {
None => { None },
Some(parents) => {
Some(parents[0].clone())
},
None => None,
Some(parents) => Some(parents[0].clone()),
}
}
pub fn get_rule(&self, grammar: &mut Grammar) -> Box<dyn AbstractRule> {
......@@ -69,7 +67,7 @@ impl StackElement {
end_rule,
name_scopes_list,
content_name_scopes_list,
stringify: "".to_string()
stringify: "".to_string(),
};
element.stringify = element.clone().stringify();
......@@ -113,5 +111,4 @@ impl StackElement {
println!("todo: set_content_name_scopes_list");
return self;
}
}
......@@ -63,7 +63,7 @@ impl BeginWhileRule {
grammar: &mut Grammar,
end_regex_source: Option<String>,
allow_a: bool,
allow_g: bool
allow_g: bool,
) -> CompiledRule {
// todo: add hasBackReferences
if let None = self._cached_compiled_patterns {
......@@ -72,9 +72,12 @@ impl BeginWhileRule {
self._cached_compiled_patterns = Option::from(compiled_patterns);
}
return self._cached_compiled_patterns.clone().unwrap().compile(grammar, allow_a, allow_g)
return self
._cached_compiled_patterns
.clone()
.unwrap()
.compile(grammar, allow_a, allow_g);
}
}
impl AbstractRule for BeginWhileRule {
......
use onig::{Regex, Error};
use onig::{Error, Regex};
use unicode_segmentation::UnicodeSegmentation;
#[derive(Debug, Clone, Serialize)]
......@@ -104,16 +104,16 @@ impl Scanner {
}
pub fn str_vec_to_string<I, T>(iter: I) -> Vec<String>
where
I: IntoIterator<Item = T>,
T: Into<String>,
where
I: IntoIterator<Item = T>,
T: Into<String>,
{
iter.into_iter().map(Into::into).collect()
}
#[cfg(test)]
mod tests {
use crate::scanner::scanner::{Scanner, str_vec_to_string};
use crate::scanner::scanner::{str_vec_to_string, Scanner};
#[test]
fn should_handle_simple_regex() {
......@@ -311,7 +311,7 @@ mod tests {
"^[ ]*(override|private)\\b",
"^[ ]*(unexport|undefine)\\b",
"^(ifdef|ifndef)\\s*([^\\s]+)(?=\\s)",
"^(ifeq|ifneq)(?=\\s)]"
"^(ifeq|ifneq)(?=\\s)]",
];
let rules = vec![2, 7, 28, 45, 48, 51, 61, 64, 66, 69, 77];
let debug_regex = str_vec_to_string(origin);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册