cbbd42d3f3
34913d5
broke the parser in the following case:
f = '\"'
This commit fixes that.
23 lines
No EOL
786 B
Haskell
23 lines
No EOL
786 B
Haskell
module Parse.Literal (literal) where
|
|
|
|
import Control.Applicative ((<$>), (<*>))
|
|
import Control.Monad
|
|
import Text.Parsec hiding (newline,spaces)
|
|
import Text.Parsec.Indent
|
|
|
|
import Parse.Helpers
|
|
import SourceSyntax.Literal
|
|
|
|
literal = num <|> (Str <$> str) <|> (Chr <$> chr)
|
|
|
|
num :: IParser Literal
|
|
num = fmap toLit (preNum <?> "number")
|
|
where toLit n | '.' `elem` n = FloatNum (read n)
|
|
| otherwise = IntNum (read n)
|
|
preNum = concat <$> sequence [ option "" minus, many1 digit, option "" postNum ]
|
|
postNum = do try $ lookAhead (string "." >> digit)
|
|
string "."
|
|
('.':) <$> many1 digit
|
|
minus = try $ do string "-"
|
|
lookAhead digit
|
|
return "-" |