Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
scie
提交
603ec605
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 搜索 >>
未验证
提交
603ec605
编写于
9月 02, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add basic scope list element push
上级
80ebad51
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
15 deletion
+51
-15
scie-grammar/src/grammar/grammar.rs
scie-grammar/src/grammar/grammar.rs
+10
-7
scie-grammar/src/grammar/line_tokens.rs
scie-grammar/src/grammar/line_tokens.rs
+11
-4
scie-grammar/src/grammar/scope_list_element.rs
scie-grammar/src/grammar/scope_list_element.rs
+30
-4
未找到文件。
scie-grammar/src/grammar/grammar.rs
浏览文件 @
603ec605
...
...
@@ -168,8 +168,8 @@ impl Grammar {
line_text
:
String
,
origin_is_first
:
bool
,
origin_line_pos
:
i32
,
prev_state
:
&
mut
StackElement
,
line_tokens
:
LineTokens
,
stack
:
&
mut
StackElement
,
mut
line_tokens
:
LineTokens
,
check_while_conditions
:
bool
,
)
->
Option
<
StackElement
>
{
let
_
line_length
=
line_text
.len
();
...
...
@@ -183,7 +183,7 @@ impl Grammar {
line_text
.clone
(),
origin_is_first
.clone
(),
origin_line_pos
.clone
(),
prev_state
.clone
(),
stack
.clone
(),
line_tokens
.clone
(),
);
}
...
...
@@ -192,7 +192,7 @@ impl Grammar {
let
mut
line_pos
=
origin_line_pos
.clone
();
let
mut
is_first_line
=
origin_is_first
.clone
();
while
!
_
stop
{
let
r
=
self
.match_rule
(
line_text
.clone
(),
is_first_line
,
line_pos
,
prev_state
,
anchor_position
);
let
r
=
self
.match_rule
(
line_text
.clone
(),
is_first_line
,
line_pos
,
stack
,
anchor_position
);
if
let
None
=
r
{
_
stop
=
true
;
return
None
;
...
...
@@ -205,7 +205,11 @@ impl Grammar {
println!
(
"todo: matched the `end` for this rule => pop it"
);
}
else
{
let
rule
=
self
.get_rule
(
matched_rule_id
);
line_tokens
.produce
(
prev_state
,
capture_indices
[
0
]
.start
as
i32
)
line_tokens
.produce
(
stack
,
capture_indices
[
0
]
.start
as
i32
);
let
before_push
=
stack
.clone
();
let
scope_name
=
rule
.get_name
(
Some
(
line_text
.clone
()),
Some
(
capture_indices
.clone
()));
// println!("{:?}", scope_name);
stack
.content_name_scopes_list
.push
(
self
,
scope_name
);
}
if
capture_indices
[
0
]
.end
>
line_pos
as
usize
{
...
...
@@ -213,7 +217,7 @@ impl Grammar {
is_first_line
=
false
;
}
}
Some
(
prev_state
.clone
())
Some
(
stack
.clone
())
}
pub
fn
check_while_conditions
(
...
...
@@ -267,7 +271,6 @@ impl Grammar {
is_first_line
,
line_pos
==
anchor_position
,
);
// rule_scanner.scanner
let
r
=
rule_scanner
.scanner
.find_next_match_sync
(
line_text
,
line_pos
);
if
let
Some
(
result
)
=
r
{
let
match_rule_result
=
MatchRuleResult
{
...
...
scie-grammar/src/grammar/line_tokens.rs
浏览文件 @
603ec605
use
crate
::
grammar
::{
StackElement
,
ScopeListElement
};
use
std
::
collections
::
HashMap
;
#[derive(Debug,
Clone)]
pub
struct
TokenTypeMatcher
{}
...
...
@@ -36,11 +37,11 @@ impl LineTokens {
}
}
pub
fn
produce
(
&
self
,
stack
:
&
mut
StackElement
,
end_index
:
i32
)
{
self
.produce_from_scopes
(
stack
.content_name_scopes_list
.clone
()
,
end_index
)
pub
fn
produce
(
&
mut
self
,
stack
:
&
mut
StackElement
,
end_index
:
i32
)
{
self
.produce_from_scopes
(
&
mut
stack
.content_name_scopes_list
,
end_index
)
}
pub
fn
produce_from_scopes
(
&
self
,
scopes_list
:
ScopeListElement
,
end_index
:
i32
)
{
pub
fn
produce_from_scopes
(
&
mut
self
,
scopes_list
:
&
mut
ScopeListElement
,
end_index
:
i32
)
{
if
self
._last_token_end_index
>
end_index
{
return
;
}
...
...
@@ -49,6 +50,12 @@ impl LineTokens {
// let meta_data = scopes_list.metadata;
// }
let
x
=
scopes_list
.generate_scopes
();
let
scopes
=
scopes_list
.generate_scopes
();
self
._tokens
.push
(
IToken
{
start_index
:
0
,
end_index
,
scopes
});
self
._last_token_end_index
=
end_index
}
}
scie-grammar/src/grammar/scope_list_element.rs
浏览文件 @
603ec605
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
hash_map
::
RandomState
;
use
crate
::
grammar
::
Grammar
;
#[derive(Debug,
Clone,
PartialEq,
Eq)]
pub
struct
ScopeListElement
{
...
...
@@ -17,14 +18,13 @@ impl ScopeListElement {
}
}
pub
fn
generate_scopes
(
&
self
)
->
HashMap
<
i32
,
String
>
{
let
mut
result
=
HashMap
::
new
();
let
mut
result_len
=
0
;
pub
fn
generate_scopes
(
&
self
)
->
Vec
<
String
>
{
let
mut
result
=
vec!
[];
let
mut
scope_list
=
self
.clone
();
let
mut
is_scope_list_none
=
false
;
while
!
is_scope_list_none
{
result
.
insert
(
result_len
,
scope_list
.scope
.clone
());
result
.
push
(
scope_list
.scope
.clone
());
match
scope_list
.parent
{
None
=>
{
is_scope_list_none
=
true
...
...
@@ -35,8 +35,34 @@ impl ScopeListElement {
}
}
result
.reverse
();
return
result
.clone
();
}
pub
fn
_
push
(
origin_target
:
ScopeListElement
,
grammar
:
&
mut
Grammar
,
scopes
:
Vec
<
String
>
)
->
ScopeListElement
{
let
mut
target
=
origin_target
.clone
();
for
scope
in
scopes
{
target
=
ScopeListElement
::
new
(
Some
(
Box
::
new
(
target
)),
scope
);
}
target
}
pub
fn
push
(
&
self
,
grammar
:
&
mut
Grammar
,
scope
:
Option
<
String
>
)
->
ScopeListElement
{
if
let
None
=
scope
{
return
self
.clone
()
}
let
scope_name
=
scope
.clone
()
.unwrap
();
return
match
scope
.iter
()
.position
(|
s
|
s
==
" "
)
{
None
=>
{
ScopeListElement
::
_
push
(
self
.clone
(),
grammar
,
vec!
[
scope_name
])
},
Some
(
_
)
=>
{
println!
(
"todo: ScopeListElement push"
);
self
.clone
()
},
}
}
}
impl
Default
for
ScopeListElement
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录