Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Correctly parse quoted here-doc delimeters
Browse files Browse the repository at this point in the history
  • Loading branch information
UnkindPartition committed Jun 15, 2010
1 parent efb92e6 commit ff34eef
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ redirection = do
mbFd <- optionMaybe number
op <- redirOp
-- fixme: if op is HereDoc, we should parse w differently
w <- token_word
w <- case op of
HereDoc {} -> hereDocDelim
_ -> token_word

let fd = case mbFd of
Just fd -> fd
Expand All @@ -261,7 +263,28 @@ redirection = do
unquote1 (SQuoted s) = s
unquote1 (DQuoted w) = unquote w
unquote1 (Escaped c) = [c]
unquote1 _ = error "This type of here-doc delimeter is not yet supported"
unquote1 x = error $ "Got unexpected thingy in here-doc delimeter: " ++ show x
hereDocDelim = token $ many1 $
escaped <|> singleQuoted <|> doubleQuoted <|> bareWord "'\"\\\n# "
doubleQuoted :: Parser WordPart
doubleQuoted = do
dQuote
parts <- many $ escaped <|> bare_word
dQuote
return $ DQuoted parts
where
dQuote = char '"'
escapables = "$`\"\\\n"
escaped = try $ do
char '\\'
Escaped <$> oneOf escapables
bare_word = do
w <- many1 ordinary_symbol
return $ Bare w
where
ordinary_symbol = noneOf "\\\"" <|>
do char '\\'; lookAhead (noneOf escapables); return '\\'


assignment = do
var <- name
Expand Down

0 comments on commit ff34eef

Please sign in to comment.