on master help sign in
Thread (ForeignPtr Word8) through a bunch of parsing code
commit14af98cde81146abd5950be3d7ab0133e55898ef authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 3 Jun 2019, 10:33 (7 years ago) parent001084e
4 files changed+24−24
compiler/src/Parse/Declaration.hs+3−3 compiler/src/Parse/Keyword.hs+16−16 compiler/src/Parse/Shader.hs+3−3 compiler/src/Parse/Symbol.hs+2−2
compiler/src/Parse/Declaration.hs+3−3
@@ -109,14 +109,14 @@ chompMatchingName expectedName =
109109 let
110110 (P.Parser parserL) = Var.lower E.DeclDefNameRepeat
111111 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 ->
113113 let
114− cokL name newState@(P.State _ _ _ er ec) =
114+ cokL name newState@(P.State _ _ _ _ er ec) =
115115 if expectedName == name
116116 then cok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState
117117 else cerr sr sc (E.DeclDefNameMatch name)
118118
119− eokL name newState@(P.State _ _ _ er ec) =
119+ eokL name newState@(P.State _ _ _ _ er ec) =
120120 if expectedName == name
121121 then eok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState
122122 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
120120
121121subscription_ :: (Row -> Col -> x) -> Parser x ()
122122subscription_ 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 ->
124124 let !pos12 = plusPtr pos 12 in
125125 if pos12 <= end
126126 && P.unsafeIndex ( pos ) == 0x73
@@ -137,7 +137,7 @@ subscription_ toError =
137137 && P.unsafeIndex (plusPtr pos 11) == 0x6E
138138 && Var.getInnerWidth pos12 end == 0
139139 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
141141 else
142142 eerr row col toError
143143
@@ -148,21 +148,21 @@ subscription_ toError =
148148
149149k2 :: Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
150150k2 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 ->
152152 let !pos2 = plusPtr pos 2 in
153153 if pos2 <= end
154154 && P.unsafeIndex ( pos ) == w1
155155 && P.unsafeIndex (plusPtr pos 1) == w2
156156 && Var.getInnerWidth pos2 end == 0
157157 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
159159 else
160160 eerr row col toError
161161
162162
163163k3 :: Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
164164k3 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 ->
166166 let !pos3 = plusPtr pos 3 in
167167 if pos3 <= end
168168 && P.unsafeIndex ( pos ) == w1
@@ -170,14 +170,14 @@ k3 w1 w2 w3 toError =
170170 && P.unsafeIndex (plusPtr pos 2) == w3
171171 && Var.getInnerWidth pos3 end == 0
172172 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
174174 else
175175 eerr row col toError
176176
177177
178178k4 :: Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
179179k4 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 ->
181181 let !pos4 = plusPtr pos 4 in
182182 if pos4 <= end
183183 && P.unsafeIndex ( pos ) == w1
@@ -186,14 +186,14 @@ k4 w1 w2 w3 w4 toError =
186186 && P.unsafeIndex (plusPtr pos 3) == w4
187187 && Var.getInnerWidth pos4 end == 0
188188 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
190190 else
191191 eerr row col toError
192192
193193
194194k5 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
195195k5 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 ->
197197 let !pos5 = plusPtr pos 5 in
198198 if pos5 <= end
199199 && P.unsafeIndex ( pos ) == w1
@@ -203,14 +203,14 @@ k5 w1 w2 w3 w4 w5 toError =
203203 && P.unsafeIndex (plusPtr pos 4) == w5
204204 && Var.getInnerWidth pos5 end == 0
205205 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
207207 else
208208 eerr row col toError
209209
210210
211211k6 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
212212k6 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 ->
214214 let !pos6 = plusPtr pos 6 in
215215 if pos6 <= end
216216 && P.unsafeIndex ( pos ) == w1
@@ -221,14 +221,14 @@ k6 w1 w2 w3 w4 w5 w6 toError =
221221 && P.unsafeIndex (plusPtr pos 5) == w6
222222 && Var.getInnerWidth pos6 end == 0
223223 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
225225 else
226226 eerr row col toError
227227
228228
229229k7 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
230230k7 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 ->
232232 let !pos7 = plusPtr pos 7 in
233233 if pos7 <= end
234234 && P.unsafeIndex ( pos ) == w1
@@ -240,14 +240,14 @@ k7 w1 w2 w3 w4 w5 w6 w7 toError =
240240 && P.unsafeIndex (plusPtr pos 6) == w7
241241 && Var.getInnerWidth pos7 end == 0
242242 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
244244 else
245245 eerr row col toError
246246
247247
248248k8 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> (Row -> Col -> x) -> Parser x ()
249249k8 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 ->
251251 let !pos8 = plusPtr pos 8 in
252252 if pos8 <= end
253253 && P.unsafeIndex ( pos ) == w1
@@ -260,6 +260,6 @@ k8 w1 w2 w3 w4 w5 w6 w7 w8 toError =
260260 && P.unsafeIndex (plusPtr pos 7) == w8
261261 && Var.getInnerWidth pos8 end == 0
262262 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
264264 else
265265 eerr row col toError
compiler/src/Parse/Shader.hs+3−3
@@ -44,7 +44,7 @@ shader start@(A.Position row col) =
4444
4545parseBlock :: Parser E.Expr String
4646parseBlock =
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 ->
4848 let
4949 !pos6 = plusPtr pos 6
5050 in
@@ -65,7 +65,7 @@ parseBlock =
6565 let
6666 !block = Utf8.fromPtr pos6 newPos
6767 !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)
6969 in
7070 cok source newState
7171
@@ -130,7 +130,7 @@ parseGlsl startRow startCol src =
130130
131131failure :: Row -> Col -> String -> Parser E.Expr a
132132failure row col msg =
133− P.Parser $ \(P.State _ _ _ _ _) _ _ cerr _ ->
133+ P.Parser $ \(P.State _ _ _ _ _ _) _ _ cerr _ ->
134134 cerr row col (E.ShaderProblem msg)
135135
136136
compiler/src/Parse/Symbol.hs+2−2
@@ -33,7 +33,7 @@ data BadOperator
3333
3434operator :: (Row -> Col -> x) -> (BadOperator -> Row -> Col -> x) -> Parser x Name.Name
3535operator 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 ->
3737 let !newPos = chompOps pos end in
3838 if pos == newPos then
3939 eerr row col toExpectation
@@ -48,7 +48,7 @@ operator toExpectation toError =
4848 op ->
4949 let
5050 !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
5252 in
5353 cok op newState
5454