on master help sign in
update the kernel parser for the new parse error style
51ed497Evan Czaplicki
compiler/src/Elm/Kernel.hs+27−14
@@ -24,12 +24,11 @@ import qualified AST.Source as Src
24import qualified Elm.ModuleName as ModuleName
24import qualified Elm.ModuleName as ModuleName
25import qualified Elm.Package as Pkg
25import qualified Elm.Package as Pkg
26import qualified Parse.Module as Module
26import qualified Parse.Module as Module
27+import qualified Parse.Space as Space
27import qualified Parse.Variable as Var
28import qualified Parse.Variable as Var
28−import Parse.Utils
29−import Parse.Primitives hiding (Parser, fromByteString)
29+import Parse.Primitives hiding (fromByteString)
30import qualified Parse.Primitives as P
30import qualified Parse.Primitives as P
31import qualified Reporting.Annotation as A
31import qualified Reporting.Annotation as A
32−import qualified Reporting.Error.Syntax as E
33
32
34
33
35
34
@@ -87,35 +86,49 @@ type Foreigns =
87fromByteString :: Pkg.Name -> Foreigns -> BS.ByteString -> Maybe Content
86fromByteString :: Pkg.Name -> Foreigns -> BS.ByteString -> Maybe Content
88fromByteString pkg foreigns bytes =
87fromByteString pkg foreigns bytes =
89 case P.fromByteString (parser pkg foreigns) bytes of
88 case P.fromByteString (parser pkg foreigns) bytes of
90− P.Ok content _ -> Just content
89+ P.Ok content _ ->
91− P.Err _ _ _ _ -> Nothing
90+ Just content
92
91
92+ P.Err () ->
93+ Nothing
93
94
95+
94−parser :: Pkg.Name -> Foreigns -> Parser Content
96+parser :: Pkg.Name -> Foreigns -> Parser () Content
95parser pkg foreigns =
97parser pkg foreigns =
96− do word2 0x2F 0x2A {-/*-} E.XXX
98+ do word2 0x2F 0x2A {-/*-} toError
97− Module.freshLine
99+ Space.chomp ignoreError
100+ Space.checkFreshLine toError
98− imports <- Module.chompImports []
101+ imports <- specialize ignoreError (Module.chompImports [])
99− word2 0x2A 0x2F {-*/-} E.XXX
102+ word2 0x2A 0x2F {-*/-} toError
100 chunks <- parseChunks (toVarTable pkg foreigns imports) Map.empty Map.empty
103 chunks <- parseChunks (toVarTable pkg foreigns imports) Map.empty Map.empty
101 return (Content imports chunks)
104 return (Content imports chunks)
102
105
103
106
107+toError :: Row -> Col -> ()
108+toError _ _ =
109+ ()
110+
111+
112+ignoreError :: a -> Row -> Col -> ()
113+ignoreError _ _ _ =
114+ ()
115+
116+
104
117
105-- PARSE CHUNKS
118-- PARSE CHUNKS
106
119
107
120
108−parseChunks :: VarTable -> Enums -> Fields -> Parser [Chunk]
121+parseChunks :: VarTable -> Enums -> Fields -> Parser () [Chunk]
109parseChunks vtable enums fields =
122parseChunks 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 _ ->
111 let
124 let
112 (# chunks, newPos, newRow, newCol #) =
125 (# chunks, newPos, newRow, newCol #) =
113 chompChunks vtable enums fields pos end row col pos []
126 chompChunks vtable enums fields pos end row col pos []
114 in
127 in
115 if newPos == end then
128 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)
117 else
130 else
118− cerr row col ctx E.XXX
131+ cerr row col toError
119
132
120
133
121chompChunks :: VarTable -> Enums -> Fields -> Ptr Word8 -> Ptr Word8 -> Word16 -> Word16 -> Ptr Word8 -> [Chunk] -> (# [Chunk], Ptr Word8, Word16, Word16 #)
134chompChunks :: VarTable -> Enums -> Fields -> Ptr Word8 -> Ptr Word8 -> Word16 -> Word16 -> Ptr Word8 -> [Chunk] -> (# [Chunk], Ptr Word8, Word16, Word16 #)