on master help sign in
Fix implementation of noSpace, checkSpace, checkAligned, and checkFreshLine
032555aEvan Czaplicki
compiler/src/Parse/Utils.hs+32−29
@@ -42,32 +42,35 @@ spaces =
42
42
43noSpace :: A.Position -> SPos -> Parser ()
43noSpace :: A.Position -> SPos -> Parser ()
44noSpace pos (SPos spos) =
44noSpace pos (SPos spos) =
45+ P.Parser $ \state@(P.State _ _ _ r c context) _ eok _ eerr ->
45− if pos == spos
46+ if pos == spos
46− then return ()
47+ then eok () state
47− else error "TODO what is this again? can it be written better?"
48+ else eerr r c context (E.TODO "noSpace")
48
49
49
50
50checkSpace :: SPos -> Parser ()
51checkSpace :: SPos -> Parser ()
51checkSpace (SPos (A.Position _ col)) =
52checkSpace (SPos (A.Position _ col)) =
52− do indent <- P.getIndent
53+ P.Parser $ \state@(P.State _ _ indent r c context) _ eok _ eerr ->
53− if col > indent && col > 1
54+ if col > indent && col > 1
54− then return ()
55+ then eok () state
55− else error "TODO what is this again? can it be written better?"
56+ else eerr r c context (E.TODO "checkSpace")
56
57
57
58
58checkAligned :: SPos -> Parser ()
59checkAligned :: SPos -> Parser ()
59checkAligned (SPos (A.Position _ col)) =
60checkAligned (SPos (A.Position _ col)) =
60− do indent <- P.getIndent
61+ P.Parser $ \state@(P.State _ _ indent r c context) _ eok _ eerr ->
61− if col == indent
62+ if col == indent
62− then return ()
63+ then eok () state
63− else error "TODO what is this again? can it be written better?"
64+ else eerr r c context (E.TODO "checkAligned")
64
65
65
66
66checkFreshLine :: SPos -> Parser ()
67checkFreshLine :: SPos -> Parser ()
67checkFreshLine (SPos (A.Position _ col)) =
68checkFreshLine (SPos (A.Position _ col)) =
69+ P.Parser $ \state@(P.State _ _ _ r c context) _ eok _ eerr ->
68− if col == 1
70+ if col == 1
69− then return ()
71+ then eok () state
70− else error "TODO what is this again?"
72+ else eerr r c context (E.TODO "checkFreshLine")
73+
71
74
72
75
73-- WHITESPACE
76-- WHITESPACE
@@ -94,14 +97,14 @@ whitespace =
94 HasTab ->
97 HasTab ->
95 eerr newRow newCol ctx E.NoTabs
98 eerr newRow newCol ctx E.NoTabs
96
99
97− UnendingMultiComment ->
100+ UnendingMultiComment sr sc ->
98− eerr newRow newCol ctx E.MultiCommentEnd
101+ eerr newRow newCol ctx (E.MultiCommentEnd sr sc)
99
102
100
103
101data Status
104data Status
102 = Good
105 = Good
103 | HasTab
106 | HasTab
104− | UnendingMultiComment
107+ | UnendingMultiComment Word16 Word16
105
108
106
109
107
110
@@ -180,7 +183,7 @@ eatMultiComment pos end row col =
180 if yesDash && noBar then
183 if yesDash && noBar then
181 let
184 let
182 (# status, newPos, newRow, newCol #) =
185 (# status, newPos, newRow, newCol #) =
183− eatMultiCommentHelp pos2 end row (col + 2) 1
186+ eatMultiCommentHelp pos2 end row (col + 2) 1 row col
184 in
187 in
185 case status of
188 case status of
186 Good ->
189 Good ->
@@ -189,35 +192,35 @@ eatMultiComment pos end row col =
189 HasTab ->
192 HasTab ->
190 (# status, newPos, newRow, newCol #)
193 (# status, newPos, newRow, newCol #)
191
194
192− UnendingMultiComment ->
195+ UnendingMultiComment _ _ ->
193 (# status, newPos, newRow, newCol #)
196 (# status, newPos, newRow, newCol #)
194
197
195 else
198 else
196 (# Good, pos, row, col #)
199 (# Good, pos, row, col #)
197
200
198
201
199−eatMultiCommentHelp :: Ptr Word8 -> Ptr Word8 -> Word16 -> Word16 -> Int -> (# Status, Ptr Word8, Word16, Word16 #)
202+eatMultiCommentHelp :: Ptr Word8 -> Ptr Word8 -> Word16 -> Word16 -> Int -> Word16 -> Word16 -> (# Status, Ptr Word8, Word16, Word16 #)
200−eatMultiCommentHelp pos end row col openComments =
203+eatMultiCommentHelp pos end row col openComments sr sc =
201 if pos >= end then
204 if pos >= end then
202− (# UnendingMultiComment, pos, row, col #)
205+ (# UnendingMultiComment sr sc, pos, row, col #)
203
206
204 else
207 else
205 let !word = P.unsafeIndex pos in
208 let !word = P.unsafeIndex pos in
206 if word == 0x0A {- \n -} then
209 if word == 0x0A {- \n -} then
207− eatMultiCommentHelp (plusPtr pos 1) end (row + 1) 1 openComments
210+ eatMultiCommentHelp (plusPtr pos 1) end (row + 1) 1 openComments sr sc
208
211
209 else if word == 0x2D {- - -} && P.isWord (plusPtr pos 1) end 0x7D {- } -} then
212 else if word == 0x2D {- - -} && P.isWord (plusPtr pos 1) end 0x7D {- } -} then
210 if openComments == 1 then
213 if openComments == 1 then
211 (# Good, plusPtr pos 2, row, col + 2 #)
214 (# Good, plusPtr pos 2, row, col + 2 #)
212 else
215 else
213− eatMultiCommentHelp (plusPtr pos 2) end row (col + 2) (openComments - 1)
216+ eatMultiCommentHelp (plusPtr pos 2) end row (col + 2) (openComments - 1) sr sc
214
217
215 else if word == 0x7B {- { -} && P.isWord (plusPtr pos 1) end 0x2D {- - -} then
218 else if word == 0x7B {- { -} && P.isWord (plusPtr pos 1) end 0x2D {- - -} then
216− eatMultiCommentHelp (plusPtr pos 2) end row (col + 2) (openComments + 1)
219+ eatMultiCommentHelp (plusPtr pos 2) end row (col + 2) (openComments + 1) sr sc
217
220
218 else
221 else
219 let !newPos = plusPtr pos (P.getCharWidth pos end word) in
222 let !newPos = plusPtr pos (P.getCharWidth pos end word) in
220− eatMultiCommentHelp newPos end row (col + 1) openComments
223+ eatMultiCommentHelp newPos end row (col + 1) openComments sr sc
221
224
222
225
223
226
@@ -237,7 +240,7 @@ docComment =
237 then
240 then
238 let
241 let
239 (# status, newPos, newRow, newCol #) =
242 (# status, newPos, newRow, newCol #) =
240− eatMultiCommentHelp pos3 end row col 1
243+ eatMultiCommentHelp pos3 end row (col + 3) 1 row col
241 in
244 in
242 case status of
245 case status of
243 Good ->
246 Good ->
@@ -249,8 +252,8 @@ docComment =
249 HasTab ->
252 HasTab ->
250 eerr newRow newCol ctx E.NoTabs
253 eerr newRow newCol ctx E.NoTabs
251
254
252− UnendingMultiComment ->
255+ UnendingMultiComment sr sc ->
253− eerr newRow newCol ctx E.MultiCommentEnd
256+ eerr newRow newCol ctx (E.MultiCommentEnd sr sc)
254
257
255 else
258 else
256 eerr row col ctx E.DocComment
259 eerr row col ctx E.DocComment