@@ -17,6 +17,7 @@ module Json.Decode
1717
1818
1919import Prelude hiding (length)
20+import qualified Data.ByteString.Char8 as Char8
2021import qualified Data.ByteString.Internal as B
2122import qualified Data.HashMap.Strict as HashMap
2223import qualified Data.Text as Text
@@ -30,6 +31,7 @@ import qualified Parse.Primitives as P
3031import qualified Parse.Primitives.Internals as I
3132import Parse.Primitives.Internals (Parser(..), State(..), noError)
3233import qualified Parse.Primitives.Keyword as Keyword
34+import qualified Parse.Primitives.Number as Number
3335import qualified Parse.Primitives.Symbol as Symbol
3436import qualified Reporting.Error.Syntax as E
3537import qualified Reporting.Region as R
@@ -169,7 +171,41 @@ arrayHelp !length revEntries =
169171
170172number :: Parser Json.Value
171173number =
172− error "TODO"
174+ Parser $ \(State fp offset terminal indent row col ctx) cok cerr _ eerr ->
175+ if offset < terminal then
176+
177+ let
178+ !word = I.unsafeIndex fp offset
179+ !offset1 = offset + 1
180+ in
181+ if word <= 0x39 {- 9 -} && word >= 0x31 {- 1 -} then
182+ case Number.chompInt fp offset1 terminal (fromIntegral (word - 0x30 {- 0 -})) of
183+ Number.Err newOffset problem ->
184+ cerr (E.ParseError row (col + (newOffset - offset)) problem)
185+
186+ Number.OkInt newOffset n ->
187+ let
188+ !newState = State fp newOffset terminal indent row (col + (newOffset - offset)) ctx
189+ in
190+ cok (Json.Integer n) newState noError
191+
192+ Number.OkFloat newOffset ->
193+ let
194+ !length = newOffset - offset
195+ !scientific = read $ Char8.unpack $ B.PS fp offset length
196+ !newState = State fp newOffset terminal indent row (col + length) ctx
197+ in
198+ cok (Json.Float scientific) newState noError
199+
200+ else if word == 0x30 {- 0 -} then
201+ cok (Json.Integer 0) (State fp offset1 terminal indent row (col + 1) ctx) noError
202+
203+ else
204+ eerr noError
205+
206+ else
207+ eerr noError
208+
173209
174210
175211