From b4fb4391918a0dd24e1fd5ee9b5ed5993bb496b2 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 3 Dec 2016 10:19:14 -0800 Subject: [PATCH] Save string read by T_ParamSubSpecialChar --- ShellCheck/AST.hs | 4 ++-- ShellCheck/ASTLib.hs | 2 ++ ShellCheck/Parser.hs | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ShellCheck/AST.hs b/ShellCheck/AST.hs index 39dfff2..37942b9 100644 --- a/ShellCheck/AST.hs +++ b/ShellCheck/AST.hs @@ -111,7 +111,7 @@ data Token = | T_NormalWord Id [Token] | T_OR_IF Id | T_OrIf Id (Token) (Token) - | T_ParamSubSpecialChar Id -- e.g. '%' in ${foo%bar} or '/' in ${foo/bar/baz} + | T_ParamSubSpecialChar Id String -- e.g. '%' in ${foo%bar} or '/' in ${foo/bar/baz} | T_Pipeline Id [Token] [Token] -- [Pipe separators] [Commands] | T_ProcSub Id String [Token] | T_Rbrace Id @@ -320,7 +320,7 @@ getId t = case t of T_DollarBraced id _ -> id T_DollarArithmetic id _ -> id T_BraceExpansion id _ -> id - T_ParamSubSpecialChar id -> id + T_ParamSubSpecialChar id _ -> id T_DollarBraceCommandExpansion id _ -> id T_IoFile id _ _ -> id T_IoDuplicate id _ _ -> id diff --git a/ShellCheck/ASTLib.hs b/ShellCheck/ASTLib.hs index e4fdf93..6e60618 100644 --- a/ShellCheck/ASTLib.hs +++ b/ShellCheck/ASTLib.hs @@ -86,6 +86,7 @@ oversimplify token = (T_Glob _ s) -> [s] (T_Pipeline _ _ [x]) -> oversimplify x (T_Literal _ x) -> [x] + (T_ParamSubSpecialChar _ x) -> [x] (T_SimpleCommand _ vars words) -> concatMap oversimplify words (T_Redirecting _ _ foo) -> oversimplify foo (T_DollarSingleQuoted _ s) -> [s] @@ -188,6 +189,7 @@ getLiteralStringExt more = g g (TA_Expansion _ l) = allInList l g (T_SingleQuoted _ s) = return s g (T_Literal _ s) = return s + g (T_ParamSubSpecialChar _ s) = return s g x = more x -- Is this token a string literal? diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index d04c87d..f887c9d 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -1015,8 +1015,7 @@ readDollarBracedLiteral = do readParamSubSpecialChar = do id <- getNextId - many1 paramSubSpecialChars - return $ T_ParamSubSpecialChar id + T_ParamSubSpecialChar id <$> many1 paramSubSpecialChars prop_readProcSub1 = isOk readProcSub "<(echo test | wc -l)" prop_readProcSub2 = isOk readProcSub "<( if true; then true; fi )"