Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
scie
提交
55689c9b
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 搜索 >>
未验证
提交
55689c9b
编写于
8月 29, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: split abstract rule
上级
671e0e2b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
51 addition
and
34 deletion
+51
-34
scie-grammar/src/grammar/grammar/mod.rs
scie-grammar/src/grammar/grammar/mod.rs
+2
-1
scie-grammar/src/grammar/grammar/stack_element.rs
scie-grammar/src/grammar/grammar/stack_element.rs
+2
-1
scie-grammar/src/rule/abstract_rule.rs
scie-grammar/src/rule/abstract_rule.rs
+21
-0
scie-grammar/src/rule/compiled_rule.rs
scie-grammar/src/rule/compiled_rule.rs
+10
-0
scie-grammar/src/rule/mod.rs
scie-grammar/src/rule/mod.rs
+16
-32
未找到文件。
scie-grammar/src/grammar/grammar/mod.rs
浏览文件 @
55689c9b
...
...
@@ -5,11 +5,12 @@ use onig::*;
use
crate
::
grammar
::
grammar
::
stack_element
::
StackElement
;
use
crate
::
inter
::{
IRawGrammar
,
IRawRepository
,
IRawRepositoryMap
,
IRawRule
};
use
crate
::
rule
::{
AbstractRule
,
IGrammarRegistry
,
IRuleFactoryHelper
,
IRuleRegistry
,
NoneRule
,
IGrammarRegistry
,
IRuleFactoryHelper
,
IRuleRegistry
,
NoneRule
,
};
use
crate
::
rule
::
rule_factory
::
RuleFactory
;
use
crate
::
grammar
::
line_tokens
::{
LineTokens
,
TokenTypeMatcher
};
use
crate
::
grammar
::
grammar
::
scope_list_element
::
ScopeListElement
;
use
crate
::
rule
::
abstract_rule
::
AbstractRule
;
pub
mod
scope_list_element
;
pub
mod
scope_metadata
;
...
...
scie-grammar/src/grammar/grammar/stack_element.rs
浏览文件 @
55689c9b
...
...
@@ -2,7 +2,8 @@ use crate::grammar::grammar::scope_list_element::ScopeListElement;
use
core
::
ptr
;
use
crate
::
grammar
::
grammar
::
Grammar
;
use
crate
::
grammar
::
grammar_registry
::
GrammarRegistry
;
use
crate
::
rule
::{
IRuleRegistry
,
AbstractRule
};
use
crate
::
rule
::{
IRuleRegistry
};
use
crate
::
rule
::
abstract_rule
::
AbstractRule
;
#[derive(Debug,
Clone,
PartialEq,
Eq)]
pub
struct
StackElement
{
...
...
scie-grammar/src/rule/abstract_rule.rs
0 → 100644
浏览文件 @
55689c9b
use
dyn_clone
::{
clone_trait_object
,
DynClone
};
use
core
::
fmt
;
pub
trait
AbstractRule
:
DynClone
+
erased_serde
::
Serialize
{
fn
id
(
&
self
)
->
i32
;
fn
type_of
(
&
self
)
->
String
;
fn
has_missing_pattern
(
&
self
)
->
bool
{
false
}
}
impl
fmt
::
Debug
for
dyn
AbstractRule
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
write!
(
f
,
"AbstractRule"
)
}
}
serialize_trait_object!
(
AbstractRule
);
clone_trait_object!
(
AbstractRule
);
scie-grammar/src/rule/compiled_rule.rs
0 → 100644
浏览文件 @
55689c9b
pub
struct
CompiledRule
{
pub
debug_reg_exps
:
Vec
<
String
>
,
pub
rules
:
Vec
<
i32
>
}
impl
CompiledRule
{
pub
fn
new
(
debug_reg_exps
:
Vec
<
String
>
,
rules
:
Vec
<
i32
>
)
->
Self
{
CompiledRule
{
debug_reg_exps
,
rules
}
}
}
\ No newline at end of file
scie-grammar/src/rule/mod.rs
浏览文件 @
55689c9b
pub
mod
rule_factory
;
pub
mod
rule_convert
;
pub
mod
reg_exp_source
;
pub
mod
compiled_rule
;
pub
(
crate
)
mod
abstract_rule
;
use
crate
::
inter
::{
ILocation
,
IRawGrammar
,
IRawRepository
};
use
reg_exp_source
::{
RegExpSource
,
RegExpSourceList
};
use
crate
::
rule
::
rule_factory
::
ICompilePatternsResult
;
use
core
::
fmt
;
use
dyn_clone
::{
clone_trait_object
,
DynClone
};
use
serde
::{
Serialize
,
Serializer
};
use
abstract_rule
::
AbstractRule
;
#[derive(Clone,
Debug,
Serialize)]
pub
struct
Rule
{
pub
_
type
:
String
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
_
location
:
Option
<
ILocation
>
,
pub
id
:
i32
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
_
name
:
Option
<
String
>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
_
content_name
:
Option
<
String
>
,
}
...
...
@@ -38,30 +40,12 @@ impl Rule {
}
}
pub
trait
AbstractRule
:
DynClone
+
erased_serde
::
Serialize
{
fn
id
(
&
self
)
->
i32
;
fn
type_of
(
&
self
)
->
String
;
fn
has_missing_pattern
(
&
self
)
->
bool
{
false
}
}
serialize_trait_object!
(
AbstractRule
);
impl
fmt
::
Debug
for
dyn
AbstractRule
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
write!
(
f
,
"AbstractRule"
)
}
}
clone_trait_object!
(
AbstractRule
);
#[derive(Clone,
Debug,
Serialize)]
pub
struct
IncludeOnlyRule
{
#[serde(flatten)]
pub
rule
:
Rule
,
pub
patterns
:
Vec
<
i32
>
,
pub
has_missing_patterns
:
bool
pub
has_missing_patterns
:
bool
,
}
impl
IncludeOnlyRule
{
...
...
@@ -81,7 +65,7 @@ impl IncludeOnlyRule {
_
content_name
:
content_name
,
},
patterns
:
captures
.patterns
,
has_missing_patterns
:
captures
.has_missing_patterns
has_missing_patterns
:
captures
.has_missing_patterns
,
}
}
}
...
...
@@ -111,7 +95,7 @@ pub struct BeginWhileRule {
pub
patterns
:
ICompilePatternsResult
,
pub
has_missing_patterns
:
bool
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
cached_compiled_patterns
:
Option
<
RegExpSourceList
>
,
}
...
...
@@ -202,9 +186,9 @@ pub struct BeginEndRule {
pub
_
end
:
RegExpSource
,
// pub endHasBackReferences: Option<bool>,
pub
end_captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
apply_end_pattern_last
:
Option
<
bool
>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
_
cached_compiled_patterns
:
Option
<
RegExpSourceList
>
,
pub
patterns
:
Vec
<
i32
>
,
pub
has_missing_patterns
:
bool
,
...
...
@@ -238,7 +222,7 @@ impl BeginEndRule {
apply_end_pattern_last
,
has_missing_patterns
:
patterns
.clone
()
.has_missing_patterns
,
patterns
:
patterns
.patterns
,
_
cached_compiled_patterns
:
None
_
cached_compiled_patterns
:
None
,
}
}
}
...
...
@@ -256,7 +240,7 @@ impl AbstractRule for BeginEndRule {
#[derive(Clone,
Debug,
Serialize)]
pub
struct
CaptureRule
{
pub
rule
:
Rule
,
pub
retokenize_captured_with_rule_id
:
i32
pub
retokenize_captured_with_rule_id
:
i32
,
}
impl
CaptureRule
{
...
...
@@ -267,9 +251,9 @@ impl CaptureRule {
_
location
:
None
,
id
:
0
,
_
name
:
None
,
_
content_name
:
None
_
content_name
:
None
,
},
retokenize_captured_with_rule_id
:
0
retokenize_captured_with_rule_id
:
0
,
}
}
pub
fn
new
(
location
:
Option
<
ILocation
>
,
id
:
i32
,
name
:
Option
<
String
>
,
content_name
:
Option
<
String
>
,
retokenize_captured_with_rule_id
:
i32
)
->
Self
{
...
...
@@ -281,7 +265,7 @@ impl CaptureRule {
_
name
:
name
,
_
content_name
:
content_name
,
},
retokenize_captured_with_rule_id
retokenize_captured_with_rule_id
,
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录