git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Parse signed numeric literals
commit21032e9b3faefa210daba1ef7810f223e7ca6ca7 authorGary Burgess <gary.burgess@gmail.com> dateTue 25 Mar 2014, 10:32 (13 years ago) parenta165722
1 file changed+8−2
src/Language/PureScript/Parser/Common.hs+8−2
src/Language/PureScript/Parser/Common.hs+8−2
@@ -227,8 +227,14 @@ parseQualified parser = part []
227227-- Parse an integer or floating point value
228228--
229229integerOrFloat :: P.Parsec String u (Either Integer Double)
230−integerOrFloat = (Right <$> P.try (PT.float tokenParser) <|>
231− Left <$> P.try (PT.natural tokenParser)) P.<?> "number"
230+integerOrFloat = (Right <$> P.try (signed PT.float) <|>
231+ Left <$> P.try (signed PT.natural)) P.<?> "number"
232+ where
233+ signed p = do
234+ let sign = (P.char '-' >> return negate) <|> (optional (P.char '+') >> return id)
235+ f <- sign
236+ n <- p tokenParser
237+ return (f n)
232238
233239-- |
234240-- Parse an identifier or parenthesized operator