on master help sign in
Update Json.Decode to compile with new parser types
commit6369fa3794d5717012b00d0328384bb81038008b authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 29 Apr 2019, 17:15 (8 years ago) parent35a43f4
1 file changed+28−21
compiler/src/Json/Decode.hs+28−21
compiler/src/Json/Decode.hs+28−21
@@ -36,14 +36,14 @@ fromByteString decoder src =
3636 fromAST decoder (P.fromByteString pFile src)
3737
3838
39−fromAST :: Decoder e a -> P.Result E.Context E.ParseExpectation AST -> Either (E.Error e) a
39+fromAST :: Decoder e a -> P.Result E.ParseError AST -> Either (E.Error e) a
4040fromAST (Decoder decode) parserResult =
4141 case parserResult of
4242 P.Ok ast _ ->
4343 decode ast Right (Left . E.DecodeProblem)
4444
45− P.Err row col ctx expectation ->
46− Left (E.ParseProblem row col ctx expectation)
45+ P.Err err ->
46+ Left (E.ParseProblem err)
4747
4848
4949
@@ -51,7 +51,14 @@ fromAST (Decoder decode) parserResult =
5151
5252
5353newtype Decoder e a =
54− Decoder (forall b. AST -> (a -> b) -> (E.Problem e -> b) -> b)
54+ Decoder
55+ (
56+ forall b.
57+ AST
58+ -> (a -> b)
59+ -> (E.Problem e -> b)
60+ -> b
61+ )
5562
5663
5764
@@ -352,7 +359,7 @@ data AST
352359
353360
354361type Parser a =
355− P.Parser E.Context E.ParseExpectation a
362+ P.Parser E.ParseError a
356363
357364
358365pFile :: Parser AST
@@ -379,9 +386,9 @@ pValue =
379386
380387endOfFile :: Parser ()
381388endOfFile =
382− P.Parser $ \state@(P.State pos end _ row col ctx) _ eok _ eerr ->
389+ P.Parser $ \state@(P.State pos end _ row col) _ eok _ eerr ->
383390 if pos < end then
384− eerr row col ctx E.EndOfFile
391+ eerr row col E.EndOfFile
385392 else
386393 eok () state
387394
@@ -466,7 +473,7 @@ pArrayHelp !len revEntries =
466473
467474pString :: Parser Utf8.String
468475pString =
469− P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
476+ P.Parser $ \(P.State pos end indent row col) cok _ cerr eerr ->
470477 if pos < end && P.unsafeIndex pos == 0x22 {-"-} then
471478
472479 let
@@ -478,16 +485,16 @@ pString =
478485 case status of
479486 GoodString ->
480487 let
481− !newState = P.State newPos end indent newRow newCol ctx
488+ !newState = P.State newPos end indent newRow newCol
482489 !content = Utf8.fromPtr pos1 (plusPtr newPos (-1))
483490 in
484491 cok content newState
485492
486493 BadStringEnd ->
487− cerr newRow newCol ctx E.StringEnd
494+ cerr newRow newCol E.StringEnd
488495
489496 else
490− eerr row col ctx E.StringStart
497+ eerr row col E.StringStart
491498
492499
493500data StringStatus
@@ -534,7 +541,7 @@ pStringHelp pos end row col =
534541
535542spaces :: Parser ()
536543spaces =
537− P.Parser $ \state@(P.State pos end indent row col ctx) cok eok _ _ ->
544+ P.Parser $ \state@(P.State pos end indent row col) cok eok _ _ ->
538545 let
539546 (# newPos, newRow, newCol #) =
540547 eatSpaces pos end row col
@@ -544,7 +551,7 @@ spaces =
544551 else
545552 let
546553 !newState =
547− P.State newPos end indent newRow newCol ctx
554+ P.State newPos end indent newRow newCol
548555 in
549556 cok () newState
550557
@@ -570,27 +577,27 @@ eatSpaces pos end row col =
570577
571578pInt :: Parser AST
572579pInt =
573− P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
580+ P.Parser $ \(P.State pos end indent row col) cok _ cerr eerr ->
574581 if pos >= end then
575− eerr row col ctx E.IntStart
582+ eerr row col E.IntStart
576583
577584 else
578585 let !word = P.unsafeIndex pos in
579586 if not (isDecimalDigit word) then
580− eerr row col ctx E.IntStart
587+ eerr row col E.IntStart
581588
582589 else if word == 0x30 {-0-} then
583590
584591 let
585592 !pos1 = plusPtr pos 1
586− !newState = P.State pos1 end indent row (col + 1) ctx
593+ !newState = P.State pos1 end indent row (col + 1)
587594 in
588595 if pos1 < end then
589596 let !word1 = P.unsafeIndex pos1 in
590597 if isDecimalDigit word1 then
591− cerr row (col + 1) ctx E.NoLeadingZeros
598+ cerr row (col + 1) E.NoLeadingZeros
592599 else if word1 == 0x2E {-.-} then
593− cerr row (col + 1) ctx E.NoFloats
600+ cerr row (col + 1) E.NoFloats
594601 else
595602 cok (Int 0) newState
596603 else
@@ -607,12 +614,12 @@ pInt =
607614 GoodInt ->
608615 let
609616 !newState =
610− P.State newPos end indent row (col + len) ctx
617+ P.State newPos end indent row (col + len)
611618 in
612619 cok (Int n) newState
613620
614621 BadIntEnd ->
615− cerr row (col + len) ctx E.NoFloats
622+ cerr row (col + len) E.NoFloats
616623
617624
618625data IntStatus = GoodInt | BadIntEnd