Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
scie
提交
03faafa2
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 搜索 >>
未验证
提交
03faafa2
编写于
8月 31, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add shift logic
上级
647e241e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
4 deletion
+20
-4
scie-grammar/src/rule/abstract_rule.rs
scie-grammar/src/rule/abstract_rule.rs
+1
-1
scie-grammar/src/rule/begin_end_rule.rs
scie-grammar/src/rule/begin_end_rule.rs
+11
-1
scie-grammar/src/rule/mod.rs
scie-grammar/src/rule/mod.rs
+8
-2
未找到文件。
scie-grammar/src/rule/abstract_rule.rs
浏览文件 @
03faafa2
use
crate
::
grammar
::
Grammar
;
use
crate
::
grammar
::
Grammar
;
use
crate
::
rule
::{
IRuleRegistry
,
RegExpSourceList
,
CompiledRule
};
use
crate
::
rule
::{
RegExpSourceList
,
CompiledRule
};
use
core
::
fmt
;
use
core
::
fmt
;
use
dyn_clone
::{
clone_trait_object
,
DynClone
};
use
dyn_clone
::{
clone_trait_object
,
DynClone
};
...
...
scie-grammar/src/rule/begin_end_rule.rs
浏览文件 @
03faafa2
...
@@ -81,11 +81,21 @@ impl AbstractRule for BeginEndRule {
...
@@ -81,11 +81,21 @@ impl AbstractRule for BeginEndRule {
// todo: figured cached issues
// todo: figured cached issues
let
mut
cached_compiled_patterns
=
RegExpSourceList
::
new
();
let
mut
cached_compiled_patterns
=
RegExpSourceList
::
new
();
self
.collect_patterns_recursive
(
grammar
,
&
mut
cached_compiled_patterns
,
true
);
self
.collect_patterns_recursive
(
grammar
,
&
mut
cached_compiled_patterns
,
true
);
if
let
Some
(
apply_end
)
=
self
.apply_end_pattern_last
{
if
apply_end
{
cached_compiled_patterns
.push
(
self
._end
.clone
());
}
else
{
cached_compiled_patterns
.unshift
(
self
._end
.clone
());
}
}
else
{
cached_compiled_patterns
.unshift
(
self
._end
.clone
());
}
self
._cached_compiled_patterns
=
Some
(
cached_compiled_patterns
);
self
._cached_compiled_patterns
=
Some
(
cached_compiled_patterns
);
}
}
// todo: support for hasBackReferences
// todo: support for hasBackReferences
self
._cached_compiled_patterns
.as_ref
()
.unwrap
()
.compile
(
grammar
,
allow_a
,
allow_g
)
self
._cached_compiled_patterns
.as_ref
()
.unwrap
()
.compile
(
grammar
,
allow_a
,
allow_g
)
}
}
}
}
scie-grammar/src/rule/mod.rs
浏览文件 @
03faafa2
...
@@ -28,8 +28,6 @@ use serde::Serialize;
...
@@ -28,8 +28,6 @@ use serde::Serialize;
// todo: trait with types
// todo: trait with types
// https://users.rust-lang.org/t/impl-trait-with-generic-function-for-generic-struct/27083/2
// https://users.rust-lang.org/t/impl-trait-with-generic-function-for-generic-struct/27083/2
pub
trait
IRuleRegistry
{
pub
trait
IRuleRegistry
{
// type Output;
// fn method(&self) -> Self::Output;
fn
register_id
(
&
mut
self
)
->
i32
;
fn
register_id
(
&
mut
self
)
->
i32
;
fn
get_rule
(
&
mut
self
,
pattern_id
:
i32
)
->
Box
<
dyn
AbstractRule
>
;
fn
get_rule
(
&
mut
self
,
pattern_id
:
i32
)
->
Box
<
dyn
AbstractRule
>
;
fn
register_rule
(
&
mut
self
,
result
:
Box
<
dyn
AbstractRule
>
)
->
Box
<
dyn
AbstractRule
>
;
fn
register_rule
(
&
mut
self
,
result
:
Box
<
dyn
AbstractRule
>
)
->
Box
<
dyn
AbstractRule
>
;
...
@@ -89,6 +87,14 @@ impl RegExpSourceList {
...
@@ -89,6 +87,14 @@ impl RegExpSourceList {
}
}
}
}
pub
fn
unshift
(
&
mut
self
,
item
:
RegExpSource
)
{
self
._items
.push
(
item
.clone
());
self
._items
.rotate_right
(
1
);
if
item
.has_anchor
{
self
._has_anchors
=
true
;
}
}
pub
fn
compile
(
&
self
,
grammar
:
&
mut
Grammar
,
allow_a
:
bool
,
allow_g
:
bool
)
->
CompiledRule
{
pub
fn
compile
(
&
self
,
grammar
:
&
mut
Grammar
,
allow_a
:
bool
,
allow_g
:
bool
)
->
CompiledRule
{
let
rules
=
self
._items
.clone
()
.into_iter
()
.map
(|
x
|
{
let
rules
=
self
._items
.clone
()
.into_iter
()
.map
(|
x
|
{
x
.source
.parse
()
.unwrap_or
(
0
)
x
.source
.parse
()
.unwrap_or
(
0
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录