on master help sign in
Update Json.Decode to compile with new parser types
6369fa3Evan Czaplicki
compiler/src/Json/Decode.hs+28−21
@@ -36,14 +36,14 @@ fromByteString decoder src =
36 fromAST decoder (P.fromByteString pFile src)
36 fromAST decoder (P.fromByteString pFile src)
37
37
38
38
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
40fromAST (Decoder decode) parserResult =
40fromAST (Decoder decode) parserResult =
41 case parserResult of
41 case parserResult of
42 P.Ok ast _ ->
42 P.Ok ast _ ->
43 decode ast Right (Left . E.DecodeProblem)
43 decode ast Right (Left . E.DecodeProblem)
44
44
45− P.Err row col ctx expectation ->
45+ P.Err err ->
46− Left (E.ParseProblem row col ctx expectation)
46+ Left (E.ParseProblem err)
47
47
48
48
49
49
@@ -51,7 +51,14 @@ fromAST (Decoder decode) parserResult =
51
51
52
52
53newtype Decoder e a =
53newtype Decoder e a =
54+ Decoder
55+ (
56+ forall b.
57+ AST
58+ -> (a -> b)
54− Decoder (forall b. AST -> (a -> b) -> (E.Problem e -> b) -> b)
59+ -> (E.Problem e -> b)
60+ -> b
61+ )
55
62
56
63
57
64
@@ -352,7 +359,7 @@ data AST
352
359
353
360
354type Parser a =
361type Parser a =
355− P.Parser E.Context E.ParseExpectation a
362+ P.Parser E.ParseError a
356
363
357
364
358pFile :: Parser AST
365pFile :: Parser AST
@@ -379,9 +386,9 @@ pValue =
379
386
380endOfFile :: Parser ()
387endOfFile :: Parser ()
381endOfFile =
388endOfFile =
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 ->
383 if pos < end then
390 if pos < end then
384− eerr row col ctx E.EndOfFile
391+ eerr row col E.EndOfFile
385 else
392 else
386 eok () state
393 eok () state
387
394
@@ -466,7 +473,7 @@ pArrayHelp !len revEntries =
466
473
467pString :: Parser Utf8.String
474pString :: Parser Utf8.String
468pString =
475pString =
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 ->
470 if pos < end && P.unsafeIndex pos == 0x22 {-"-} then
477 if pos < end && P.unsafeIndex pos == 0x22 {-"-} then
471
478
472 let
479 let
@@ -478,16 +485,16 @@ pString =
478 case status of
485 case status of
479 GoodString ->
486 GoodString ->
480 let
487 let
481− !newState = P.State newPos end indent newRow newCol ctx
488+ !newState = P.State newPos end indent newRow newCol
482 !content = Utf8.fromPtr pos1 (plusPtr newPos (-1))
489 !content = Utf8.fromPtr pos1 (plusPtr newPos (-1))
483 in
490 in
484 cok content newState
491 cok content newState
485
492
486 BadStringEnd ->
493 BadStringEnd ->
487− cerr newRow newCol ctx E.StringEnd
494+ cerr newRow newCol E.StringEnd
488
495
489 else
496 else
490− eerr row col ctx E.StringStart
497+ eerr row col E.StringStart
491
498
492
499
493data StringStatus
500data StringStatus
@@ -534,7 +541,7 @@ pStringHelp pos end row col =
534
541
535spaces :: Parser ()
542spaces :: Parser ()
536spaces =
543spaces =
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 _ _ ->
538 let
545 let
539 (# newPos, newRow, newCol #) =
546 (# newPos, newRow, newCol #) =
540 eatSpaces pos end row col
547 eatSpaces pos end row col
@@ -544,7 +551,7 @@ spaces =
544 else
551 else
545 let
552 let
546 !newState =
553 !newState =
547− P.State newPos end indent newRow newCol ctx
554+ P.State newPos end indent newRow newCol
548 in
555 in
549 cok () newState
556 cok () newState
550
557
@@ -570,27 +577,27 @@ eatSpaces pos end row col =
570
577
571pInt :: Parser AST
578pInt :: Parser AST
572pInt =
579pInt =
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 ->
574 if pos >= end then
581 if pos >= end then
575− eerr row col ctx E.IntStart
582+ eerr row col E.IntStart
576
583
577 else
584 else
578 let !word = P.unsafeIndex pos in
585 let !word = P.unsafeIndex pos in
579 if not (isDecimalDigit word) then
586 if not (isDecimalDigit word) then
580− eerr row col ctx E.IntStart
587+ eerr row col E.IntStart
581
588
582 else if word == 0x30 {-0-} then
589 else if word == 0x30 {-0-} then
583
590
584 let
591 let
585 !pos1 = plusPtr pos 1
592 !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)
587 in
594 in
588 if pos1 < end then
595 if pos1 < end then
589 let !word1 = P.unsafeIndex pos1 in
596 let !word1 = P.unsafeIndex pos1 in
590 if isDecimalDigit word1 then
597 if isDecimalDigit word1 then
591− cerr row (col + 1) ctx E.NoLeadingZeros
598+ cerr row (col + 1) E.NoLeadingZeros
592 else if word1 == 0x2E {-.-} then
599 else if word1 == 0x2E {-.-} then
593− cerr row (col + 1) ctx E.NoFloats
600+ cerr row (col + 1) E.NoFloats
594 else
601 else
595 cok (Int 0) newState
602 cok (Int 0) newState
596 else
603 else
@@ -607,12 +614,12 @@ pInt =
607 GoodInt ->
614 GoodInt ->
608 let
615 let
609 !newState =
616 !newState =
610− P.State newPos end indent row (col + len) ctx
617+ P.State newPos end indent row (col + len)
611 in
618 in
612 cok (Int n) newState
619 cok (Int n) newState
613
620
614 BadIntEnd ->
621 BadIntEnd ->
615− cerr row (col + len) ctx E.NoFloats
622+ cerr row (col + len) E.NoFloats
616
623
617
624
618data IntStatus = GoodInt | BadIntEnd
625data IntStatus = GoodInt | BadIntEnd