Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
scie
提交
4e4e2672
S
scie
项目概览
Phodal
/
scie
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
scie
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
4e4e2672
编写于
9月 06, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix lints
上级
d6d879b9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
40 addition
and
36 deletion
+40
-36
scie-grammar/src/grammar/grammar.rs
scie-grammar/src/grammar/grammar.rs
+22
-18
scie-grammar/src/grammar/scope_list_element.rs
scie-grammar/src/grammar/scope_list_element.rs
+2
-2
scie-grammar/src/grammar/stack_element.rs
scie-grammar/src/grammar/stack_element.rs
+4
-7
scie-grammar/src/rule/begin_while_rule.rs
scie-grammar/src/rule/begin_while_rule.rs
+6
-3
scie-scanner/src/scanner/scanner.rs
scie-scanner/src/scanner/scanner.rs
+6
-6
未找到文件。
scie-grammar/src/grammar/grammar.rs
浏览文件 @
4e4e2672
...
...
@@ -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
);
}
...
...
scie-grammar/src/grammar/scope_list_element.rs
浏览文件 @
4e4e2672
...
...
@@ -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
()
,
}
}
}
scie-grammar/src/grammar/stack_element.rs
浏览文件 @
4e4e2672
...
...
@@ -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
;
}
}
scie-grammar/src/rule/begin_while_rule.rs
浏览文件 @
4e4e2672
...
...
@@ -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
{
...
...
scie-scanner/src/scanner/scanner.rs
浏览文件 @
4e4e2672
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录