Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
scie
提交
749094a3
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 搜索 >>
未验证
提交
749094a3
编写于
8月 30, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add collect pattern for match
上级
c001f911
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
25 addition
and
11 deletion
+25
-11
scie-grammar/src/rule/abstract_rule.rs
scie-grammar/src/rule/abstract_rule.rs
+1
-1
scie-grammar/src/rule/include_only_rule.rs
scie-grammar/src/rule/include_only_rule.rs
+5
-4
scie-grammar/src/rule/match_rule.rs
scie-grammar/src/rule/match_rule.rs
+5
-1
scie-grammar/src/rule/mod.rs
scie-grammar/src/rule/mod.rs
+14
-5
未找到文件。
scie-grammar/src/rule/abstract_rule.rs
浏览文件 @
749094a3
...
@@ -9,7 +9,7 @@ pub trait AbstractRule: DynClone + erased_serde::Serialize {
...
@@ -9,7 +9,7 @@ pub trait AbstractRule: DynClone + erased_serde::Serialize {
fn
has_missing_pattern
(
&
self
)
->
bool
{
fn
has_missing_pattern
(
&
self
)
->
bool
{
false
false
}
}
fn
collect_patterns_recursive
(
&
mut
self
,
grammar
:
&
mut
Grammar
,
out
:
Option
<
RegExpSourceList
>
,
is_first
:
bool
)
{
fn
collect_patterns_recursive
(
&
mut
self
,
grammar
:
&
mut
Grammar
,
out
:
&
mut
RegExpSourceList
,
is_first
:
bool
)
{
}
}
fn
compile
(
fn
compile
(
&
mut
self
,
&
mut
self
,
...
...
scie-grammar/src/rule/include_only_rule.rs
浏览文件 @
749094a3
...
@@ -46,18 +46,19 @@ impl AbstractRule for IncludeOnlyRule {
...
@@ -46,18 +46,19 @@ impl AbstractRule for IncludeOnlyRule {
self
.has_missing_patterns
self
.has_missing_patterns
}
}
fn
collect_patterns_recursive
(
&
mut
self
,
grammar
:
&
mut
Grammar
,
out
:
Option
<
RegExpSourceList
>
,
is_first
:
bool
)
{
fn
collect_patterns_recursive
(
&
mut
self
,
grammar
:
&
mut
Grammar
,
out
:
&
mut
RegExpSourceList
,
is_first
:
bool
)
{
for
x
in
self
.patterns
.clone
()
{
for
x
in
self
.patterns
.clone
()
{
let
mut
rule
=
grammar
.get_rule
(
x
);
let
mut
rule
=
grammar
.get_rule
(
x
);
rule
.collect_patterns_recursive
(
grammar
,
out
.clone
()
,
is_first
);
rule
.collect_patterns_recursive
(
grammar
,
out
,
is_first
);
}
}
}
}
fn
compile
(
&
mut
self
,
grammar
:
&
mut
Grammar
,
end_regex_source
:
Option
<
String
>
,
allow_a
:
bool
,
allow_g
:
bool
)
{
fn
compile
(
&
mut
self
,
grammar
:
&
mut
Grammar
,
end_regex_source
:
Option
<
String
>
,
allow_a
:
bool
,
allow_g
:
bool
)
{
if
let
None
=
self
._cached_compiled_patterns
{
if
let
None
=
self
._cached_compiled_patterns
{
self
._cached_compiled_patterns
=
Some
(
RegExpSourceList
::
new
());
let
mut
cached_compiled_patterns
=
RegExpSourceList
::
new
();
self
.collect_patterns_recursive
(
grammar
,
self
._cached_compiled_patterns
.clone
(),
true
);
self
.collect_patterns_recursive
(
grammar
,
&
mut
cached_compiled_patterns
,
true
);
self
._cached_compiled_patterns
=
Some
(
cached_compiled_patterns
);
}
}
return
self
._cached_compiled_patterns
.as_ref
()
.unwrap
()
.compile
(
grammar
,
allow_a
,
allow_g
);
return
self
._cached_compiled_patterns
.as_ref
()
.unwrap
()
.compile
(
grammar
,
allow_a
,
allow_g
);
...
...
scie-grammar/src/rule/match_rule.rs
浏览文件 @
749094a3
use
crate
::
inter
::
ILocation
;
use
crate
::
inter
::
ILocation
;
use
crate
::
rule
::
RegExpSource
;
use
crate
::
rule
::
{
RegExpSource
,
RegExpSourceList
}
;
use
crate
::
rule
::{
AbstractRule
,
Rule
};
use
crate
::
rule
::{
AbstractRule
,
Rule
};
use
crate
::
grammar
::
Grammar
;
#[derive(Clone,
Debug,
Serialize)]
#[derive(Clone,
Debug,
Serialize)]
pub
struct
MatchRule
{
pub
struct
MatchRule
{
...
@@ -38,4 +39,7 @@ impl AbstractRule for MatchRule {
...
@@ -38,4 +39,7 @@ impl AbstractRule for MatchRule {
fn
type_of
(
&
self
)
->
String
{
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
String
::
from
(
self
.rule
.clone
()
._type
)
}
}
fn
collect_patterns_recursive
(
&
mut
self
,
grammar
:
&
mut
Grammar
,
out
:
&
mut
RegExpSourceList
,
is_first
:
bool
)
{
out
.push
(
self
._match
.clone
());
}
}
}
scie-grammar/src/rule/mod.rs
浏览文件 @
749094a3
...
@@ -59,7 +59,7 @@ impl Default for AnchorCache {
...
@@ -59,7 +59,7 @@ impl Default for AnchorCache {
A0_G0
:
None
,
A0_G0
:
None
,
A0_G1
:
None
,
A0_G1
:
None
,
A1_G0
:
None
,
A1_G0
:
None
,
A1_G1
:
None
A1_G1
:
None
,
}
}
}
}
}
}
...
@@ -68,7 +68,8 @@ impl Default for AnchorCache {
...
@@ -68,7 +68,8 @@ impl Default for AnchorCache {
pub
struct
RegExpSourceList
{
pub
struct
RegExpSourceList
{
pub
_
has_anchors
:
bool
,
pub
_
has_anchors
:
bool
,
pub
_
cached
:
Option
<
CompiledRule
>
,
pub
_
cached
:
Option
<
CompiledRule
>
,
pub
_
anchor_cache
:
AnchorCache
pub
_
anchor_cache
:
AnchorCache
,
pub
_
items
:
Vec
<
RegExpSource
>
}
}
impl
RegExpSourceList
{
impl
RegExpSourceList
{
...
@@ -76,19 +77,26 @@ impl RegExpSourceList {
...
@@ -76,19 +77,26 @@ impl RegExpSourceList {
RegExpSourceList
{
RegExpSourceList
{
_
has_anchors
:
false
,
_
has_anchors
:
false
,
_
cached
:
None
,
_
cached
:
None
,
_
anchor_cache
:
Default
::
default
()
_
anchor_cache
:
Default
::
default
(),
_
items
:
vec!
[]
}
}
}
}
pub
fn
compile
(
&
self
,
grammar
:
&
mut
Grammar
,
allow_a
:
bool
,
allow_g
:
bool
)
{
pub
fn
push
(
&
mut
self
,
item
:
RegExpSource
)
{
self
._items
.push
(
item
.clone
());
if
item
.has_anchor
{
self
._has_anchors
=
true
;
}
}
}
pub
fn
compile
(
&
self
,
grammar
:
&
mut
Grammar
,
allow_a
:
bool
,
allow_g
:
bool
)
{}
}
}
#[derive(Clone,
Debug,
Serialize)]
#[derive(Clone,
Debug,
Serialize)]
pub
struct
RegExpSource
{
pub
struct
RegExpSource
{
pub
source
:
String
,
pub
source
:
String
,
pub
rule_id
:
i32
,
pub
rule_id
:
i32
,
pub
has_anchor
:
bool
}
}
impl
RegExpSource
{
impl
RegExpSource
{
...
@@ -96,6 +104,7 @@ impl RegExpSource {
...
@@ -96,6 +104,7 @@ impl RegExpSource {
RegExpSource
{
RegExpSource
{
source
:
reg_exp_source
,
source
:
reg_exp_source
,
rule_id
,
rule_id
,
has_anchor
:
false
}
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录