Tokenize number parser

The essential change hidden behind the code golfing is using the `tok`
combinator. This was making fail the Kitchen Sink test.
This commit is contained in:
Danny Navarro 2016-12-18 12:19:59 -03:00
parent aa66236081
commit 933cfd2852
No known key found for this signature in database
GPG Key ID: 81E5F99780FA6A32
2 changed files with 3 additions and 10 deletions

View File

@ -148,7 +148,8 @@ typeCondition = namedType
-- explicit types use the `typedValue` parser.
value :: Parser Value
value = ValueVariable <$> variable
<|> number
-- TODO: Handle maxBound, Int32 in spec.
<|> tok (either ValueFloat ValueInt . floatingOrInteger <$> scientific)
<|> ValueBoolean <$> booleanValue
<|> ValueString <$> stringValue
-- `true` and `false` have been tried before
@ -156,13 +157,6 @@ value = ValueVariable <$> variable
<|> ValueList <$> listValue
<|> ValueObject <$> objectValue
<?> "value error!"
where
number = do
v <- scientific
case floatingOrInteger v of
Left r -> pure (ValueFloat r)
-- TODO: Handle maxBound, Int32 in spec.
Right i -> pure (ValueInt i)
booleanValue :: Parser Bool
booleanValue = True <$ tok "true"

View File

@ -30,4 +30,3 @@ ksTest = testCase "Kitchen Sink"
actual = either (error "Parsing error!") Encoder.document
. parseOnly Parser.document
<$> expected