Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
scie
提交
80ebad51
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 搜索 >>
未验证
提交
80ebad51
编写于
9月 02, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add get name support
上级
a614fb51
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
40 addition
and
15 deletion
+40
-15
scie-grammar/src/grammar/grammar.rs
scie-grammar/src/grammar/grammar.rs
+15
-5
scie-grammar/src/grammar/scope_list_element.rs
scie-grammar/src/grammar/scope_list_element.rs
+6
-6
scie-grammar/src/rule/abstract_rule.rs
scie-grammar/src/rule/abstract_rule.rs
+12
-2
scie-grammar/src/support/regex_source.rs
scie-grammar/src/support/regex_source.rs
+7
-2
未找到文件。
scie-grammar/src/grammar/grammar.rs
浏览文件 @
80ebad51
...
...
@@ -119,10 +119,18 @@ impl Grammar {
}
if
is_first_line
{
let
scope_list
=
ScopeListElement
::
default
();
// self.get_rule(self.root_id.clone());
// let scope_list = ScopeListElement::new(
// None, );
// let scope_list = ScopeListElement::default();
let
_
root_scope_name
=
self
.get_rule
(
self
.root_id
.clone
())
.get_name
(
None
,
None
);
let
mut
root_scope_name
=
String
::
from
(
"unknown"
);
if
let
Some
(
name
)
=
_
root_scope_name
{
root_scope_name
=
name
}
let
scope_list
=
ScopeListElement
::
new
(
None
,
root_scope_name
);
let
mut
state
=
StackElement
::
new
(
None
,
self
.root_id
.clone
(),
...
...
@@ -135,6 +143,8 @@ impl Grammar {
);
current_state
=
state
;
}
else
{
is_first_line
=
false
;
}
let
format_line_text
=
format!
(
"{:?}
\n
"
,
line_text
);
...
...
@@ -185,7 +195,7 @@ impl Grammar {
let
r
=
self
.match_rule
(
line_text
.clone
(),
is_first_line
,
line_pos
,
prev_state
,
anchor_position
);
if
let
None
=
r
{
_
stop
=
true
;
return
None
return
None
;
}
let
capture_result
=
r
.unwrap
();
...
...
scie-grammar/src/grammar/scope_list_element.rs
浏览文件 @
80ebad51
...
...
@@ -5,26 +5,26 @@ use std::collections::hash_map::RandomState;
pub
struct
ScopeListElement
{
pub
parent
:
Option
<
Box
<
ScopeListElement
>>
,
pub
scope
:
String
,
pub
metadata
:
i32
,
//
pub metadata: i32,
}
impl
ScopeListElement
{
pub
fn
new
(
parent
:
Option
<
Box
<
ScopeListElement
>>
,
scope
:
String
,
metadata
:
i32
)
->
Self
{
pub
fn
new
(
parent
:
Option
<
Box
<
ScopeListElement
>>
,
scope
:
String
)
->
Self
{
ScopeListElement
{
parent
,
scope
,
metadata
,
//
metadata,
}
}
pub
fn
generate_scopes
(
&
self
)
->
HashMap
<
i32
,
String
>
{
let
mut
result
=
HashMap
::
new
();
let
mut
result
L
en
=
0
;
let
mut
result
_l
en
=
0
;
let
mut
scope_list
=
self
.clone
();
let
mut
is_scope_list_none
=
false
;
while
!
is_scope_list_none
{
result
.insert
(
result
L
en
,
scope_list
.scope
.clone
());
result
.insert
(
result
_l
en
,
scope_list
.scope
.clone
());
match
scope_list
.parent
{
None
=>
{
is_scope_list_none
=
true
...
...
@@ -44,7 +44,7 @@ impl Default for ScopeListElement {
ScopeListElement
{
parent
:
None
,
scope
:
""
.to_string
(),
metadata
:
0
,
//
metadata: 0,
}
}
}
scie-grammar/src/rule/abstract_rule.rs
浏览文件 @
80ebad51
...
...
@@ -3,6 +3,7 @@ use crate::rule::{CompiledRule, RegExpSourceList, Rule};
use
core
::
fmt
;
use
dyn_clone
::{
clone_trait_object
,
DynClone
};
use
scie_scanner
::
scanner
::
scanner
::
IOnigCaptureIndex
;
use
crate
::
support
::
regex_source
::
RegexSource
;
pub
trait
AbstractRule
:
DynClone
+
erased_serde
::
Serialize
{
fn
id
(
&
self
)
->
i32
;
...
...
@@ -12,8 +13,17 @@ pub trait AbstractRule: DynClone + erased_serde::Serialize {
}
// todo: add support for this;
fn
get_rule
(
&
self
)
->
Rule
;
fn
get_name
(
&
self
,
line_text
:
Option
<
String
>
,
capture_indices
:
Option
<
Vec
<
IOnigCaptureIndex
>>
)
->
String
{
String
::
from
(
""
)
fn
get_name
(
&
self
,
line_text
:
Option
<
String
>
,
capture_indices
:
Option
<
Vec
<
IOnigCaptureIndex
>>
)
->
Option
<
String
>
{
let
name
=
self
.get_rule
()
._name
.clone
();
let
has_captures
=
RegexSource
::
has_captures
(
name
.clone
());
if
let
None
=
capture_indices
{
return
name
}
if
!
has_captures
||
name
==
None
||
line_text
==
None
{
return
name
}
return
Some
(
String
::
from
(
""
));
}
fn
has_missing_pattern
(
&
self
)
->
bool
{
false
...
...
scie-grammar/src/support/regex_source.rs
浏览文件 @
80ebad51
use
regex
::
Regex
;
use
scie_scanner
::
scanner
::
scanner
::
IOnigCaptureIndex
;
pub
struct
RegexSource
{}
...
...
@@ -10,13 +11,17 @@ impl RegexSource {
match
regex_source
{
None
=>
{
false
}
,
}
Some
(
source
)
=>
{
let
re
=
Regex
::
new
(
capturing_regex_source
)
.unwrap
();
re
.is_match
(
source
.as_str
())
}
,
}
}
}
pub
fn
replace_captures
(
regex_source
:
String
,
capture_source
:
String
,
capture_indices
:
Vec
<
IOnigCaptureIndex
>
)
->
String
{
String
::
from
(
""
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录