Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Annlix
ShellCheck
提交
6e263e6b
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,发现更多精彩内容 >>
提交
6e263e6b
编写于
12月 02, 2012
作者:
V
Vidar Holen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Parsing support for array indices in assignments.
上级
b765ed1a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
13 deletion
+22
-13
ShellCheck/Parser.hs
ShellCheck/Parser.hs
+22
-13
未找到文件。
ShellCheck/Parser.hs
浏览文件 @
6e263e6b
...
...
@@ -494,22 +494,22 @@ readComment = do
prop_readNormalWord
=
isOk
readNormalWord
"'foo'
\"
bar
\"
{1..3}baz$(lol)"
prop_readNormalWord2
=
isOk
readNormalWord
"foo**(foo)!!!(@@(bar))"
readNormalWord
=
do
readNormalWord
=
readNormalishWord
""
readNormalishWord
end
=
do
id
<-
getNextId
pos
<-
getPosition
x
<-
many1
readNormalWordPart
x
<-
many1
(
readNormalWordPart
end
)
checkPossibleTermination
pos
x
return
$
T_NormalWord
id
x
checkPossibleTermination
pos
[
T_Literal
_
x
]
=
if
x
`
elem
`
[
"do"
,
"done"
,
"then"
,
"fi"
,
"esac"
,
"}"
]
then
parseProblemAt
pos
WarningC
$
"Use semicolon or linefeed before '"
++
x
++
"' (or quote to make it literal)."
else
return
()
checkPossibleTermination
_
_
=
return
()
readNormalWordPart
=
readSingleQuoted
<|>
readDoubleQuoted
<|>
readGlob
<|>
readDollar
<|>
readBraced
<|>
readBackTicked
<|>
readProcSub
<|>
readNormalLiteral
readNormalWordPart
end
=
readSingleQuoted
<|>
readDoubleQuoted
<|>
readGlob
<|>
readDollar
<|>
readBraced
<|>
readBackTicked
<|>
readProcSub
<|>
(
readNormalLiteral
end
)
readSpacePart
=
do
id
<-
getNextId
x
<-
many1
whitespace
...
...
@@ -601,10 +601,9 @@ readDoubleLiteralPart = do
x
<-
(
readDoubleEscaped
<|>
(
anyChar
>>=
\
x
->
return
[
x
]))
`
reluctantlyTill1
`
doubleQuotable
return
$
concat
x
prop_readNormalLiteral
=
isOk
readNormalLiteral
"hello
\\
world"
readNormalLiteral
=
do
readNormalLiteral
end
=
do
id
<-
getNextId
s
<-
many1
readNormalLiteralPart
s
<-
many1
(
readNormalLiteralPart
end
)
return
$
T_Literal
id
(
concat
s
)
prop_readGlob1
=
isOk
readGlob
"*"
...
...
@@ -628,8 +627,8 @@ readGlob = readExtglob <|> readSimple <|> readClass <|> readGlobbyLiteral
c
<-
extglobStart
<|>
char
'['
return
$
T_Literal
id
[
c
]
readNormalLiteralPart
=
do
readNormalEscaped
<|>
(
anyChar
`
reluctantlyTill1
`
(
quotable
<|>
extglobStart
<|>
char
'['
))
readNormalLiteralPart
end
=
do
readNormalEscaped
<|>
(
anyChar
`
reluctantlyTill1
`
(
quotable
<|>
extglobStart
<|>
char
'['
<|>
oneOf
end
))
readNormalEscaped
=
called
"escaped char"
$
do
pos
<-
getPosition
...
...
@@ -660,7 +659,7 @@ readExtglob = called "extglob" $ do
readExtglobPart
=
do
id
<-
getNextId
x
<-
many1
(
readNormalWordPart
<|>
readSpacePart
)
x
<-
many1
(
readNormalWordPart
""
<|>
readSpacePart
)
return
$
T_NormalWord
id
x
...
...
@@ -826,7 +825,7 @@ readHereDoc = called "here document" $ do
let
message
=
"Shells are space sensitive. Use '< <(cmd)', not '<<"
++
sp
++
"(cmd)'."
parseProblemAt
pos
ErrorC
message
hid
<-
getNextId
(
quoted
,
endToken
)
<-
(
readNormalLiteral
>>=
(
\
x
->
return
(
False
,
stripLiteral
x
))
)
(
quoted
,
endToken
)
<-
(
readNormalLiteral
""
>>=
(
\
x
->
return
(
False
,
stripLiteral
x
))
)
<|>
(
readDoubleQuotedLiteral
>>=
return
.
(
\
x
->
(
True
,
stripLiteral
x
)))
<|>
(
readSingleQuotedLiteral
>>=
return
.
(
\
x
->
(
True
,
x
)))
spacing
...
...
@@ -1254,10 +1253,13 @@ prop_readAssignmentWord3 = isWarning readAssignmentWord "$b = 13"
prop_readAssignmentWord4
=
isWarning
readAssignmentWord
"b = $(lol)"
prop_readAssignmentWord5
=
isOk
readAssignmentWord
"b+=lol"
prop_readAssignmentWord6
=
isWarning
readAssignmentWord
"b += (1 2 3)"
prop_readAssignmentWord7
=
isOk
readAssignmentWord
"a[3$n'']=42"
prop_readAssignmentWord8
=
isOk
readAssignmentWord
"a[4''$(cat foo)]=42"
readAssignmentWord
=
try
$
do
id
<-
getNextId
optional
(
char
'$'
>>
parseNote
ErrorC
"Don't use $ on the left side of assignments."
)
variable
<-
readVariableName
optional
readArrayIndex
-- Throws away the index. Fixme?
space
<-
spacing
pos
<-
getPosition
op
<-
string
"+="
<|>
string
"="
-- analysis doesn't treat += as a reference. fixme?
...
...
@@ -1268,6 +1270,14 @@ readAssignmentWord = try $ do
when
(
space
==
""
&&
space2
/=
""
)
$
parseNoteAt
pos
StyleC
"Use var='' if you intended to assign the empty string."
return
$
T_Assignment
id
variable
value
-- This is only approximate. Fixme?
readArrayIndex
=
do
char
'['
optional
space
x
<-
readNormalishWord
"]"
optional
space
char
']'
readArray
=
called
"array assignment"
$
do
id
<-
getNextId
char
'('
...
...
@@ -1276,7 +1286,6 @@ readArray = called "array assignment" $ do
char
')'
return
$
T_Array
id
words
tryToken
s
t
=
try
$
do
id
<-
getNextId
string
s
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录