Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
scie
提交
6b713c5e
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 搜索 >>
未验证
提交
6b713c5e
编写于
8月 30, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix lint
上级
09ef5393
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
230 addition
and
128 deletion
+230
-128
scie-grammar/src/grammar/grammar/mod.rs
scie-grammar/src/grammar/grammar/mod.rs
+40
-12
scie-grammar/src/grammar/grammar/stack_element.rs
scie-grammar/src/grammar/grammar/stack_element.rs
+15
-7
scie-grammar/src/grammar/line_tokens.rs
scie-grammar/src/grammar/line_tokens.rs
+8
-5
scie-grammar/src/grammar/mod.rs
scie-grammar/src/grammar/mod.rs
+3
-3
scie-grammar/src/inter/mod.rs
scie-grammar/src/inter/mod.rs
+19
-19
scie-grammar/src/lib.rs
scie-grammar/src/lib.rs
+1
-1
scie-grammar/src/matcher.rs
scie-grammar/src/matcher.rs
+1
-3
scie-grammar/src/rule/abstract_rule.rs
scie-grammar/src/rule/abstract_rule.rs
+17
-5
scie-grammar/src/rule/begin_end_rule.rs
scie-grammar/src/rule/begin_end_rule.rs
+5
-4
scie-grammar/src/rule/begin_while_rule.rs
scie-grammar/src/rule/begin_while_rule.rs
+5
-3
scie-grammar/src/rule/capture_rule.rs
scie-grammar/src/rule/capture_rule.rs
+14
-4
scie-grammar/src/rule/compiled_rule.rs
scie-grammar/src/rule/compiled_rule.rs
+6
-3
scie-grammar/src/rule/empty_rule.rs
scie-grammar/src/rule/empty_rule.rs
+3
-1
scie-grammar/src/rule/include_only_rule.rs
scie-grammar/src/rule/include_only_rule.rs
+5
-3
scie-grammar/src/rule/match_rule.rs
scie-grammar/src/rule/match_rule.rs
+4
-2
scie-grammar/src/rule/mod.rs
scie-grammar/src/rule/mod.rs
+7
-7
scie-grammar/src/rule/rule.rs
scie-grammar/src/rule/rule.rs
+1
-1
scie-grammar/src/rule/rule_convert.rs
scie-grammar/src/rule/rule_convert.rs
+7
-6
scie-grammar/src/rule/rule_factory.rs
scie-grammar/src/rule/rule_factory.rs
+69
-39
未找到文件。
scie-grammar/src/grammar/grammar/mod.rs
浏览文件 @
6b713c5e
...
...
@@ -5,8 +5,8 @@ use onig::*;
use
crate
::
grammar
::
line_tokens
::{
LineTokens
,
TokenTypeMatcher
};
use
crate
::
grammar
::{
ScopeListElement
,
StackElement
};
use
crate
::
inter
::{
IRawGrammar
,
IRawRepository
,
IRawRepositoryMap
,
IRawRule
};
use
crate
::
rule
::{
AbstractRule
,
EmptyRule
,
IGrammarRegistry
,
IRuleFactoryHelper
,
IRuleRegistry
};
use
crate
::
rule
::
rule_factory
::
RuleFactory
;
use
crate
::
rule
::{
AbstractRule
,
EmptyRule
,
IGrammarRegistry
,
IRuleFactoryHelper
,
IRuleRegistry
};
pub
mod
scope_list_element
;
pub
mod
scope_metadata
;
...
...
@@ -107,15 +107,17 @@ impl Grammar {
if
self
.root_id
.clone
()
==
-
1
{
let
mut
repository
=
self
.grammar.repository
.clone
()
.unwrap
();
let
based
=
repository
.clone
()
.map.self_s
.unwrap
();
self
.root_id
=
RuleFactory
::
get_compiled_rule_id
(
based
.clone
(),
self
,
&
mut
repository
.clone
(),
String
::
from
(
""
));
self
.root_id
=
RuleFactory
::
get_compiled_rule_id
(
based
.clone
(),
self
,
&
mut
repository
.clone
(),
String
::
from
(
""
),
);
}
let
mut
is_first_line
:
bool
=
false
;
match
prev_state
.clone
()
{
None
=>
{
is_first_line
=
true
}
None
=>
is_first_line
=
true
,
Some
(
state
)
=>
{
if
state
==
StackElement
::
null
()
{
is_first_line
=
true
...
...
@@ -125,11 +127,24 @@ impl Grammar {
if
is_first_line
{
let
scope_list
=
ScopeListElement
::
default
();
prev_state
=
Some
(
StackElement
::
new
(
None
,
self
.root_id
.clone
(),
-
1
,
-
1
,
false
,
None
,
scope_list
.clone
(),
scope_list
.clone
()))
prev_state
=
Some
(
StackElement
::
new
(
None
,
self
.root_id
.clone
(),
-
1
,
-
1
,
false
,
None
,
scope_list
.clone
(),
scope_list
.clone
(),
))
}
let
format_line_text
=
format!
(
"{:?}
\n
"
,
line_text
);
let
line_tokens
=
LineTokens
::
new
(
emit_binary_tokens
,
line_text
,
self
._token_type_matchers
.clone
());
let
line_tokens
=
LineTokens
::
new
(
emit_binary_tokens
,
line_text
,
self
._token_type_matchers
.clone
(),
);
self
.tokenize_string
(
format_line_text
.parse
()
.unwrap
(),
is_first_line
,
...
...
@@ -164,8 +179,13 @@ impl Grammar {
);
}
self
.match_rule_or_injections
(
line_text
,
is_first_line
,
line_pos
,
prev_state
,
anchor_position
);
self
.match_rule_or_injections
(
line_text
,
is_first_line
,
line_pos
,
prev_state
,
anchor_position
,
);
}
pub
fn
check_while_conditions
(
...
...
@@ -177,7 +197,9 @@ impl Grammar {
line_tokens
:
LineTokens
,
)
{
let
mut
anchor_position
=
-
1
;
if
_
stack
.begin_rule_captured_eol
{
anchor_position
=
0
}
if
_
stack
.begin_rule_captured_eol
{
anchor_position
=
0
}
// let while_rules = vec![];
}
...
...
@@ -189,7 +211,13 @@ impl Grammar {
stack
:
StackElement
,
anchor_position
:
i32
,
)
{
self
.match_rule
(
line_text
,
is_first_line
,
line_pos
,
stack
.clone
(),
anchor_position
);
self
.match_rule
(
line_text
,
is_first_line
,
line_pos
,
stack
.clone
(),
anchor_position
,
);
}
pub
fn
match_rule
(
...
...
scie-grammar/src/grammar/grammar/stack_element.rs
浏览文件 @
6b713c5e
use
core
::
ptr
;
use
crate
::
grammar
::{
Grammar
,
ScopeListElement
};
use
crate
::
grammar
::
grammar_registry
::
GrammarRegistry
;
use
crate
::
rule
::{
IRuleRegistry
,
AbstractRule
};
use
crate
::
grammar
::{
Grammar
,
ScopeListElement
};
use
crate
::
rule
::{
AbstractRule
,
IRuleRegistry
};
use
core
::
ptr
;
#[derive(Debug,
Clone,
PartialEq,
Eq)]
pub
struct
StackElement
{
...
...
@@ -27,8 +27,7 @@ impl StackElement {
begin_rule_captured_eol
:
false
,
end_rule
:
None
,
name_scopes_list
:
Default
::
default
(),
content_name_scopes_list
:
Default
::
default
()
content_name_scopes_list
:
Default
::
default
(),
}
}
...
...
@@ -38,7 +37,16 @@ impl StackElement {
pub
fn
get_rule
(
&
self
,
grammar
:
&
mut
Grammar
)
->
Box
<
dyn
AbstractRule
>
{
grammar
.get_rule
(
self
.rule_id
)
}
pub
fn
new
(
parent
:
Option
<
Box
<
StackElement
>>
,
rule_id
:
i32
,
enter_pos
:
i32
,
anchor_pos
:
i32
,
begin_rule_captured_eol
:
bool
,
end_rule
:
Option
<
String
>
,
name_scopes_list
:
ScopeListElement
,
content_name_scopes_list
:
ScopeListElement
)
->
Self
{
pub
fn
new
(
parent
:
Option
<
Box
<
StackElement
>>
,
rule_id
:
i32
,
enter_pos
:
i32
,
anchor_pos
:
i32
,
begin_rule_captured_eol
:
bool
,
end_rule
:
Option
<
String
>
,
name_scopes_list
:
ScopeListElement
,
content_name_scopes_list
:
ScopeListElement
,
)
->
Self
{
StackElement
{
parent
,
// todo: this.depth = (this.parent ? this.parent.depth + 1 : 1);
...
...
@@ -49,7 +57,7 @@ impl StackElement {
begin_rule_captured_eol
,
end_rule
,
name_scopes_list
,
content_name_scopes_list
content_name_scopes_list
,
}
}
}
scie-grammar/src/grammar/line_tokens.rs
浏览文件 @
6b713c5e
...
...
@@ -5,7 +5,7 @@ pub struct TokenTypeMatcher {}
pub
struct
IToken
{
pub
start_index
:
i32
,
pub
end_index
:
i32
,
pub
scopes
:
Vec
<
String
>
pub
scopes
:
Vec
<
String
>
,
}
#[derive(Debug,
Clone)]
...
...
@@ -15,19 +15,22 @@ pub struct LineTokens {
pub
_
tokens
:
Vec
<
IToken
>
,
pub
_
binary_tokens
:
Vec
<
IToken
>
,
pub
_
last_token_end_index
:
i32
,
pub
_
token_type_overrides
:
Vec
<
TokenTypeMatcher
>
pub
_
token_type_overrides
:
Vec
<
TokenTypeMatcher
>
,
}
impl
LineTokens
{
pub
fn
new
(
emit_binary_tokens
:
bool
,
_
line_text
:
String
,
_
token_type_overrides
:
Vec
<
TokenTypeMatcher
>
)
->
Self
{
pub
fn
new
(
emit_binary_tokens
:
bool
,
_
line_text
:
String
,
_
token_type_overrides
:
Vec
<
TokenTypeMatcher
>
,
)
->
Self
{
LineTokens
{
emit_binary_tokens
,
_
line_text
,
_
tokens
:
vec!
[],
_
binary_tokens
:
vec!
[],
_
last_token_end_index
:
0
,
_
token_type_overrides
_
token_type_overrides
,
}
}
}
scie-grammar/src/grammar/mod.rs
浏览文件 @
6b713c5e
pub
mod
grammar
;
pub
mod
grammar_reader
;
pub
mod
line_tokens
;
pub
mod
grammar_registry
;
pub
mod
line_tokens
;
pub
use
self
::
grammar
::
Grammar
;
pub
use
self
::
grammar
::
stack_element
::
StackElement
;
pub
use
self
::
grammar
::
scope_list_element
::
ScopeListElement
;
pub
use
self
::
grammar
::
scope_metadata
::
ScopeMetadata
;
pub
use
self
::
grammar
::
stack_element
::
StackElement
;
pub
use
self
::
grammar
::
Grammar
;
scie-grammar/src/inter/mod.rs
浏览文件 @
6b713c5e
...
...
@@ -20,7 +20,7 @@ impl ILocation {
#[derive(Serialize,
Deserialize,
PartialEq,
Debug,
Clone)]
pub
struct
ILocatable
{
#[serde(flatten,
skip_serializing_if
=
"Option::is_none"
)]
#[serde(flatten,
skip_serializing_if
=
"Option::is_none"
)]
pub
textmate_location
:
Option
<
ILocation
>
,
}
...
...
@@ -42,9 +42,9 @@ pub struct IRawCapturesMap {
pub
struct
IRawRepositoryMap
{
#[serde(flatten)]
pub
name_map
:
HashMap
<
String
,
Box
<
IRawRule
>>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
self_s
:
Option
<
IRawRule
>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
base_s
:
Option
<
IRawRule
>
,
}
...
...
@@ -62,7 +62,7 @@ impl IRawRepositoryMap {
pub
struct
IRawRepository
{
#[serde(flatten)]
pub
map
:
Box
<
IRawRepositoryMap
>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
location
:
Option
<
ILocation
>
,
}
...
...
@@ -79,19 +79,19 @@ impl IRawRepository {
pub
struct
IRawCaptures
{
#[serde(flatten)]
pub
map
:
IRawCapturesMap
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
location
:
Option
<
ILocatable
>
,
}
#[derive(Serialize,
Deserialize,
PartialEq,
Debug,
Clone)]
pub
struct
IRawRule
{
pub
id
:
Option
<
i32
>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
location
:
Option
<
ILocation
>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
include
:
Option
<
String
>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
name
:
Option
<
String
>
,
#[serde(alias
=
"contentName"
)]
...
...
@@ -99,34 +99,34 @@ pub struct IRawRule {
#[serde(alias
=
"match"
)]
pub
match_s
:
Option
<
String
>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
captures
:
Option
<
Box
<
IRawCaptures
>>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
begin
:
Option
<
String
>
,
#[serde(alias
=
"beginCaptures"
,
skip_serializing_if
=
"Option::is_none"
)]
#[serde(alias
=
"beginCaptures"
,
skip_serializing_if
=
"Option::is_none"
)]
pub
begin_captures
:
Option
<
Box
<
IRawCaptures
>>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
end
:
Option
<
String
>
,
#[serde(alias
=
"endCaptures"
,
skip_serializing_if
=
"Option::is_none"
)]
#[serde(alias
=
"endCaptures"
,
skip_serializing_if
=
"Option::is_none"
)]
pub
end_captures
:
Option
<
Box
<
IRawCaptures
>>
,
#[serde(alias
=
"while"
,
skip_serializing_if
=
"Option::is_none"
)]
#[serde(alias
=
"while"
,
skip_serializing_if
=
"Option::is_none"
)]
pub
while_s
:
Option
<
String
>
,
#[serde(alias
=
"whileCaptures"
,
skip_serializing_if
=
"Option::is_none"
)]
#[serde(alias
=
"whileCaptures"
,
skip_serializing_if
=
"Option::is_none"
)]
pub
while_captures
:
Option
<
Box
<
IRawCaptures
>>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
patterns
:
Option
<
Vec
<
IRawRule
>>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
repository
:
Option
<
IRawRepository
>
,
#[serde(alias
=
"applyEndPatternLast"
,
skip_serializing_if
=
"Option::is_none"
)]
#[serde(alias
=
"applyEndPatternLast"
,
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
information_for_contributors
:
Option
<
Vec
<
String
>>
,
}
...
...
scie-grammar/src/lib.rs
浏览文件 @
6b713c5e
...
...
@@ -8,5 +8,5 @@ extern crate erased_serde;
pub
mod
grammar
;
pub
mod
inter
;
pub
mod
rule
;
pub
mod
matcher
;
pub
mod
rule
;
scie-grammar/src/matcher.rs
浏览文件 @
6b713c5e
...
...
@@ -9,6 +9,4 @@ pub struct MatcherWithPriority {
priority
:
MatchPriority
,
}
pub
struct
Matcher
{
}
\ No newline at end of file
pub
struct
Matcher
{}
scie-grammar/src/rule/abstract_rule.rs
浏览文件 @
6b713c5e
use
dyn_clone
::{
clone_trait_object
,
DynClone
};
use
core
::
fmt
;
use
crate
::
rule
::{
IRuleRegistry
,
RegExpSourceList
};
use
core
::
fmt
;
use
dyn_clone
::{
clone_trait_object
,
DynClone
};
pub
trait
AbstractRule
:
DynClone
+
erased_serde
::
Serialize
{
fn
id
(
&
self
)
->
i32
;
...
...
@@ -8,8 +8,21 @@ pub trait AbstractRule: DynClone + erased_serde::Serialize {
fn
has_missing_pattern
(
&
self
)
->
bool
{
false
}
fn
collect_patterns_recursive
(
&
self
,
grammar
:
Box
<
dyn
IRuleRegistry
>
,
out
:
RegExpSourceList
,
is_first
:
bool
)
{}
fn
compile
(
&
self
,
grammar
:
Box
<
dyn
IRuleRegistry
>
,
end_regex_source
:
Option
<
String
>
,
allow_a
:
bool
,
allow_g
:
bool
)
{}
fn
collect_patterns_recursive
(
&
self
,
grammar
:
Box
<
dyn
IRuleRegistry
>
,
out
:
RegExpSourceList
,
is_first
:
bool
,
)
{
}
fn
compile
(
&
self
,
grammar
:
Box
<
dyn
IRuleRegistry
>
,
end_regex_source
:
Option
<
String
>
,
allow_a
:
bool
,
allow_g
:
bool
,
)
{
}
}
impl
fmt
::
Debug
for
dyn
AbstractRule
{
...
...
@@ -21,4 +34,3 @@ impl fmt::Debug for dyn AbstractRule {
serialize_trait_object!
(
AbstractRule
);
clone_trait_object!
(
AbstractRule
);
scie-grammar/src/rule/begin_end_rule.rs
浏览文件 @
6b713c5e
use
crate
::
rule
::{
RegExpSource
,
RegExpSourceList
};
use
crate
::
rule
::{
Rule
,
AbstractRule
};
use
crate
::
inter
::
ILocation
;
use
crate
::
rule
::
rule_factory
::
ICompilePatternsResult
;
use
crate
::
rule
::{
AbstractRule
,
Rule
};
use
crate
::
rule
::{
RegExpSource
,
RegExpSourceList
};
#[derive(Clone,
Debug,
Serialize)]
pub
struct
BeginEndRule
{
...
...
@@ -54,7 +54,9 @@ impl BeginEndRule {
}
impl
AbstractRule
for
BeginEndRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
...
...
@@ -62,4 +64,3 @@ impl AbstractRule for BeginEndRule {
self
.has_missing_patterns
}
}
scie-grammar/src/rule/begin_while_rule.rs
浏览文件 @
6b713c5e
use
crate
::
inter
::
ILocation
;
use
crate
::
rule
::
rule_factory
::
ICompilePatternsResult
;
use
crate
::
rule
::{
AbstractRule
,
Rule
};
use
crate
::
rule
::{
RegExpSource
,
RegExpSourceList
};
use
crate
::
rule
::
rule_factory
::
ICompilePatternsResult
;
use
crate
::
inter
::
ILocation
;
#[derive(Clone,
Debug,
Serialize)]
pub
struct
BeginWhileRule
{
...
...
@@ -54,7 +54,9 @@ impl BeginWhileRule {
}
impl
AbstractRule
for
BeginWhileRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
...
...
scie-grammar/src/rule/capture_rule.rs
浏览文件 @
6b713c5e
use
crate
::
rule
::{
Rule
,
AbstractRule
};
use
crate
::
inter
::
ILocation
;
use
crate
::
rule
::{
AbstractRule
,
Rule
};
#[derive(Clone,
Debug,
Serialize)]
pub
struct
CaptureRule
{
...
...
@@ -20,7 +20,13 @@ impl CaptureRule {
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
{
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"
),
...
...
@@ -35,6 +41,10 @@ impl CaptureRule {
}
impl
AbstractRule
for
CaptureRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
}
scie-grammar/src/rule/compiled_rule.rs
浏览文件 @
6b713c5e
pub
struct
CompiledRule
{
pub
debug_reg_exps
:
Vec
<
String
>
,
pub
rules
:
Vec
<
i32
>
pub
rules
:
Vec
<
i32
>
,
}
impl
CompiledRule
{
pub
fn
new
(
debug_reg_exps
:
Vec
<
String
>
,
rules
:
Vec
<
i32
>
)
->
Self
{
CompiledRule
{
debug_reg_exps
,
rules
}
CompiledRule
{
debug_reg_exps
,
rules
,
}
}
}
\ No newline at end of file
}
scie-grammar/src/rule/empty_rule.rs
浏览文件 @
6b713c5e
...
...
@@ -4,7 +4,9 @@ use crate::rule::AbstractRule;
pub
struct
EmptyRule
{}
impl
AbstractRule
for
EmptyRule
{
fn
id
(
&
self
)
->
i32
{
0
}
fn
id
(
&
self
)
->
i32
{
0
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
"EmptyRule"
)
}
...
...
scie-grammar/src/rule/include_only_rule.rs
浏览文件 @
6b713c5e
use
crate
::
rule
::
rule_factory
::
ICompilePatternsResult
;
use
crate
::
rule
::{
Rule
,
AbstractRule
};
use
crate
::
inter
::
ILocation
;
use
crate
::
rule
::
rule_factory
::
ICompilePatternsResult
;
use
crate
::
rule
::{
AbstractRule
,
Rule
};
#[derive(Clone,
Debug,
Serialize)]
pub
struct
IncludeOnlyRule
{
...
...
@@ -33,7 +33,9 @@ impl IncludeOnlyRule {
}
impl
AbstractRule
for
IncludeOnlyRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
...
...
scie-grammar/src/rule/match_rule.rs
浏览文件 @
6b713c5e
use
crate
::
rule
::{
AbstractRule
,
Rule
};
use
crate
::
inter
::
ILocation
;
use
crate
::
rule
::
RegExpSource
;
use
crate
::
rule
::{
AbstractRule
,
Rule
};
#[derive(Clone,
Debug,
Serialize)]
pub
struct
MatchRule
{
...
...
@@ -32,7 +32,9 @@ impl MatchRule {
}
impl
AbstractRule
for
MatchRule
{
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
id
(
&
self
)
->
i32
{
self
.rule.id
}
fn
type_of
(
&
self
)
->
String
{
String
::
from
(
self
.rule
.clone
()
._type
)
}
...
...
scie-grammar/src/rule/mod.rs
浏览文件 @
6b713c5e
pub
mod
rule_factory
;
pub
mod
rule_convert
;
pub
mod
rule_factory
;
pub
mod
abstract_rule
;
pub
mod
begin_end_rule
;
pub
mod
begin_while_rule
;
pub
mod
capture_rule
;
pub
mod
compiled_rule
;
pub
mod
empty_rule
;
pub
mod
include_only_rule
;
pub
mod
match_rule
;
pub
mod
capture_rule
;
pub
mod
empty_rule
;
pub
mod
rule
;
pub
use
self
::
rule
::
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
;
pub
use
self
::
compiled_rule
::
CompiledRule
;
pub
use
self
::
empty_rule
::
EmptyRule
;
pub
use
self
::
include_only_rule
::
IncludeOnlyRule
;
pub
use
self
::
match_rule
::
MatchRule
;
pub
use
self
::
rule
::
Rule
;
use
crate
::
inter
::{
ILocation
,
IRawGrammar
,
IRawRepository
};
use
crate
::
rule
::
rule_factory
::
ICompilePatternsResult
;
...
...
scie-grammar/src/rule/rule.rs
浏览文件 @
6b713c5e
...
...
@@ -27,4 +27,4 @@ impl Rule {
_
content_name
:
content_name
,
}
}
}
\ No newline at end of file
}
scie-grammar/src/rule/rule_convert.rs
浏览文件 @
6b713c5e
use
crate
::
rule
::{
AbstractRule
,
BeginEndRule
,
BeginWhileRule
,
CaptureRule
,
IncludeOnlyRule
,
MatchRule
,
};
use
std
::
collections
::
BTreeMap
as
Map
;
use
crate
::
rule
::{
AbstractRule
,
MatchRule
,
IncludeOnlyRule
,
CaptureRule
,
BeginWhileRule
,
BeginEndRule
};
#[derive(Serialize,
Debug)]
pub
struct
RuleList
{
...
...
@@ -47,15 +49,14 @@ fn abstract_rule_to_json(map: Map<i32, Box<dyn AbstractRule>>) {
println!
(
"{:?}"
,
j
);
}
#[cfg(test)]
mod
tests
{
use
crate
::
grammar
::
Grammar
;
use
std
::
path
::
Path
;
use
std
::
fs
::
File
;
use
crate
::
inter
::
IRawGrammar
;
use
std
::
io
::
Read
;
use
crate
::
rule
::
rule_convert
::
abstract_rule_to_json
;
use
std
::
fs
::
File
;
use
std
::
io
::
Read
;
use
std
::
path
::
Path
;
#[test]
fn
should_build_text_grammar
()
{
...
...
@@ -82,4 +83,4 @@ GitHub 漫游指南
grammar
}
}
\ No newline at end of file
}
scie-grammar/src/rule/rule_factory.rs
浏览文件 @
6b713c5e
use
crate
::
grammar
::
Grammar
;
use
crate
::
inter
::{
IRawCaptures
,
IRawRepository
,
IRawRule
,
ILocation
};
use
crate
::
rule
::{
BeginEndRule
,
BeginWhileRule
,
CaptureRule
,
IRuleRegistry
,
IncludeOnlyRule
,
MatchRule
,
AbstractRule
,
Rule
};
use
crate
::
inter
::{
ILocation
,
IRawCaptures
,
IRawRepository
,
IRawRule
};
use
crate
::
rule
::{
AbstractRule
,
BeginEndRule
,
BeginWhileRule
,
CaptureRule
,
IRuleRegistry
,
IncludeOnlyRule
,
MatchRule
,
Rule
,
};
#[derive(Clone,
Debug,
Serialize)]
pub
struct
ICompilePatternsResult
{
...
...
@@ -33,22 +36,34 @@ impl RuleFactory {
}
}
r
.resize
((
maximum_capture_id
+
1
)
as
usize
,
Box
::
new
(
CaptureRule
::
empty
()));
r
.resize
(
(
maximum_capture_id
+
1
)
as
usize
,
Box
::
new
(
CaptureRule
::
empty
()),
);
for
(
id_str
,
desc
)
in
capts
.clone
()
.map.capture_map
{
// todo: figure captureId === '$vscodeTextmateLocation'
let
numeric_capture_id
:
usize
=
id_str
.parse
()
.unwrap_or
(
0
);
let
mut
retokenize_captured_with_rule_id
=
0
;
let
options_patterns
=
capts
.map.capture_map
.get
(
&*
numeric_capture_id
.to_string
());
let
options_patterns
=
capts
.map.capture_map
.get
(
&*
numeric_capture_id
.to_string
());
if
let
Some
(
rule
)
=
options_patterns
{
if
let
Some
(
patterns
)
=
rule
.clone
()
.patterns
{
retokenize_captured_with_rule_id
=
RuleFactory
::
get_compiled_rule_id
(
desc
.clone
(),
helper
,
repository
,
String
::
from
(
""
));
retokenize_captured_with_rule_id
=
RuleFactory
::
get_compiled_rule_id
(
desc
.clone
(),
helper
,
repository
,
String
::
from
(
""
),
);
}
}
r
[
numeric_capture_id
]
=
RuleFactory
::
create_capture_rule
(
helper
,
desc
.clone
()
.location
,
desc
.clone
()
.name
,
desc
.clone
()
.content_name
,
retokenize_captured_with_rule_id
);
r
[
numeric_capture_id
]
=
RuleFactory
::
create_capture_rule
(
helper
,
desc
.clone
()
.location
,
desc
.clone
()
.name
,
desc
.clone
()
.content_name
,
retokenize_captured_with_rule_id
,
);
}
// todo: remove first element, because it's filled & empty.
};
...
...
@@ -56,14 +71,25 @@ impl RuleFactory {
r
}
pub
fn
create_capture_rule
(
helper
:
&
mut
Grammar
,
location
:
Option
<
ILocation
>
,
name
:
Option
<
String
>
,
content_name
:
Option
<
String
>
,
retokenizeCapturedWithRuleId
:
i32
)
->
Box
<
dyn
AbstractRule
>
{
pub
fn
create_capture_rule
(
helper
:
&
mut
Grammar
,
location
:
Option
<
ILocation
>
,
name
:
Option
<
String
>
,
content_name
:
Option
<
String
>
,
retokenizeCapturedWithRuleId
:
i32
,
)
->
Box
<
dyn
AbstractRule
>
{
let
id
=
helper
.register_id
();
let
rule
=
CaptureRule
::
new
(
location
,
id
,
name
,
content_name
,
retokenizeCapturedWithRuleId
);
let
rule
=
CaptureRule
::
new
(
location
,
id
,
name
,
content_name
,
retokenizeCapturedWithRuleId
,
);
helper
.register_rule
(
Box
::
from
(
rule
));
return
helper
.get_rule
(
id
);
}
pub
fn
compile_patterns
(
origin_patterns
:
Option
<
Vec
<
IRawRule
>>
,
helper
:
&
mut
Grammar
,
...
...
@@ -92,7 +118,8 @@ impl RuleFactory {
);
}
}
else
if
include_s
==
"$base"
||
include_s
==
"$self"
{
let
local_included_rule
=
repository
.map.name_map
.get_mut
(
include_s
.as_str
());
let
local_included_rule
=
repository
.map.name_map
.get_mut
(
include_s
.as_str
());
if
let
Some
(
mut
rule
)
=
local_included_rule
.cloned
()
{
pattern_id
=
RuleFactory
::
get_compiled_rule_id
(
*
rule
,
...
...
@@ -123,15 +150,22 @@ impl RuleFactory {
}
}
}
else
{
pattern_id
=
RuleFactory
::
get_compiled_rule_id
(
pattern
,
helper
,
repository
,
String
::
from
(
""
));
pattern_id
=
RuleFactory
::
get_compiled_rule_id
(
pattern
,
helper
,
repository
,
String
::
from
(
""
),
);
}
if
pattern_id
!=
-
1
{
let
rule
=
helper
.get_rule
(
pattern_id
);
let
mut
skip_rule
=
false
;
if
rule
.type_of
()
==
"IncludeOnlyRule"
||
rule
.type_of
()
==
"BeginEndRule"
||
rule
.type_of
()
==
"BeginWhileRule"
{
if
rule
.has_missing_pattern
()
{
if
rule
.type_of
()
==
"IncludeOnlyRule"
||
rule
.type_of
()
==
"BeginEndRule"
||
rule
.type_of
()
==
"BeginWhileRule"
{
if
rule
.has_missing_pattern
()
{
skip_rule
=
true
;
}
}
...
...
@@ -151,12 +185,12 @@ impl RuleFactory {
if
0
!=
r
.len
()
{
has_missing_patterns
=
true
}
}
,
}
Some
(
patterns
)
=>
{
if
patterns
.len
()
!=
r
.len
()
{
has_missing_patterns
=
true
}
}
,
}
}
let
result
=
ICompilePatternsResult
{
...
...
@@ -182,16 +216,17 @@ impl RuleFactory {
// by name.
if
desc_name
!=
""
{
if
let
Some
(
a
)
=
repository
.map.name_map
.get
(
desc_name
.as_str
())
.clone
()
{
repository
.map.name_map
.get_mut
(
desc_name
.as_str
())
.unwrap
()
.id
=
Some
(
id
);
repository
.map
.name_map
.get_mut
(
desc_name
.as_str
())
.unwrap
()
.id
=
Some
(
id
);
}
}
if
let
Some
(
match_s
)
=
desc
.match_s
{
let
rule_factory
=
RuleFactory
::
compile_captures
(
desc
.captures
,
helper
,
repository
,
);
let
rule_factory
=
RuleFactory
::
compile_captures
(
desc
.captures
,
helper
,
repository
);
let
match_rule
=
MatchRule
::
new
(
desc
.location
.clone
(),
id
.clone
(),
...
...
@@ -206,7 +241,11 @@ impl RuleFactory {
if
let
None
=
desc
.begin
{
if
let
Some
(
repo
)
=
desc
.repository
.clone
()
{
desc
.repository
.unwrap
()
.map.name_map
.extend
(
repository
.clone
()
.map.name_map
);
desc
.repository
.unwrap
()
.map
.name_map
.extend
(
repository
.clone
()
.map.name_map
);
}
let
mut
patterns
=
desc
.patterns
;
...
...
@@ -218,8 +257,7 @@ impl RuleFactory {
}
}
let
rule_factory
=
RuleFactory
::
compile_patterns
(
patterns
,
helper
,
repository
);
let
rule_factory
=
RuleFactory
::
compile_patterns
(
patterns
,
helper
,
repository
);
let
include_only_rule
=
IncludeOnlyRule
::
new
(
desc
.location
.clone
(),
id
.clone
(),
...
...
@@ -247,11 +285,8 @@ impl RuleFactory {
RuleFactory
::
compile_captures
(
begin_captures
,
helper
,
repository
);
let
end_rule_factory
=
RuleFactory
::
compile_captures
(
end_captures
,
helper
,
repository
);
let
pattern_factory
=
RuleFactory
::
compile_patterns
(
desc
.patterns
,
helper
,
repository
,
);
let
pattern_factory
=
RuleFactory
::
compile_patterns
(
desc
.patterns
,
helper
,
repository
);
let
begin_while_rule
=
BeginWhileRule
::
new
(
desc
.location
,
...
...
@@ -271,13 +306,8 @@ impl RuleFactory {
let
begin_rule_factory
=
RuleFactory
::
compile_captures
(
begin_captures
,
helper
,
repository
);
let
end_rule_factory
=
RuleFactory
::
compile_captures
(
end_captures
,
helper
,
repository
);
let
pattern_factory
=
RuleFactory
::
compile_patterns
(
desc
.patterns
,
helper
,
repository
,
);
let
end_rule_factory
=
RuleFactory
::
compile_captures
(
end_captures
,
helper
,
repository
);
let
pattern_factory
=
RuleFactory
::
compile_patterns
(
desc
.patterns
,
helper
,
repository
);
// todo: register with compile patterns
let
begin_end_rule
=
BeginEndRule
::
new
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录