on master help sign in
Thread (ForeignPtr Word8) through a bunch of parsing code
14af98cEvan Czaplicki
compiler/src/Parse/Declaration.hs+3−3
@@ -109,14 +109,14 @@ chompMatchingName expectedName =
109 let
109 let
110 (P.Parser parserL) = Var.lower E.DeclDefNameRepeat
110 (P.Parser parserL) = Var.lower E.DeclDefNameRepeat
111 in
111 in
112− P.Parser $ \state@(P.State _ _ _ sr sc) cok eok cerr eerr ->
112+ P.Parser $ \state@(P.State _ _ _ _ sr sc) cok eok cerr eerr ->
113 let
113 let
114− cokL name newState@(P.State _ _ _ er ec) =
114+ cokL name newState@(P.State _ _ _ _ er ec) =
115 if expectedName == name
115 if expectedName == name
116 then cok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState
116 then cok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState
117 else cerr sr sc (E.DeclDefNameMatch name)
117 else cerr sr sc (E.DeclDefNameMatch name)
118
118
119− eokL name newState@(P.State _ _ _ er ec) =
119+ eokL name newState@(P.State _ _ _ _ er ec) =
120 if expectedName == name
120 if expectedName == name
121 then eok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState
121 then eok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState
122 else eerr sr sc (E.DeclDefNameMatch name)
122 else eerr sr sc (E.DeclDefNameMatch name)
compiler/src/Parse/Keyword.hs+16−16
@@ -120,7 +120,7 @@ command_ tx = k7 0x63 0x6F 0x6D 0x6D 0x61 0x6E 0x64 tx
120
120
121subscription_ :: (Row -> Col -> x) -> Parser x ()
121subscription_ :: (Row -> Col -> x) -> Parser x ()
122subscription_ toError =
122subscription_ toError =
123− P.Parser $ \(P.State pos end indent row col) cok _ _ eerr ->
123+ P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
124 let !pos12 = plusPtr pos 12 in
124 let !pos12 = plusPtr pos 12 in
125 if pos12 <= end
125 if pos12 <= end
126 && P.unsafeIndex ( pos ) == 0x73
126 && P.unsafeIndex ( pos ) == 0x73
@@ -137,7 +137,7 @@ subscription_ toError =
137 && P.unsafeIndex (plusPtr pos 11) == 0x6E
137 && P.unsafeIndex (plusPtr pos 11) == 0x6E
138 && Var.getInnerWidth pos12 end == 0
138 && Var.getInnerWidth pos12 end == 0
139 then
139 then
140− let !s = P.State pos12 end indent row (col + 12) in cok () s
140+ let !s = P.State src pos12 end indent row (col + 12) in cok () s
141 else
141 else
142 eerr row col toError
142 eerr row col toError
143
143
@@ -148,21 +148,21 @@ subscription_ toError =
148
148
149k2 :: Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
149k2 :: Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
150k2 w1 w2 toError =
150k2 w1 w2 toError =
151− P.Parser $ \(P.State pos end indent row col) cok _ _ eerr ->
151+ P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
152 let !pos2 = plusPtr pos 2 in
152 let !pos2 = plusPtr pos 2 in
153 if pos2 <= end
153 if pos2 <= end
154 && P.unsafeIndex ( pos ) == w1
154 && P.unsafeIndex ( pos ) == w1
155 && P.unsafeIndex (plusPtr pos 1) == w2
155 && P.unsafeIndex (plusPtr pos 1) == w2
156 && Var.getInnerWidth pos2 end == 0
156 && Var.getInnerWidth pos2 end == 0
157 then
157 then
158− let !s = P.State pos2 end indent row (col + 2) in cok () s
158+ let !s = P.State src pos2 end indent row (col + 2) in cok () s
159 else
159 else
160 eerr row col toError
160 eerr row col toError
161
161
162
162
163k3 :: Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
163k3 :: Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
164k3 w1 w2 w3 toError =
164k3 w1 w2 w3 toError =
165− P.Parser $ \(P.State pos end indent row col) cok _ _ eerr ->
165+ P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
166 let !pos3 = plusPtr pos 3 in
166 let !pos3 = plusPtr pos 3 in
167 if pos3 <= end
167 if pos3 <= end
168 && P.unsafeIndex ( pos ) == w1
168 && P.unsafeIndex ( pos ) == w1
@@ -170,14 +170,14 @@ k3 w1 w2 w3 toError =
170 && P.unsafeIndex (plusPtr pos 2) == w3
170 && P.unsafeIndex (plusPtr pos 2) == w3
171 && Var.getInnerWidth pos3 end == 0
171 && Var.getInnerWidth pos3 end == 0
172 then
172 then
173− let !s = P.State pos3 end indent row (col + 3) in cok () s
173+ let !s = P.State src pos3 end indent row (col + 3) in cok () s
174 else
174 else
175 eerr row col toError
175 eerr row col toError
176
176
177
177
178k4 :: Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
178k4 :: Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
179k4 w1 w2 w3 w4 toError =
179k4 w1 w2 w3 w4 toError =
180− P.Parser $ \(P.State pos end indent row col) cok _ _ eerr ->
180+ P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
181 let !pos4 = plusPtr pos 4 in
181 let !pos4 = plusPtr pos 4 in
182 if pos4 <= end
182 if pos4 <= end
183 && P.unsafeIndex ( pos ) == w1
183 && P.unsafeIndex ( pos ) == w1
@@ -186,14 +186,14 @@ k4 w1 w2 w3 w4 toError =
186 && P.unsafeIndex (plusPtr pos 3) == w4
186 && P.unsafeIndex (plusPtr pos 3) == w4
187 && Var.getInnerWidth pos4 end == 0
187 && Var.getInnerWidth pos4 end == 0
188 then
188 then
189− let !s = P.State pos4 end indent row (col + 4) in cok () s
189+ let !s = P.State src pos4 end indent row (col + 4) in cok () s
190 else
190 else
191 eerr row col toError
191 eerr row col toError
192
192
193
193
194k5 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
194k5 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
195k5 w1 w2 w3 w4 w5 toError =
195k5 w1 w2 w3 w4 w5 toError =
196− P.Parser $ \(P.State pos end indent row col) cok _ _ eerr ->
196+ P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
197 let !pos5 = plusPtr pos 5 in
197 let !pos5 = plusPtr pos 5 in
198 if pos5 <= end
198 if pos5 <= end
199 && P.unsafeIndex ( pos ) == w1
199 && P.unsafeIndex ( pos ) == w1
@@ -203,14 +203,14 @@ k5 w1 w2 w3 w4 w5 toError =
203 && P.unsafeIndex (plusPtr pos 4) == w5
203 && P.unsafeIndex (plusPtr pos 4) == w5
204 && Var.getInnerWidth pos5 end == 0
204 && Var.getInnerWidth pos5 end == 0
205 then
205 then
206− let !s = P.State pos5 end indent row (col + 5) in cok () s
206+ let !s = P.State src pos5 end indent row (col + 5) in cok () s
207 else
207 else
208 eerr row col toError
208 eerr row col toError
209
209
210
210
211k6 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
211k6 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
212k6 w1 w2 w3 w4 w5 w6 toError =
212k6 w1 w2 w3 w4 w5 w6 toError =
213− P.Parser $ \(P.State pos end indent row col) cok _ _ eerr ->
213+ P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
214 let !pos6 = plusPtr pos 6 in
214 let !pos6 = plusPtr pos 6 in
215 if pos6 <= end
215 if pos6 <= end
216 && P.unsafeIndex ( pos ) == w1
216 && P.unsafeIndex ( pos ) == w1
@@ -221,14 +221,14 @@ k6 w1 w2 w3 w4 w5 w6 toError =
221 && P.unsafeIndex (plusPtr pos 5) == w6
221 && P.unsafeIndex (plusPtr pos 5) == w6
222 && Var.getInnerWidth pos6 end == 0
222 && Var.getInnerWidth pos6 end == 0
223 then
223 then
224− let !s = P.State pos6 end indent row (col + 6) in cok () s
224+ let !s = P.State src pos6 end indent row (col + 6) in cok () s
225 else
225 else
226 eerr row col toError
226 eerr row col toError
227
227
228
228
229k7 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
229k7 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
230k7 w1 w2 w3 w4 w5 w6 w7 toError =
230k7 w1 w2 w3 w4 w5 w6 w7 toError =
231− P.Parser $ \(P.State pos end indent row col) cok _ _ eerr ->
231+ P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
232 let !pos7 = plusPtr pos 7 in
232 let !pos7 = plusPtr pos 7 in
233 if pos7 <= end
233 if pos7 <= end
234 && P.unsafeIndex ( pos ) == w1
234 && P.unsafeIndex ( pos ) == w1
@@ -240,14 +240,14 @@ k7 w1 w2 w3 w4 w5 w6 w7 toError =
240 && P.unsafeIndex (plusPtr pos 6) == w7
240 && P.unsafeIndex (plusPtr pos 6) == w7
241 && Var.getInnerWidth pos7 end == 0
241 && Var.getInnerWidth pos7 end == 0
242 then
242 then
243− let !s = P.State pos7 end indent row (col + 7) in cok () s
243+ let !s = P.State src pos7 end indent row (col + 7) in cok () s
244 else
244 else
245 eerr row col toError
245 eerr row col toError
246
246
247
247
248k8 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
248k8 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
249k8 w1 w2 w3 w4 w5 w6 w7 w8 toError =
249k8 w1 w2 w3 w4 w5 w6 w7 w8 toError =
250− P.Parser $ \(P.State pos end indent row col) cok _ _ eerr ->
250+ P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
251 let !pos8 = plusPtr pos 8 in
251 let !pos8 = plusPtr pos 8 in
252 if pos8 <= end
252 if pos8 <= end
253 && P.unsafeIndex ( pos ) == w1
253 && P.unsafeIndex ( pos ) == w1
@@ -260,6 +260,6 @@ k8 w1 w2 w3 w4 w5 w6 w7 w8 toError =
260 && P.unsafeIndex (plusPtr pos 7) == w8
260 && P.unsafeIndex (plusPtr pos 7) == w8
261 && Var.getInnerWidth pos8 end == 0
261 && Var.getInnerWidth pos8 end == 0
262 then
262 then
263− let !s = P.State pos8 end indent row (col + 8) in cok () s
263+ let !s = P.State src pos8 end indent row (col + 8) in cok () s
264 else
264 else
265 eerr row col toError
265 eerr row col toError
compiler/src/Parse/Shader.hs+3−3
@@ -44,7 +44,7 @@ shader start@(A.Position row col) =
44
44
45parseBlock :: Parser E.Expr String
45parseBlock :: Parser E.Expr String
46parseBlock =
46parseBlock =
47− P.Parser $ \(P.State pos end indent row col) cok _ cerr eerr ->
47+ P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
48 let
48 let
49 !pos6 = plusPtr pos 6
49 !pos6 = plusPtr pos 6
50 in
50 in
@@ -65,7 +65,7 @@ parseBlock =
65 let
65 let
66 !block = Utf8.fromPtr pos6 newPos
66 !block = Utf8.fromPtr pos6 newPos
67 !source = Utf8.toChars block
67 !source = Utf8.toChars block
68− !newState = P.State (plusPtr newPos 2) end indent newRow (newCol + 2)
68+ !newState = P.State src (plusPtr newPos 2) end indent newRow (newCol + 2)
69 in
69 in
70 cok source newState
70 cok source newState
71
71
@@ -130,7 +130,7 @@ parseGlsl startRow startCol src =
130
130
131failure :: Row -> Col -> String -> Parser E.Expr a
131failure :: Row -> Col -> String -> Parser E.Expr a
132failure row col msg =
132failure row col msg =
133− P.Parser $ \(P.State _ _ _ _ _) _ _ cerr _ ->
133+ P.Parser $ \(P.State _ _ _ _ _ _) _ _ cerr _ ->
134 cerr row col (E.ShaderProblem msg)
134 cerr row col (E.ShaderProblem msg)
135
135
136
136
compiler/src/Parse/Symbol.hs+2−2
@@ -33,7 +33,7 @@ data BadOperator
33
33
34operator :: (Row -> Col -> x) -> (BadOperator -> Row -> Col -> x) -> Parser x Name.Name
34operator :: (Row -> Col -> x) -> (BadOperator -> Row -> Col -> x) -> Parser x Name.Name
35operator toExpectation toError =
35operator toExpectation toError =
36− P.Parser $ \(P.State pos end indent row col) cok _ cerr eerr ->
36+ P.Parser $ \(P.State src pos end indent row col) cok _ cerr eerr ->
37 let !newPos = chompOps pos end in
37 let !newPos = chompOps pos end in
38 if pos == newPos then
38 if pos == newPos then
39 eerr row col toExpectation
39 eerr row col toExpectation
@@ -48,7 +48,7 @@ operator toExpectation toError =
48 op ->
48 op ->
49 let
49 let
50 !newCol = col + fromIntegral (minusPtr newPos pos)
50 !newCol = col + fromIntegral (minusPtr newPos pos)
51− !newState = P.State newPos end indent row newCol
51+ !newState = P.State src newPos end indent row newCol
52 in
52 in
53 cok op newState
53 cok op newState
54
54