From 807ecbd038384667629e598f1f810471dceb836b Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 19 Nov 2012 23:20:01 -0800 Subject: [PATCH] Added extglob support that actually works --- ShellCheck/Parser.hs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index d555dbb..1d35a4b 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -47,6 +47,7 @@ quotable = oneOf "#|&;<>()$`\\ \"'\t\n" doubleQuotable = oneOf "\"$`" whitespace = oneOf " \t\n" linewhitespace = oneOf " \t" +extglobStart = oneOf "?*@!+" prop_spacing = isOk spacing " \\\n # Comment" spacing = do @@ -445,6 +446,7 @@ readComment = do anyChar `reluctantlyTill` linefeed prop_readNormalWord = isOk readNormalWord "'foo'\"bar\"{1..3}baz$(lol)" +prop_readNormalWord2 = isOk readNormalWord "foo**(foo)!!!(@@(bar))" readNormalWord = do id <- getNextId x <- many1 readNormalWordPart @@ -523,7 +525,7 @@ readNormalLiteral = do return $ T_Literal id (concat s) readNormalLiteralPart = do - readNormalEscaped <|> (anyChar `reluctantlyTill1` quotable) + readNormalEscaped <|> (anyChar `reluctantlyTill1` (quotable <|> extglobStart)) readNormalEscaped = do pos <- getPosition @@ -542,13 +544,15 @@ prop_readExtglob1 = isOk readExtglob "!(*.mp3)" prop_readExtglob2 = isOk readExtglob "!(*.mp3|*.wmv)" prop_readExtglob4 = isOk readExtglob "+(foo \\) bar)" prop_readExtglob5 = isOk readExtglob "+(!(foo *(bar)))" -readExtglob = try $ do +readExtglob = do id <- getNextId - c <- oneOf "?*@!+" - char '(' - contents <- readExtglobPart `sepBy` (char '|') - char ')' - return $ T_Extglob id [c] contents + c <- extglobStart + ( try $ do + char '(' + contents <- readExtglobPart `sepBy` (char '|') + char ')' + return $ T_Extglob id [c] contents + ) <|> (return $ T_Literal id [c]) readExtglobPart = do id <- getNextId