Added extglob support that actually works

This commit is contained in:
Vidar Holen 2012-11-19 23:20:01 -08:00
parent 5100bc0989
commit 807ecbd038
1 changed files with 11 additions and 7 deletions

View File

@ -47,6 +47,7 @@ quotable = oneOf "#|&;<>()$`\\ \"'\t\n"
doubleQuotable = oneOf "\"$`" doubleQuotable = oneOf "\"$`"
whitespace = oneOf " \t\n" whitespace = oneOf " \t\n"
linewhitespace = oneOf " \t" linewhitespace = oneOf " \t"
extglobStart = oneOf "?*@!+"
prop_spacing = isOk spacing " \\\n # Comment" prop_spacing = isOk spacing " \\\n # Comment"
spacing = do spacing = do
@ -445,6 +446,7 @@ readComment = do
anyChar `reluctantlyTill` linefeed anyChar `reluctantlyTill` linefeed
prop_readNormalWord = isOk readNormalWord "'foo'\"bar\"{1..3}baz$(lol)" prop_readNormalWord = isOk readNormalWord "'foo'\"bar\"{1..3}baz$(lol)"
prop_readNormalWord2 = isOk readNormalWord "foo**(foo)!!!(@@(bar))"
readNormalWord = do readNormalWord = do
id <- getNextId id <- getNextId
x <- many1 readNormalWordPart x <- many1 readNormalWordPart
@ -523,7 +525,7 @@ readNormalLiteral = do
return $ T_Literal id (concat s) return $ T_Literal id (concat s)
readNormalLiteralPart = do readNormalLiteralPart = do
readNormalEscaped <|> (anyChar `reluctantlyTill1` quotable) readNormalEscaped <|> (anyChar `reluctantlyTill1` (quotable <|> extglobStart))
readNormalEscaped = do readNormalEscaped = do
pos <- getPosition pos <- getPosition
@ -542,13 +544,15 @@ prop_readExtglob1 = isOk readExtglob "!(*.mp3)"
prop_readExtglob2 = isOk readExtglob "!(*.mp3|*.wmv)" prop_readExtglob2 = isOk readExtglob "!(*.mp3|*.wmv)"
prop_readExtglob4 = isOk readExtglob "+(foo \\) bar)" prop_readExtglob4 = isOk readExtglob "+(foo \\) bar)"
prop_readExtglob5 = isOk readExtglob "+(!(foo *(bar)))" prop_readExtglob5 = isOk readExtglob "+(!(foo *(bar)))"
readExtglob = try $ do readExtglob = do
id <- getNextId id <- getNextId
c <- oneOf "?*@!+" c <- extglobStart
( try $ do
char '(' char '('
contents <- readExtglobPart `sepBy` (char '|') contents <- readExtglobPart `sepBy` (char '|')
char ')' char ')'
return $ T_Extglob id [c] contents return $ T_Extglob id [c] contents
) <|> (return $ T_Literal id [c])
readExtglobPart = do readExtglobPart = do
id <- getNextId id <- getNextId