aboutsummaryrefslogtreecommitdiff
path: root/ProgramParser.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ProgramParser.hs')
-rw-r--r--ProgramParser.hs19
1 files changed, 14 insertions, 5 deletions
diff --git a/ProgramParser.hs b/ProgramParser.hs
index 34b5ce7..a71d07e 100644
--- a/ProgramParser.hs
+++ b/ProgramParser.hs
@@ -204,30 +204,39 @@ pENew = do
return $ ENew t e
pLiteral :: Parser Literal
-pLiteral = (LInt <$> pInteger) <|> (LChar <$> pCharLit) <|> pLCall <|> (LVar <$> pName)
+pLiteral =
+ (LInt <$> pInteger) <|> (LChar <$> pCharLit) <|> (LStr <$> pString) <|>
+ pLCall <|> (LVar <$> pName)
pCharLit :: Parser Char
pCharLit = do
void $ char '\''
- c <- pStringChar
+ c <- pStringChar (const False)
void $ char '\''
pWhiteComment
return c
-pStringChar :: Parser Char
-pStringChar =
+pStringChar :: (Char -> Bool) -> Parser Char
+pStringChar avoid =
(char '\\' >> ((char 'n' >> return '\n') <|>
(char 'r' >> return '\r') <|>
(char 't' >> return '\t') <|>
(char '0' >> return '\0') <|>
(char 'x' >> pHexDigit >>= \a -> pHexDigit >>= \b -> return (chr $ 16 * a + b)))) <|>
- anyToken
+ satisfy (not . avoid)
where
pHexDigit :: Parser Int
pHexDigit = (subtract 48 . fromEnum <$> digit)
<|> ((+ (10 - 97)) . ord <$> oneOf "abcdef")
<|> ((+ (10 - 65)) . ord <$> oneOf "ABCDEF")
+pString :: Parser String
+pString = do
+ void $ char '"'
+ s <- many (pStringChar (== '"'))
+ void $ char '"'
+ return s
+
pLCall :: Parser Literal
pLCall = do
n <- try $ pName <* symbol "("