on master help sign in
update the kernel parser for the new parse error style
commit51ed49730aae3b72653a37fb7024e979049038df authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 30 Apr 2019, 13:36 (8 years ago) parentcabf9fe
1 file changed+27−14
compiler/src/Elm/Kernel.hs+27−14
compiler/src/Elm/Kernel.hs+27−14
@@ -24,12 +24,11 @@ import qualified AST.Source as Src
2424import qualified Elm.ModuleName as ModuleName
2525import qualified Elm.Package as Pkg
2626import qualified Parse.Module as Module
27+import qualified Parse.Space as Space
2728import qualified Parse.Variable as Var
28−import Parse.Utils
29−import Parse.Primitives hiding (Parser, fromByteString)
29+import Parse.Primitives hiding (fromByteString)
3030import qualified Parse.Primitives as P
3131import qualified Reporting.Annotation as A
32−import qualified Reporting.Error.Syntax as E
3332
3433
3534
@@ -87,35 +86,49 @@ type Foreigns =
8786fromByteString :: Pkg.Name -> Foreigns -> BS.ByteString -> Maybe Content
8887fromByteString pkg foreigns bytes =
8988 case P.fromByteString (parser pkg foreigns) bytes of
90− P.Ok content _ -> Just content
91− P.Err _ _ _ _ -> Nothing
89+ P.Ok content _ ->
90+ Just content
9291
92+ P.Err () ->
93+ Nothing
9394
94−parser :: Pkg.Name -> Foreigns -> Parser Content
95+
96+parser :: Pkg.Name -> Foreigns -> Parser () Content
9597parser pkg foreigns =
96− do word2 0x2F 0x2A {-/*-} E.XXX
97− Module.freshLine
98− imports <- Module.chompImports []
99− word2 0x2A 0x2F {-*/-} E.XXX
98+ do word2 0x2F 0x2A {-/*-} toError
99+ Space.chomp ignoreError
100+ Space.checkFreshLine toError
101+ imports <- specialize ignoreError (Module.chompImports [])
102+ word2 0x2A 0x2F {-*/-} toError
100103 chunks <- parseChunks (toVarTable pkg foreigns imports) Map.empty Map.empty
101104 return (Content imports chunks)
102105
103106
107+toError :: Row -> Col -> ()
108+toError _ _ =
109+ ()
110+
111+
112+ignoreError :: a -> Row -> Col -> ()
113+ignoreError _ _ _ =
114+ ()
115+
116+
104117
105118-- PARSE CHUNKS
106119
107120
108−parseChunks :: VarTable -> Enums -> Fields -> Parser [Chunk]
121+parseChunks :: VarTable -> Enums -> Fields -> Parser () [Chunk]
109122parseChunks vtable enums fields =
110− P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr _ ->
123+ P.Parser $ \(P.State pos end indent row col) cok _ cerr _ ->
111124 let
112125 (# chunks, newPos, newRow, newCol #) =
113126 chompChunks vtable enums fields pos end row col pos []
114127 in
115128 if newPos == end then
116− cok chunks (P.State newPos end indent newRow newCol ctx)
129+ cok chunks (P.State newPos end indent newRow newCol)
117130 else
118− cerr row col ctx E.XXX
131+ cerr row col toError
119132
120133
121134chompChunks :: VarTable -> Enums -> Fields -> Ptr Word8 -> Ptr Word8 -> Word16 -> Word16 -> Ptr Word8 -> [Chunk] -> (# [Chunk], Ptr Word8, Word16, Word16 #)