aboutsummaryrefslogtreecommitdiff
path: root/ProgramParser.hs
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-08-27 20:34:57 +0200
committertomsmeding <tom.smeding@gmail.com>2017-08-27 20:34:57 +0200
commitc129641b18156b463cd12318ba956c85a9017e39 (patch)
tree1b17cfa6b009db854380c983b7ea9a00507b9513 /ProgramParser.hs
parentaa049227c17f15ad22092f1fcab4410bbf3521ba (diff)
Tenth
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 "("