on master help sign in
Improve parse errors in a couple Parse/* modules
commitb3d515fccaab2513f9f754e95c5d871f7f6cb319 authorEvan Czaplicki <evancz@users.noreply.github.com> dateFri 28 Dec 2018, 12:25 (8 years ago) parente4b3c93
4 files changed+36−37
compiler/src/Parse/Number.hs+5−5 compiler/src/Parse/Shader.hs+5−6 compiler/src/Parse/Symbol.hs+11−11 compiler/src/Parse/Utf8.hs+15−15
compiler/src/Parse/Number.hs+5−5
@@ -50,12 +50,12 @@ number :: Parser Number
5050number =
5151 P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
5252 if pos >= end then
53− eerr row col ctx E.Number
53+ eerr row col ctx E.Number_Start
5454
5555 else
5656 let !word = P.unsafeIndex pos in
5757 if not (isDecimalDigit word) then
58− eerr row col ctx E.Number
58+ eerr row col ctx E.Number_Start
5959
6060 else
6161 let
@@ -176,7 +176,7 @@ chompFractionHelp pos end =
176176chompExponent :: Ptr Word8 -> Ptr Word8 -> Outcome
177177chompExponent pos end =
178178 if pos >= end then
179− Err pos E.Number_Exp
179+ Err pos E.Number_End
180180
181181 else
182182 let !word = P.unsafeIndex pos in
@@ -189,10 +189,10 @@ chompExponent pos end =
189189 if pos1 < end && isDecimalDigit (P.unsafeIndex pos1) then
190190 chompExponentHelp (plusPtr pos 2) end
191191 else
192− Err pos E.Number_Exp
192+ Err pos E.Number_End
193193
194194 else
195− Err pos E.Number_Exp
195+ Err pos E.Number_End
196196
197197
198198chompExponentHelp :: Ptr Word8 -> Ptr Word8 -> Outcome
compiler/src/Parse/Shader.hs+5−6
@@ -70,7 +70,7 @@ parseBlock =
7070 cok block newState
7171
7272 Unending ->
73− cerr row col ctx E.ShaderEnd
73+ cerr row col ctx (E.ShaderEnd col (col + 6))
7474
7575 else
7676 eerr row col ctx E.ShaderStart
@@ -123,16 +123,15 @@ parseGlsl startRow startCol src =
123123 "end of input"
124124 (Parsec.errorMessages err)
125125 in
126− if row == 1 then
127− failure startRow (startCol + 6 + col) msg
128− else
129− failure (startRow + row - 1) col msg
126+ if row == 1
127+ then failure startRow (startCol + 6 + col) msg
128+ else failure (startRow + row - 1) col msg
130129
131130
132131failure :: Word16 -> Word16 -> String -> Parser a
133132failure row col msg =
134133 P.Parser $ \(P.State _ _ _ _ _ ctx) _ _ cerr _ ->
135− cerr row col ctx (E.ShaderValid msg)
134+ cerr row col ctx (E.ShaderProblem msg)
136135
137136
138137
compiler/src/Parse/Symbol.hs+11−11
@@ -1,7 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE BangPatterns, UnboxedTuples, OverloadedStrings #-}
33module Parse.Symbol
4− ( underscore
4+ ( wildcard
55 , binop
66 )
77 where
@@ -24,11 +24,11 @@ import qualified Reporting.Error.Syntax as E
2424-- UNDERSCORE
2525
2626
27−underscore :: Parser ()
28−underscore =
27+wildcard :: Parser ()
28+wildcard =
2929 P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
3030 if pos == end || P.unsafeIndex pos /= 0x5F {- _ -} then
31− eerr row col ctx E.Underscore
31+ eerr row col ctx E.Wildcard
3232 else
3333 let
3434 !newPos = plusPtr pos 1
@@ -36,7 +36,7 @@ underscore =
3636 in
3737 if Var.getInnerWidth newPos end > 0 then
3838 let (# _, badCol #) = Var.chompInnerChars newPos end newCol in
39− cerr row newCol ctx (E.UnderscoreNotVar (fromIntegral (badCol - newCol)))
39+ cerr row col ctx (E.WildcardNotVar newCol badCol)
4040 else
4141 let !newState = P.State newPos end indent row newCol ctx in
4242 cok () newState
@@ -51,15 +51,15 @@ binop =
5151 P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
5252 let !newPos = chompOps pos end in
5353 if pos == newPos then
54− eerr row col ctx E.Binop
54+ eerr row col ctx E.XXX
5555
5656 else
5757 case Name.fromPtr pos newPos of
58− "." -> cerr row col ctx (E.ReservedBinop E.Dot)
59− "|" -> cerr row col ctx (E.ReservedBinop E.Pipe)
60− "->" -> cerr row col ctx (E.ReservedBinop E.Arrow)
61− "=" -> cerr row col ctx (E.ReservedBinop E.Equals)
62− ":" -> cerr row col ctx (E.ReservedBinop E.HasType)
58+ "." -> cerr row col ctx (E.ReservedOperator E.Dot)
59+ "|" -> cerr row col ctx (E.ReservedOperator E.Pipe)
60+ "->" -> cerr row col ctx (E.ReservedOperator E.Arrow)
61+ "=" -> cerr row col ctx (E.ReservedOperator E.Equals)
62+ ":" -> cerr row col ctx (E.ReservedOperator E.HasType)
6363 op ->
6464 let
6565 !newCol = col + fromIntegral (minusPtr newPos pos)
compiler/src/Parse/Utf8.hs+15−15
@@ -101,7 +101,7 @@ string =
101101 !pos1 = plusPtr pos 1
102102 result =
103103 if isDoubleQuote pos1 end && isDoubleQuote (plusPtr pos 2) end then
104− multiString (plusPtr pos 3) end row (col + 3) (plusPtr pos 3) mempty
104+ multiString (plusPtr pos 3) end row (col + 3) (plusPtr pos 3) row col mempty
105105 else
106106 singleString pos1 end row (col + 1) pos1 mempty
107107 in
@@ -198,10 +198,10 @@ singleString pos end row col initialPos revChunks =
198198-- MULTI STRINGS
199199
200200
201−multiString :: Ptr Word8 -> Ptr Word8 -> Word16 -> Word16 -> Ptr Word8 -> [Utf8.Chunk] -> StringResult
202−multiString pos end row col initialPos revChunks =
201+multiString :: Ptr Word8 -> Ptr Word8 -> Word16 -> Word16 -> Ptr Word8 -> Word16 -> Word16 -> [Utf8.Chunk] -> StringResult
202+multiString pos end row col initialPos sr sc revChunks =
203203 if pos >= end then
204− Err row col E.StringEnd_Multi
204+ Err row col (E.StringEnd_Multi sr sc)
205205
206206 else
207207 let !word = P.unsafeIndex pos in
@@ -211,38 +211,38 @@ multiString pos end row col initialPos revChunks =
211211
212212 else if word == 0x27 {- ' -} then
213213 let !pos1 = plusPtr pos 1 in
214− multiString pos1 end row (col + 1) pos1 $
214+ multiString pos1 end row (col + 1) pos1 sr sc $
215215 addEscape singleQuote initialPos pos revChunks
216216
217217 else if word == 0x0A {- \n -} then
218218 let !pos1 = plusPtr pos 1 in
219− multiString pos1 end (row + 1) 1 pos1 $
219+ multiString pos1 end (row + 1) 1 pos1 sr sc $
220220 addEscape newline initialPos pos revChunks
221221
222222 else if word == 0x0D {- \r -} then
223223 let !pos1 = plusPtr pos 1 in
224− multiString pos1 end row col pos1 $
224+ multiString pos1 end row col pos1 sr sc $
225225 addEscape carriageReturn initialPos pos revChunks
226226
227227 else if word == 0x5C {- \ -} then
228228 case eatEscape (plusPtr pos 1) end col of
229229 EscapeNormal ->
230− multiString (plusPtr pos 2) end row (col + 2) initialPos revChunks
230+ multiString (plusPtr pos 2) end row (col + 2) initialPos sr sc revChunks
231231
232232 EscapeUnicode delta code ->
233233 let !newPos = plusPtr pos delta in
234− multiString newPos end row (col + fromIntegral delta) newPos $
234+ multiString newPos end row (col + fromIntegral delta) newPos sr sc $
235235 addEscape (Utf8.CodePoint code) initialPos pos revChunks
236236
237237 EscapeProblem x ->
238238 Err row col x
239239
240240 EscapeEndOfFile ->
241− Err row (col + 1) E.StringEnd_Multi
241+ Err row (col + 1) (E.StringEnd_Multi sr sc)
242242
243243 else
244244 let !newPos = plusPtr pos (P.getCharWidth pos end word) in
245− multiString newPos end row (col + 1) initialPos revChunks
245+ multiString newPos end row (col + 1) initialPos sr sc revChunks
246246
247247
248248
@@ -276,7 +276,7 @@ eatEscape pos end startCol =
276276eatUnicode :: Ptr Word8 -> Ptr Word8 -> Word16 -> Escape
277277eatUnicode pos end startCol =
278278 if pos >= end || P.unsafeIndex pos /= 0x7B {- { -} then
279− EscapeProblem $ E.BadUnicodeStart startCol (startCol + 1)
279+ EscapeProblem $ E.BadUnicodeFormat startCol (startCol + 1)
280280 else
281281 let
282282 !digitPos = plusPtr pos 1
@@ -284,16 +284,16 @@ eatUnicode pos end startCol =
284284 !numDigits = minusPtr newPos digitPos
285285 in
286286 if newPos >= end || P.unsafeIndex newPos /= 0x7D {- } -} then
287− EscapeProblem $ E.BadUnicodeEnd startCol $
287+ EscapeProblem $ E.BadUnicodeFormat startCol $
288288 startCol + fromIntegral (minusPtr newPos pos)
289289
290290 else if code < 0 || 0x10FFFF < code then
291− EscapeProblem $ E.BadUnicodeRange startCol $
291+ EscapeProblem $ E.BadUnicodeCode startCol $
292292 startCol + fromIntegral (minusPtr newPos pos) + 1
293293
294294 else if numDigits < 4 || 6 < numDigits then
295295 EscapeProblem $
296− E.BadUnicodeFormat
296+ E.BadUnicodeLength
297297 startCol
298298 (startCol + fromIntegral (minusPtr newPos pos) + 1)
299299 numDigits