Skip to content

Commit 23710ea

Browse files
committed
WIP draft
1 parent a28d4fc commit 23710ea

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

spago.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
, "math"
1313
, "maybe"
1414
, "newtype"
15+
, "numbers"
1516
, "prelude"
1617
, "strings"
1718
, "tailrec"

src/Text/Parsing/Parser/Token.purs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import Data.List (List(..))
3737
import Data.List as List
3838
import Data.List.NonEmpty (NonEmptyList)
3939
import Data.Maybe (Maybe(..), maybe)
40+
import Data.Number (fromString)
4041
import Data.String (CodePoint, null, toLower)
4142
import Data.String.CodePoints (codePointFromChar)
4243
import Data.String.CodeUnits (singleton, toChar) as CodeUnits
@@ -48,6 +49,7 @@ import Text.Parsing.Parser (ParseState(..), ParserT, consume, fail)
4849
import Text.Parsing.Parser.Combinators (between, choice, notFollowedBy, option, sepBy, sepBy1, skipMany, skipMany1, try, tryRethrow, (<?>), (<??>))
4950
import Text.Parsing.Parser.Pos (Position)
5051
import Text.Parsing.Parser.String (char, noneOf, oneOf, satisfy, satisfyCodePoint, string)
52+
import Text.Parsing.Parser.String as Parser.String
5153

5254
-- | A parser which returns the first token in the stream.
5355
token :: forall m a. Monad m => (a -> Position) -> ParserT (List a) m a
@@ -608,8 +610,14 @@ makeTokenParser (LanguageDef languageDef) =
608610
natural = lexeme nat <?> "natural"
609611

610612
-- floats
613+
611614
floating :: ParserT String m Number
612-
floating = decimal >>= fractExponent
615+
-- floating = decimal >>= fractExponent
616+
floating = do
617+
Tuple section _ <- Parser.String.match $ skipMany1 $ oneOf [ '-', '.', 'e', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ]
618+
case fromString section of
619+
Nothing -> fail $ "Could not parse Number " <> section
620+
Just x -> pure x
613621

614622
natFloat :: ParserT String m (Either Int Number)
615623
natFloat = char '0' *> zeroNumFloat

test/Main.purs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ tokenParserFloatTest = do
365365
-- parse float with exponent
366366
parseTest "100.5e1" 1005.0 testTokenParser.float
367367

368-
-- fail on nonfloat
369-
parseErrorTestPosition testTokenParser.float "100.e1" $ mkPos 5
368+
-- I don't agree that this is a non-float — jamesdbrock
369+
-- -- fail on nonfloat
370+
-- parseErrorTestPosition testTokenParser.float "100.e1" $ mkPos 5
370371

371372
-- I think ideally the float parser should round-trip with show.
372373
-- test from issue #73
@@ -375,6 +376,9 @@ tokenParserFloatTest = do
375376
-- test from issue #115
376377
parseTest "-6.0" (-6.0) testTokenParser.float
377378

379+
parseErrorTestPosition testTokenParser.float "NaN" (mkPos 1)
380+
parseErrorTestPosition testTokenParser.float "---" (mkPos 4)
381+
378382
-- TODO
379383
tokenParserNaturalOrFloatTest :: TestM
380384
tokenParserNaturalOrFloatTest = do

0 commit comments

Comments
 (0)