From da51b14789026b20da4c76990439908ef8462106 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 14 Dec 2013 15:20:15 -0800 Subject: [PATCH] Parser: accept here doc token strings more liberally --- ShellCheck/Parser.hs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index 832ba62..8c9d9f2 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -1009,9 +1009,9 @@ prop_readHereDoc = isOk readHereDoc "<< foo\nlol\ncow\nfoo" prop_readHereDoc2 = isWarning readHereDoc "<<- EOF\n cow\n EOF" prop_readHereDoc3 = isOk readHereDoc "<< foo\n$\"\nfoo" prop_readHereDoc4 = isOk readHereDoc "<< foo\n`\nfoo" +prop_readHereDoc5 = isOk readHereDoc "<<- !foo\nbar\n!foo" +prop_readHereDoc6 = isOk readHereDoc "<< foo\\ bar\ncow\nfoo bar" readHereDoc = called "here document" $ do - let stripLiteral (T_Literal _ x) = x - stripLiteral (T_SingleQuoted _ x) = x fid <- getNextId pos <- getPosition try $ string "<<" @@ -1023,9 +1023,10 @@ readHereDoc = called "here document" $ do let message = "Shells are space sensitive. Use '< <(cmd)', not '<<" ++ sp ++ "(cmd)'." parseProblemAt pos ErrorC 1038 message hid <- getNextId - (quoted, endToken) <- (readNormalLiteral "" >>= (\x -> return (Unquoted, stripLiteral x)) ) - <|> (readDoubleQuotedLiteral >>= return . (\x -> (Quoted, stripLiteral x))) - <|> (readSingleQuotedLiteral >>= return . (\x -> (Quoted, x))) + (quoted, endToken) <- + (readDoubleQuotedLiteral >>= return . (\x -> (Quoted, stripLiteral x))) + <|> (readSingleQuotedLiteral >>= return . (\x -> (Quoted, x))) + <|> (readToken >>= (\x -> return (Unquoted, x))) spacing startPos <- getPosition @@ -1045,6 +1046,19 @@ readHereDoc = called "here document" $ do `attempting` (eof >> debugHereDoc tokenPosition endToken hereData) where + stripLiteral (T_Literal _ x) = x + stripLiteral (T_SingleQuoted _ x) = x + + readToken = do + liftM concat $ many1 (escaped <|> quoted <|> normal) + where + quoted = liftM stripLiteral readDoubleQuotedLiteral <|> readSingleQuotedLiteral + normal = anyChar `reluctantlyTill1` (whitespace <|> oneOf ";&)'\"\\") + escaped = do -- surely the user must be doing something wrong at this point + char '\\' + c <- anyChar + return [c] + parseHereData Quoted startPos hereData = do id <- getNextIdAt startPos return $ [T_Literal id hereData]