From e84d5abc3e142208597d203b5490e40deb5a10bd Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 10 Jul 2013 23:47:25 -0700 Subject: [PATCH] Support for recursive regex groups --- ShellCheck/Parser.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index 3c7dcc6..ebbbf8f 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -341,7 +341,7 @@ readConditionContents single = do try (string "=~") <|> try (string "~=") return True) <|> return False - readRegex = called "regex" $ do + readRegex = called "regex" $ do id <- getNextId parts <- many1 (readGroup <|> readSingleQuoted <|> readDoubleQuoted <|> readDollarExpression <|> readNormalLiteral "( " <|> readGlobLiteral) disregard spacing @@ -351,12 +351,16 @@ readConditionContents single = do id <- getNextId s <- many1 (extglobStart <|> oneOf "[]$") return $ T_Literal id s - readGroup = do -- Fixme: account for vars and quotes in groups + readGroup = called "regex grouping" $ do id <- getNextId char '(' - s <- readGenericLiteral (char ')') + parts <- many (readGroup <|> readSingleQuoted <|> readDoubleQuoted <|> readDollarExpression <|> readRegexLiteral <|> readGlobLiteral) char ')' - return $ T_Literal id $ "(" ++ s ++ ")" + return $ T_NormalWord id parts + readRegexLiteral = do + id <- getNextId + str <- readGenericLiteral1 (singleQuote <|> doubleQuotable <|> oneOf "()") + return $ T_Literal id str readCondTerm = readCondNot <|> readCondExpr readCondNot = do @@ -549,6 +553,8 @@ prop_readCondition2 = isOk readCondition "[[ (a = b) || (c = d) ]]" prop_readCondition3 = isOk readCondition "[[ $c = [[:alpha:].~-] ]]" prop_readCondition4 = isOk readCondition "[[ $c =~ *foo* ]]" prop_readCondition5 = isOk readCondition "[[ $c =~ f( ]] )* ]]" +prop_readCondition5a= isOk readCondition "[[ $c =~ a(b) ]]" +prop_readCondition5b= isOk readCondition "[[ $c =~ f( ($var ]]) )* ]]" prop_readCondition6 = isOk readCondition "[[ $c =~ ^[yY]$ ]]" prop_readCondition7 = isOk readCondition "[[ ${line} =~ ^[[:space:]]*# ]]" readCondition = called "test expression" $ do