Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
scie
提交
5310e8e8
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 搜索 >>
未验证
提交
5310e8e8
编写于
8月 29, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: extract more rules
上级
f1980b93
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
195 addition
and
175 deletion
+195
-175
scie-grammar/src/rule/begin_while_rule.rs
scie-grammar/src/rule/begin_while_rule.rs
+64
-0
scie-grammar/src/rule/capture_rule.rs
scie-grammar/src/rule/capture_rule.rs
+40
-0
scie-grammar/src/rule/include_only_rule.rs
scie-grammar/src/rule/include_only_rule.rs
+44
-0
scie-grammar/src/rule/match_rule.rs
scie-grammar/src/rule/match_rule.rs
+39
-0
scie-grammar/src/rule/mod.rs
scie-grammar/src/rule/mod.rs
+8
-175
未找到文件。
scie-grammar/src/rule/begin_while_rule.rs
0 → 100644
浏览文件 @
5310e8e8
use
crate
::
rule
::{
AbstractRule
,
Rule
};
use
crate
::
rule
::
reg_exp_source
::{
RegExpSource
,
RegExpSourceList
};
use
crate
::
rule
::
rule_factory
::
ICompilePatternsResult
;
use
crate
::
inter
::
ILocation
;
#[derive(Clone,
Debug,
Serialize)]
pub
struct
BeginWhileRule
{
pub
rule
:
Rule
,
pub
_
begin
:
RegExpSource
,
pub
begin_captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
pub
_
while
:
Option
<
String
>
,
pub
while_captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
pub
apply_end_pattern_last
:
bool
,
pub
patterns
:
ICompilePatternsResult
,
pub
has_missing_patterns
:
bool
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
cached_compiled_patterns
:
Option
<
RegExpSourceList
>
,
}
impl
BeginWhileRule
{
pub
fn
new
(
location
:
Option
<
ILocation
>
,
id
:
i32
,
name
:
Option
<
String
>
,
content_name
:
Option
<
String
>
,
_
begin
:
Option
<
String
>
,
begin_captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
_
while
:
Option
<
String
>
,
while_captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
patterns
:
ICompilePatternsResult
,
)
->
BeginWhileRule
{
BeginWhileRule
{
rule
:
Rule
{
_
type
:
String
::
from
(
"BeginWhileRule"
),
_
location
:
location
,
id
,
_
name
:
name
,
_
content_name
:
content_name
,
},
_
begin
:
RegExpSource
::
new
(
_
begin
.unwrap
()
.clone
(),
id
.clone
()),
begin_captures
,
_
while
,
while_captures
,
apply_end_pattern_last
:
false
,
has_missing_patterns
:
patterns
.clone
()
.has_missing_patterns
,
patterns
,
cached_compiled_patterns
:
None
,
}
}
}
impl
AbstractRule
for
BeginWhileRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
fn
has_missing_pattern
(
&
self
)
->
bool
{
self
.has_missing_patterns
}
}
scie-grammar/src/rule/capture_rule.rs
0 → 100644
浏览文件 @
5310e8e8
use
crate
::
rule
::{
Rule
,
AbstractRule
};
use
crate
::
inter
::
ILocation
;
#[derive(Clone,
Debug,
Serialize)]
pub
struct
CaptureRule
{
pub
rule
:
Rule
,
pub
retokenize_captured_with_rule_id
:
i32
,
}
impl
CaptureRule
{
pub
fn
empty
()
->
Self
{
CaptureRule
{
rule
:
Rule
{
_
type
:
""
.to_string
(),
_
location
:
None
,
id
:
0
,
_
name
:
None
,
_
content_name
:
None
,
},
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
{
CaptureRule
{
rule
:
Rule
{
_
type
:
String
::
from
(
"CaptureRule"
),
_
location
:
location
,
id
,
_
name
:
name
,
_
content_name
:
content_name
,
},
retokenize_captured_with_rule_id
,
}
}
}
impl
AbstractRule
for
CaptureRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
}
scie-grammar/src/rule/include_only_rule.rs
0 → 100644
浏览文件 @
5310e8e8
use
crate
::
rule
::
rule_factory
::
ICompilePatternsResult
;
use
crate
::
rule
::{
Rule
,
AbstractRule
};
use
crate
::
inter
::
ILocation
;
#[derive(Clone,
Debug,
Serialize)]
pub
struct
IncludeOnlyRule
{
#[serde(flatten)]
pub
rule
:
Rule
,
pub
patterns
:
Vec
<
i32
>
,
pub
has_missing_patterns
:
bool
,
}
impl
IncludeOnlyRule
{
pub
fn
new
(
location
:
Option
<
ILocation
>
,
id
:
i32
,
name
:
Option
<
String
>
,
content_name
:
Option
<
String
>
,
captures
:
ICompilePatternsResult
,
)
->
Self
{
IncludeOnlyRule
{
rule
:
Rule
{
_
type
:
String
::
from
(
"IncludeOnlyRule"
),
_
location
:
location
,
id
,
_
name
:
name
,
_
content_name
:
content_name
,
},
patterns
:
captures
.patterns
,
has_missing_patterns
:
captures
.has_missing_patterns
,
}
}
}
impl
AbstractRule
for
IncludeOnlyRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
fn
has_missing_pattern
(
&
self
)
->
bool
{
self
.has_missing_patterns
}
}
scie-grammar/src/rule/match_rule.rs
0 → 100644
浏览文件 @
5310e8e8
use
crate
::
rule
::{
AbstractRule
,
Rule
};
use
crate
::
inter
::
ILocation
;
use
crate
::
rule
::
reg_exp_source
::
RegExpSource
;
#[derive(Clone,
Debug,
Serialize)]
pub
struct
MatchRule
{
pub
rule
:
Rule
,
pub
_
match
:
RegExpSource
,
pub
captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
}
impl
MatchRule
{
pub
fn
new
(
location
:
Option
<
ILocation
>
,
id
:
i32
,
name
:
Option
<
String
>
,
_
match
:
String
,
captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
)
->
Self
{
MatchRule
{
rule
:
Rule
{
_
type
:
String
::
from
(
"MatchRule"
),
_
location
:
location
,
id
,
_
name
:
name
,
_
content_name
:
None
,
},
_
match
:
RegExpSource
::
new
(
_
match
,
id
),
captures
,
}
}
}
impl
AbstractRule
for
MatchRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
}
scie-grammar/src/rule/mod.rs
浏览文件 @
5310e8e8
...
...
@@ -4,11 +4,19 @@ pub mod reg_exp_source;
pub
mod
abstract_rule
;
pub
mod
begin_end_rule
;
pub
mod
begin_while_rule
;
pub
mod
compiled_rule
;
pub
mod
include_only_rule
;
pub
mod
match_rule
;
pub
mod
capture_rule
;
pub
use
self
::
abstract_rule
::
AbstractRule
;
pub
use
self
::
compiled_rule
::
CompiledRule
;
pub
use
self
::
begin_end_rule
::
BeginEndRule
;
pub
use
self
::
begin_while_rule
::
BeginWhileRule
;
pub
use
self
::
include_only_rule
::
IncludeOnlyRule
;
pub
use
self
::
match_rule
::
MatchRule
;
pub
use
self
::
capture_rule
::
CaptureRule
;
use
crate
::
inter
::{
ILocation
,
IRawGrammar
,
IRawRepository
};
use
reg_exp_source
::{
RegExpSource
,
RegExpSourceList
};
...
...
@@ -45,181 +53,6 @@ impl Rule {
}
}
#[derive(Clone,
Debug,
Serialize)]
pub
struct
IncludeOnlyRule
{
#[serde(flatten)]
pub
rule
:
Rule
,
pub
patterns
:
Vec
<
i32
>
,
pub
has_missing_patterns
:
bool
,
}
impl
IncludeOnlyRule
{
pub
fn
new
(
location
:
Option
<
ILocation
>
,
id
:
i32
,
name
:
Option
<
String
>
,
content_name
:
Option
<
String
>
,
captures
:
ICompilePatternsResult
,
)
->
Self
{
IncludeOnlyRule
{
rule
:
Rule
{
_
type
:
String
::
from
(
"IncludeOnlyRule"
),
_
location
:
location
,
id
,
_
name
:
name
,
_
content_name
:
content_name
,
},
patterns
:
captures
.patterns
,
has_missing_patterns
:
captures
.has_missing_patterns
,
}
}
}
impl
AbstractRule
for
IncludeOnlyRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
fn
has_missing_pattern
(
&
self
)
->
bool
{
self
.has_missing_patterns
}
}
#[derive(Clone,
Debug,
Serialize)]
pub
struct
BeginWhileRule
{
pub
rule
:
Rule
,
pub
_
begin
:
RegExpSource
,
pub
begin_captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
pub
_
while
:
Option
<
String
>
,
pub
while_captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
pub
apply_end_pattern_last
:
bool
,
pub
patterns
:
ICompilePatternsResult
,
pub
has_missing_patterns
:
bool
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
cached_compiled_patterns
:
Option
<
RegExpSourceList
>
,
}
impl
BeginWhileRule
{
pub
fn
new
(
location
:
Option
<
ILocation
>
,
id
:
i32
,
name
:
Option
<
String
>
,
content_name
:
Option
<
String
>
,
_
begin
:
Option
<
String
>
,
begin_captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
_
while
:
Option
<
String
>
,
while_captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
patterns
:
ICompilePatternsResult
,
)
->
BeginWhileRule
{
BeginWhileRule
{
rule
:
Rule
{
_
type
:
String
::
from
(
"BeginWhileRule"
),
_
location
:
location
,
id
,
_
name
:
name
,
_
content_name
:
content_name
,
},
_
begin
:
RegExpSource
::
new
(
_
begin
.unwrap
()
.clone
(),
id
.clone
()),
begin_captures
,
_
while
,
while_captures
,
apply_end_pattern_last
:
false
,
has_missing_patterns
:
patterns
.clone
()
.has_missing_patterns
,
patterns
,
cached_compiled_patterns
:
None
,
}
}
}
impl
AbstractRule
for
BeginWhileRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
fn
has_missing_pattern
(
&
self
)
->
bool
{
self
.has_missing_patterns
}
}
#[derive(Clone,
Debug,
Serialize)]
pub
struct
MatchRule
{
pub
rule
:
Rule
,
pub
_
match
:
RegExpSource
,
pub
captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
}
impl
MatchRule
{
pub
fn
new
(
location
:
Option
<
ILocation
>
,
id
:
i32
,
name
:
Option
<
String
>
,
_
match
:
String
,
captures
:
Vec
<
Box
<
dyn
AbstractRule
>>
,
)
->
Self
{
MatchRule
{
rule
:
Rule
{
_
type
:
String
::
from
(
"MatchRule"
),
_
location
:
location
,
id
,
_
name
:
name
,
_
content_name
:
None
,
},
_
match
:
RegExpSource
::
new
(
_
match
,
id
),
captures
,
}
}
}
impl
AbstractRule
for
MatchRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
}
#[derive(Clone,
Debug,
Serialize)]
pub
struct
CaptureRule
{
pub
rule
:
Rule
,
pub
retokenize_captured_with_rule_id
:
i32
,
}
impl
CaptureRule
{
pub
fn
empty
()
->
Self
{
CaptureRule
{
rule
:
Rule
{
_
type
:
""
.to_string
(),
_
location
:
None
,
id
:
0
,
_
name
:
None
,
_
content_name
:
None
,
},
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
{
CaptureRule
{
rule
:
Rule
{
_
type
:
String
::
from
(
"CaptureRule"
),
_
location
:
location
,
id
,
_
name
:
name
,
_
content_name
:
content_name
,
},
retokenize_captured_with_rule_id
,
}
}
}
impl
AbstractRule
for
CaptureRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
}
#[derive(Clone,
Debug,
Serialize)]
pub
struct
NoneRule
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录