Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Annlix
ShellCheck
提交
ca37794b
S
ShellCheck
项目概览
Annlix
/
ShellCheck
与 Fork 源项目一致
Fork自
镜像 / koalaman / ShellCheck
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
ShellCheck
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ca37794b
编写于
6月 14, 2015
作者:
V
Vidar Holen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow empty scripts, $()s and <()s. Also improves related error messages.
上级
8b8b48ef
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
18 deletion
+36
-18
ShellCheck/Parser.hs
ShellCheck/Parser.hs
+36
-18
未找到文件。
ShellCheck/Parser.hs
浏览文件 @
ca37794b
...
...
@@ -771,14 +771,14 @@ readDollarBracedLiteral = do
prop_readProcSub1
=
isOk
readProcSub
"<(echo test | wc -l)"
prop_readProcSub2
=
isOk
readProcSub
"<( if true; then true; fi )"
prop_readProcSub3
=
isOk
readProcSub
"<( # nothing here
\n
)"
readProcSub
=
called
"process substitution"
$
do
id
<-
getNextId
dir
<-
try
$
do
x
<-
oneOf
"<>"
char
'('
return
[
x
]
allspacing
list
<-
readCompoundList
list
<-
readCompoundListOrEmpty
allspacing
char
')'
return
$
T_ProcSub
id
dir
list
...
...
@@ -843,19 +843,23 @@ readBackTicked = called "backtick expansion" $ do
suggestForgotClosingQuote
startPos
endPos
"backtick expansion"
-- Result positions may be off due to escapes
result
<-
subParse
subStart
readTermOrNone
(
unEscape
subString
)
result
<-
subParse
subStart
subParser
(
unEscape
subString
)
return
$
T_Backticked
id
result
where
unEscape
[]
=
[]
unEscape
(
'
\\
'
:
x
:
rest
)
|
x
`
elem
`
"$`
\\
"
=
x
:
unEscape
rest
unEscape
(
'
\\
'
:
'
\n
'
:
rest
)
=
unEscape
rest
unEscape
(
c
:
rest
)
=
c
:
unEscape
rest
subParser
=
do
cmds
<-
readCompoundListOrEmpty
verifyEof
return
cmds
backtick
=
disregard
(
char
'`'
)
<|>
do
pos
<-
getPosition
char
'´'
parseProblemAt
pos
ErrorC
1077
"For command expansion, the tick should slant left (` vs ´)."
"For command expansion, the tick should slant left (` vs ´).
Use $(..) instead.
"
subParse
pos
parser
input
=
do
lastPosition
<-
getPosition
...
...
@@ -1132,11 +1136,13 @@ readDollarBraced = called "parameter expansion" $ do
char
'}'
return
$
T_DollarBraced
id
word
prop_readDollarExpansion
=
isOk
readDollarExpansion
"$(echo foo; ls
\n
)"
prop_readDollarExpansion1
=
isOk
readDollarExpansion
"$(echo foo; ls
\n
)"
prop_readDollarExpansion2
=
isOk
readDollarExpansion
"$( )"
prop_readDollarExpansion3
=
isOk
readDollarExpansion
"$( command
\n
#comment
\n
)"
readDollarExpansion
=
called
"command expansion"
$
do
id
<-
getNextId
try
(
string
"$("
)
cmds
<-
readCompoundList
cmds
<-
readCompoundList
OrEmpty
char
')'
<?>
"end of $(..) expression"
return
$
T_DollarExpansion
id
cmds
...
...
@@ -1845,6 +1851,9 @@ readCompoundCommand = do
readCompoundList
=
readTerm
readCompoundListOrEmpty
=
do
allspacing
readTerm
<|>
return
[]
readCmdPrefix
=
many1
(
readIoRedirect
<|>
readAssignmentWord
)
readCmdSuffix
=
many1
(
readIoRedirect
<|>
readCmdWord
)
...
...
@@ -2048,10 +2057,25 @@ readShebang = do
parseProblemAt
pos
ErrorC
1084
"Use #!, not !#, for the shebang."
verifyEof
=
eof
<|>
choice
[
ifParsable
g_Lparen
$
parseProblem
ErrorC
1088
"Parsing stopped here. Invalid use of parentheses?"
,
ifParsable
readKeyword
$
parseProblem
ErrorC
1089
"Parsing stopped here. Is this keyword correctly matched up?"
,
parseProblem
ErrorC
1070
"Parsing stopped here. Mismatched keywords or invalid parentheses?"
]
where
ifParsable
p
action
=
do
try
(
lookAhead
p
)
action
prop_readScript1
=
isOk
readScript
"#!/bin/bash
\n
echo hello world
\n
"
prop_readScript2
=
isWarning
readScript
"#!/bin/bash
\r\n
echo hello world
\n
"
prop_readScript3
=
isWarning
readScript
"#!/bin/bash
\n
echo hello
\xA0
world"
prop_readScript4
=
isWarning
readScript
"#!/usr/bin/perl
\n
foo=("
prop_readScript5
=
isOk
readScript
"#!/bin/bash
\n
#This is an empty script
\n\n
"
readScript
=
do
id
<-
getNextId
pos
<-
getPosition
...
...
@@ -2062,19 +2086,13 @@ readScript = do
sb
<-
option
""
readShebang
verifyShell
pos
(
getShell
sb
)
if
isValidShell
(
getShell
sb
)
/=
Just
False
then
do
{
allspacing
;
commands
<-
readTerm
;
eof
<|>
parseProblem
ErrorC
1070
"Parsing stopped here because of parsing errors."
;
return
$
T_Script
id
sb
commands
;
}
<|>
do
{
parseProblem
WarningC
1014
"Couldn't read any commands."
;
then
do
commands
<-
readCompoundListOrEmpty
verifyEof
return
$
T_Script
id
sb
commands
else
do
many
anyChar
return
$
T_Script
id
sb
[]
}
else
do
many
anyChar
return
$
T_Script
id
sb
[]
;
where
basename
s
=
reverse
.
takeWhile
(
/=
'/'
)
.
reverse
$
s
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录