Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
6c31008a
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6c31008a
编写于
7月 20, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more prep for #17545
上级
1e9ca905
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
90 addition
and
36 deletion
+90
-36
src/vs/editor/contrib/snippet/browser/snippetParser.ts
src/vs/editor/contrib/snippet/browser/snippetParser.ts
+90
-36
未找到文件。
src/vs/editor/contrib/snippet/browser/snippetParser.ts
浏览文件 @
6c31008a
...
...
@@ -68,14 +68,6 @@ export class Scanner {
return
this
.
value
.
substr
(
token
.
pos
,
token
.
len
);
}
// anchor() {
// const pos = this.pos;
// return {
// reset: () => this.pos = pos,
// text: () => this.value.substring(pos, this.pos)
// };
// }
next
():
Token
{
if
(
this
.
pos
>=
this
.
value
.
length
)
{
...
...
@@ -440,12 +432,21 @@ export class SnippetParser {
return
false
;
}
private
_backTo
(
token
:
Token
):
false
{
this
.
_scanner
.
pos
=
token
.
pos
+
token
.
len
;
this
.
_token
=
token
;
return
false
;
}
private
_parse
(
marker
:
Marker
):
boolean
{
return
this
.
_parseEscaped
(
marker
)
||
this
.
_parsePlaceholderOrVariable
(
marker
)
||
this
.
_parseTabstopOrVariableName
(
marker
)
||
this
.
_parseComplexPlaceholder
(
marker
)
||
this
.
_parseComplexVariable
(
marker
)
||
this
.
_parseAnything
(
marker
);
}
// \$, \\, \} -> just text
private
_parseEscaped
(
marker
:
Marker
):
boolean
{
let
value
:
string
;
if
(
value
=
this
.
_accept
(
TokenType
.
Backslash
,
true
))
{
...
...
@@ -461,58 +462,111 @@ export class SnippetParser {
return
false
;
}
private
_parsePlaceholderOrVariable
(
marker
:
Marker
):
boolean
{
// $foo -> variable, $1 -> tabstop
private
_parseTabstopOrVariableName
(
parent
:
Marker
):
boolean
{
let
value
:
string
;
const
token
=
this
.
_token
;
const
match
=
this
.
_accept
(
TokenType
.
Dollar
)
&&
(
value
=
this
.
_accept
(
TokenType
.
VariableName
,
true
)
||
this
.
_accept
(
TokenType
.
Int
,
true
));
if
(
!
this
.
_accept
(
TokenType
.
Dollar
)
)
{
return
false
;
if
(
!
match
)
{
return
this
.
_backTo
(
token
)
;
}
let
value
=
this
.
_accept
(
TokenType
.
VariableName
,
true
)
||
this
.
_accept
(
TokenType
.
Int
,
true
);
parent
.
appendChild
(
/^
\d
+$/
.
test
(
value
)
?
new
Placeholder
(
Number
(
value
))
:
new
Variable
(
value
)
);
return
true
;
}
if
(
value
)
{
// $foo -> variable, $1 -> tabstop
marker
.
appendChild
(
/^
\d
+$/
.
test
(
value
)
?
new
Placeholder
(
Number
(
value
))
:
new
Variable
(
value
));
return
true
;
// ${1:<children>}, ${1} -> placeholder
private
_parseComplexPlaceholder
(
parent
:
Marker
):
boolean
{
let
index
:
string
;
const
token
=
this
.
_token
;
const
match
=
this
.
_accept
(
TokenType
.
Dollar
)
&&
this
.
_accept
(
TokenType
.
CurlyOpen
)
&&
(
index
=
this
.
_accept
(
TokenType
.
Int
,
true
));
}
else
if
(
this
.
_accept
(
TokenType
.
CurlyOpen
))
{
// ${foo:<children>}, ${foo}, ${1:<children>}, ${1}
if
(
!
match
)
{
return
this
.
_backTo
(
token
);
}
value
=
this
.
_accept
(
TokenType
.
VariableName
,
true
)
||
this
.
_accept
(
TokenType
.
Int
,
true
);
const
variable
=
new
Placeholder
(
Number
(
index
));
if
(
this
.
_accept
(
TokenType
.
Colon
))
{
// ${1:<children>}
while
(
true
)
{
// ...} -> done
if
(
this
.
_accept
(
TokenType
.
CurlyClose
))
{
parent
.
appendChild
(
variable
);
return
true
;
}
if
(
this
.
_parse
(
variable
))
{
continue
;
}
if
(
!
value
)
{
marker
.
appendChild
(
new
Text
(
'
${
'
));
// fallback
parent
.
appendChild
(
new
Text
(
'
${
'
+
index
+
'
:
'
));
variable
.
children
.
forEach
(
parent
.
appendChild
,
parent
);
return
true
;
}
let
placeholderOrVariable
=
/^
\d
+$/
.
test
(
value
)
?
new
Placeholder
(
Number
(
value
))
:
new
Variable
(
value
);
}
else
if
(
this
.
_accept
(
TokenType
.
CurlyClose
))
{
// ${1}
parent
.
appendChild
(
variable
);
return
true
;
}
else
{
// ${1 <- missing curly or colon
return
this
.
_backTo
(
token
);
}
}
// ${foo:<children>}, ${foo} -> variable
private
_parseComplexVariable
(
parent
:
Marker
):
boolean
{
let
name
:
string
;
const
token
=
this
.
_token
;
const
match
=
this
.
_accept
(
TokenType
.
Dollar
)
&&
this
.
_accept
(
TokenType
.
CurlyOpen
)
&&
(
name
=
this
.
_accept
(
TokenType
.
VariableName
,
true
));
if
(
!
match
)
{
return
this
.
_backTo
(
token
);
}
const
variable
=
new
Variable
(
name
);
if
(
this
.
_accept
(
TokenType
.
Colon
))
{
// ${foo:<children>}
while
(
true
)
{
// ...} -> done
if
(
this
.
_accept
(
TokenType
.
CurlyClose
))
{
marker
.
appendChild
(
placeholderOrVariable
);
return
true
;
}
if
(
placeholderOrVariable
.
children
.
length
===
0
&&
!
this
.
_accept
(
TokenType
.
Colon
))
{
marker
.
appendChild
(
new
Text
(
'
${
'
+
value
));
parent
.
appendChild
(
variable
);
return
true
;
}
if
(
this
.
_parse
(
placeholderOrV
ariable
))
{
if
(
this
.
_parse
(
v
ariable
))
{
continue
;
}
// fallback
marker
.
appendChild
(
new
Text
(
'
${
'
+
valu
e
+
'
:
'
));
placeholderOrVariable
.
children
.
forEach
(
marker
.
appendChild
,
marker
);
parent
.
appendChild
(
new
Text
(
'
${
'
+
nam
e
+
'
:
'
));
variable
.
children
.
forEach
(
parent
.
appendChild
,
parent
);
return
true
;
}
}
else
{
marker
.
appendChild
(
new
Text
(
'
$
'
));
}
else
if
(
this
.
_accept
(
TokenType
.
CurlyClose
))
{
// ${foo}
parent
.
appendChild
(
variable
);
return
true
;
}
else
{
// ${foo <- missing curly or colon
return
this
.
_backTo
(
token
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录