on master help sign in
Improve parse errors in a couple Parse/* modules
b3d515fEvan Czaplicki
compiler/src/Parse/Number.hs+5−5
@@ -50,12 +50,12 @@ number :: Parser Number
50number =
50number =
51 P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
51 P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
52 if pos >= end then
52 if pos >= end then
53− eerr row col ctx E.Number
53+ eerr row col ctx E.Number_Start
54
54
55 else
55 else
56 let !word = P.unsafeIndex pos in
56 let !word = P.unsafeIndex pos in
57 if not (isDecimalDigit word) then
57 if not (isDecimalDigit word) then
58− eerr row col ctx E.Number
58+ eerr row col ctx E.Number_Start
59
59
60 else
60 else
61 let
61 let
@@ -176,7 +176,7 @@ chompFractionHelp pos end =
176chompExponent :: Ptr Word8 -> Ptr Word8 -> Outcome
176chompExponent :: Ptr Word8 -> Ptr Word8 -> Outcome
177chompExponent pos end =
177chompExponent pos end =
178 if pos >= end then
178 if pos >= end then
179− Err pos E.Number_Exp
179+ Err pos E.Number_End
180
180
181 else
181 else
182 let !word = P.unsafeIndex pos in
182 let !word = P.unsafeIndex pos in
@@ -189,10 +189,10 @@ chompExponent pos end =
189 if pos1 < end && isDecimalDigit (P.unsafeIndex pos1) then
189 if pos1 < end && isDecimalDigit (P.unsafeIndex pos1) then
190 chompExponentHelp (plusPtr pos 2) end
190 chompExponentHelp (plusPtr pos 2) end
191 else
191 else
192− Err pos E.Number_Exp
192+ Err pos E.Number_End
193
193
194 else
194 else
195− Err pos E.Number_Exp
195+ Err pos E.Number_End
196
196
197
197
198chompExponentHelp :: Ptr Word8 -> Ptr Word8 -> Outcome
198chompExponentHelp :: Ptr Word8 -> Ptr Word8 -> Outcome
compiler/src/Parse/Shader.hs+5−6
@@ -70,7 +70,7 @@ parseBlock =
70 cok block newState
70 cok block newState
71
71
72 Unending ->
72 Unending ->
73− cerr row col ctx E.ShaderEnd
73+ cerr row col ctx (E.ShaderEnd col (col + 6))
74
74
75 else
75 else
76 eerr row col ctx E.ShaderStart
76 eerr row col ctx E.ShaderStart
@@ -123,16 +123,15 @@ parseGlsl startRow startCol src =
123 "end of input"
123 "end of input"
124 (Parsec.errorMessages err)
124 (Parsec.errorMessages err)
125 in
125 in
126− if row == 1 then
126+ if row == 1
127− failure startRow (startCol + 6 + col) msg
127+ then failure startRow (startCol + 6 + col) msg
128− else
129− failure (startRow + row - 1) col msg
128+ else failure (startRow + row - 1) col msg
130
129
131
130
132failure :: Word16 -> Word16 -> String -> Parser a
131failure :: Word16 -> Word16 -> String -> Parser a
133failure row col msg =
132failure row col msg =
134 P.Parser $ \(P.State _ _ _ _ _ ctx) _ _ cerr _ ->
133 P.Parser $ \(P.State _ _ _ _ _ ctx) _ _ cerr _ ->
135− cerr row col ctx (E.ShaderValid msg)
134+ cerr row col ctx (E.ShaderProblem msg)
136
135
137
136
138
137
compiler/src/Parse/Symbol.hs+11−11
@@ -1,7 +1,7 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE BangPatterns, UnboxedTuples, OverloadedStrings #-}
2{-# LANGUAGE BangPatterns, UnboxedTuples, OverloadedStrings #-}
3module Parse.Symbol
3module Parse.Symbol
4− ( underscore
4+ ( wildcard
5 , binop
5 , binop
6 )
6 )
7 where
7 where
@@ -24,11 +24,11 @@ import qualified Reporting.Error.Syntax as E
24-- UNDERSCORE
24-- UNDERSCORE
25
25
26
26
27−underscore :: Parser ()
27+wildcard :: Parser ()
28−underscore =
28+wildcard =
29 P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
29 P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
30 if pos == end || P.unsafeIndex pos /= 0x5F {- _ -} then
30 if pos == end || P.unsafeIndex pos /= 0x5F {- _ -} then
31− eerr row col ctx E.Underscore
31+ eerr row col ctx E.Wildcard
32 else
32 else
33 let
33 let
34 !newPos = plusPtr pos 1
34 !newPos = plusPtr pos 1
@@ -36,7 +36,7 @@ underscore =
36 in
36 in
37 if Var.getInnerWidth newPos end > 0 then
37 if Var.getInnerWidth newPos end > 0 then
38 let (# _, badCol #) = Var.chompInnerChars newPos end newCol in
38 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)
40 else
40 else
41 let !newState = P.State newPos end indent row newCol ctx in
41 let !newState = P.State newPos end indent row newCol ctx in
42 cok () newState
42 cok () newState
@@ -51,15 +51,15 @@ binop =
51 P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
51 P.Parser $ \(P.State pos end indent row col ctx) cok _ cerr eerr ->
52 let !newPos = chompOps pos end in
52 let !newPos = chompOps pos end in
53 if pos == newPos then
53 if pos == newPos then
54− eerr row col ctx E.Binop
54+ eerr row col ctx E.XXX
55
55
56 else
56 else
57 case Name.fromPtr pos newPos of
57 case Name.fromPtr pos newPos of
58− "." -> cerr row col ctx (E.ReservedBinop E.Dot)
58+ "." -> cerr row col ctx (E.ReservedOperator E.Dot)
59− "|" -> cerr row col ctx (E.ReservedBinop E.Pipe)
59+ "|" -> cerr row col ctx (E.ReservedOperator E.Pipe)
60− "->" -> cerr row col ctx (E.ReservedBinop E.Arrow)
60+ "->" -> cerr row col ctx (E.ReservedOperator E.Arrow)
61− "=" -> cerr row col ctx (E.ReservedBinop E.Equals)
61+ "=" -> cerr row col ctx (E.ReservedOperator E.Equals)
62− ":" -> cerr row col ctx (E.ReservedBinop E.HasType)
62+ ":" -> cerr row col ctx (E.ReservedOperator E.HasType)
63 op ->
63 op ->
64 let
64 let
65 !newCol = col + fromIntegral (minusPtr newPos pos)
65 !newCol = col + fromIntegral (minusPtr newPos pos)
compiler/src/Parse/Utf8.hs+15−15
@@ -101,7 +101,7 @@ string =
101 !pos1 = plusPtr pos 1
101 !pos1 = plusPtr pos 1
102 result =
102 result =
103 if isDoubleQuote pos1 end && isDoubleQuote (plusPtr pos 2) end then
103 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
105 else
105 else
106 singleString pos1 end row (col + 1) pos1 mempty
106 singleString pos1 end row (col + 1) pos1 mempty
107 in
107 in
@@ -198,10 +198,10 @@ singleString pos end row col initialPos revChunks =
198-- MULTI STRINGS
198-- MULTI STRINGS
199
199
200
200
201−multiString :: Ptr Word8 -> Ptr Word8 -> Word16 -> Word16 -> Ptr Word8 -> [Utf8.Chunk] -> StringResult
201+multiString :: Ptr Word8 -> Ptr Word8 -> Word16 -> Word16 -> Ptr Word8 -> Word16 -> Word16 -> [Utf8.Chunk] -> StringResult
202−multiString pos end row col initialPos revChunks =
202+multiString pos end row col initialPos sr sc revChunks =
203 if pos >= end then
203 if pos >= end then
204− Err row col E.StringEnd_Multi
204+ Err row col (E.StringEnd_Multi sr sc)
205
205
206 else
206 else
207 let !word = P.unsafeIndex pos in
207 let !word = P.unsafeIndex pos in
@@ -211,38 +211,38 @@ multiString pos end row col initialPos revChunks =
211
211
212 else if word == 0x27 {- ' -} then
212 else if word == 0x27 {- ' -} then
213 let !pos1 = plusPtr pos 1 in
213 let !pos1 = plusPtr pos 1 in
214− multiString pos1 end row (col + 1) pos1 $
214+ multiString pos1 end row (col + 1) pos1 sr sc $
215 addEscape singleQuote initialPos pos revChunks
215 addEscape singleQuote initialPos pos revChunks
216
216
217 else if word == 0x0A {- \n -} then
217 else if word == 0x0A {- \n -} then
218 let !pos1 = plusPtr pos 1 in
218 let !pos1 = plusPtr pos 1 in
219− multiString pos1 end (row + 1) 1 pos1 $
219+ multiString pos1 end (row + 1) 1 pos1 sr sc $
220 addEscape newline initialPos pos revChunks
220 addEscape newline initialPos pos revChunks
221
221
222 else if word == 0x0D {- \r -} then
222 else if word == 0x0D {- \r -} then
223 let !pos1 = plusPtr pos 1 in
223 let !pos1 = plusPtr pos 1 in
224− multiString pos1 end row col pos1 $
224+ multiString pos1 end row col pos1 sr sc $
225 addEscape carriageReturn initialPos pos revChunks
225 addEscape carriageReturn initialPos pos revChunks
226
226
227 else if word == 0x5C {- \ -} then
227 else if word == 0x5C {- \ -} then
228 case eatEscape (plusPtr pos 1) end col of
228 case eatEscape (plusPtr pos 1) end col of
229 EscapeNormal ->
229 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
231
231
232 EscapeUnicode delta code ->
232 EscapeUnicode delta code ->
233 let !newPos = plusPtr pos delta in
233 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 $
235 addEscape (Utf8.CodePoint code) initialPos pos revChunks
235 addEscape (Utf8.CodePoint code) initialPos pos revChunks
236
236
237 EscapeProblem x ->
237 EscapeProblem x ->
238 Err row col x
238 Err row col x
239
239
240 EscapeEndOfFile ->
240 EscapeEndOfFile ->
241− Err row (col + 1) E.StringEnd_Multi
241+ Err row (col + 1) (E.StringEnd_Multi sr sc)
242
242
243 else
243 else
244 let !newPos = plusPtr pos (P.getCharWidth pos end word) in
244 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
246
246
247
247
248
248
@@ -276,7 +276,7 @@ eatEscape pos end startCol =
276eatUnicode :: Ptr Word8 -> Ptr Word8 -> Word16 -> Escape
276eatUnicode :: Ptr Word8 -> Ptr Word8 -> Word16 -> Escape
277eatUnicode pos end startCol =
277eatUnicode pos end startCol =
278 if pos >= end || P.unsafeIndex pos /= 0x7B {- { -} then
278 if pos >= end || P.unsafeIndex pos /= 0x7B {- { -} then
279− EscapeProblem $ E.BadUnicodeStart startCol (startCol + 1)
279+ EscapeProblem $ E.BadUnicodeFormat startCol (startCol + 1)
280 else
280 else
281 let
281 let
282 !digitPos = plusPtr pos 1
282 !digitPos = plusPtr pos 1
@@ -284,16 +284,16 @@ eatUnicode pos end startCol =
284 !numDigits = minusPtr newPos digitPos
284 !numDigits = minusPtr newPos digitPos
285 in
285 in
286 if newPos >= end || P.unsafeIndex newPos /= 0x7D {- } -} then
286 if newPos >= end || P.unsafeIndex newPos /= 0x7D {- } -} then
287− EscapeProblem $ E.BadUnicodeEnd startCol $
287+ EscapeProblem $ E.BadUnicodeFormat startCol $
288 startCol + fromIntegral (minusPtr newPos pos)
288 startCol + fromIntegral (minusPtr newPos pos)
289
289
290 else if code < 0 || 0x10FFFF < code then
290 else if code < 0 || 0x10FFFF < code then
291− EscapeProblem $ E.BadUnicodeRange startCol $
291+ EscapeProblem $ E.BadUnicodeCode startCol $
292 startCol + fromIntegral (minusPtr newPos pos) + 1
292 startCol + fromIntegral (minusPtr newPos pos) + 1
293
293
294 else if numDigits < 4 || 6 < numDigits then
294 else if numDigits < 4 || 6 < numDigits then
295 EscapeProblem $
295 EscapeProblem $
296− E.BadUnicodeFormat
296+ E.BadUnicodeLength
297 startCol
297 startCol
298 (startCol + fromIntegral (minusPtr newPos pos) + 1)
298 (startCol + fromIntegral (minusPtr newPos pos) + 1)
299 numDigits
299 numDigits