@@ -3,11 +3,12 @@
3module Parse.Primitives
3module Parse.Primitives
5 , run, runAt
5 , run, runAt
6− , try, failure, deadend, expecting, endOfFile
6+ , try, failure, deadend, hint, endOfFile
8 , symbol, keyword, keywords
8 , symbol, keyword, keywords
9 , lowVar, capVar, infixOp
9 , lowVar, capVar, infixOp
10 , getPosition, getCol
10 , getPosition, getCol
11+ , getContext, pushContext, popContext
11 , getIndent, setIndent
12 , getIndent, setIndent
12 , SPos(..), whitespace
13 , SPos(..), whitespace
13 , docComment, chompUntilDocs
14 , docComment, chompUntilDocs
@@ -38,8 +39,11 @@ import qualified AST.Helpers as Help (isSymbol)
38import qualified AST.Literal as L
39import qualified AST.Literal as L
39import qualified Reporting.Annotation as A
40import qualified Reporting.Annotation as A
40import qualified Reporting.Error.Syntax as E
41import qualified Reporting.Error.Syntax as E
41−import Reporting.Error.Syntax ( ParseError(..), Problem(..), Theory(..) )
42import qualified Reporting.Region as Region
42import qualified Reporting.Region as Region
43+import Reporting.Error.Syntax
44+ ( ParseError(..), Problem(..), Theory(..)
45+ , Context(..), BadOp(..)
@@ -51,10 +55,10 @@ newtype Parser a =
52 :: forall b.
56 :: forall b.
54− -> (a -> State -> b) -- consumed ok
58+ -> (a -> State -> ParseError -> b) -- consumed ok
55− -> (ParseError -> b) -- consumed err
59+ -> ( ParseError -> b) -- consumed err
56− -> (a -> State -> b) -- empty ok
60+ -> (a -> State -> ParseError -> b) -- empty ok
57− -> (ParseError -> b) -- empty err
61+ -> ( ParseError -> b) -- empty err
@@ -67,24 +71,20 @@ data State =
67 , _indent :: !Int
71 , _indent :: !Int
68 , _row :: !Int
72 , _row :: !Int
69 , _col :: !Int
73 , _col :: !Int
74+ , _context :: [Context]
73−data Result a
78+{-# NOINLINE noError #-}
74− = Ok a State
79+noError :: ParseError
75− | Err ParseError
80+noError =
76−
81+ ParseError 0 0 (Theories [] [])
78−{-# INLINE noTheory #-}
79−noTheory :: Int -> Int -> ParseError
81− ParseError row col (Theories [])
84−{-# INLINE loneTheory #-}
84+{-# INLINE expect #-}
85−loneTheory :: Int -> Int -> Theory -> ParseError
85+expect :: Int -> Int -> [Context] -> Theory -> ParseError
86−loneTheory row col theory =
86+expect row col ctx theory =
87− ParseError row col (Theories [theory])
87+ ParseError row col (Theories ctx [theory])
@@ -98,8 +98,8 @@ run parser text =
99runAt :: Int -> Int -> Parser a -> Text -> Either (A.Located E.Error) a
99runAt :: Int -> Int -> Parser a -> Text -> Either (A.Located E.Error) a
100runAt sRow sCol parser (Text.Text array offset length) =
100runAt sRow sCol parser (Text.Text array offset length) =
101− case _run parser (State array offset length 0 sRow sCol) Ok Err Ok Err of
101+ case _run parser (State array offset length 0 sRow sCol []) Ok Err Ok Err of
102− Ok value _ ->
102+ Ok value _ _ ->
103 Right value
103 Right value
105 Err (ParseError row col problem) ->
105 Err (ParseError row col problem) ->
@@ -110,6 +110,11 @@ runAt sRow sCol parser (Text.Text array offset length) =
110 Left (A.A region (E.Parse problem))
110 Left (A.A region (E.Parse problem))
114+ = Ok a State ParseError
114-- COMBINATORS
119-- COMBINATORS
@@ -122,7 +127,7 @@ try parser =
123failure :: Problem -> Parser a
128failure :: Problem -> Parser a
124failure problem =
129failure problem =
125− Parser $ \(State _ _ _ _ row col) _ cerr _ _ ->
130+ Parser $ \(State _ _ _ _ row col _) _ cerr _ _ ->
126 cerr (ParseError row col problem)
131 cerr (ParseError row col problem)
@@ -132,33 +137,33 @@ shaderFailure row col msg =
132 cerr (ParseError row col (BadShader msg))
137 cerr (ParseError row col (BadShader msg))
135−deadend :: Theory -> Parser a
140+deadend :: [Theory] -> Parser a
136−deadend theory =
141+deadend thrys =
137− Parser $ \(State _ _ _ _ row col) _ _ _ eerr ->
142+ Parser $ \(State _ _ _ _ row col ctx) _ _ _ eerr ->
138− eerr (loneTheory row col theory)
143+ eerr (ParseError row col (Theories ctx thrys))
141−expecting :: Text -> Parser a -> Parser a
146+hint :: E.Next -> Parser a -> Parser a
142−expecting description parser =
147+hint next parser =
143− Parser $ \state@(State _ _ _ _ row col) cok cerr eok eerr ->
148+ Parser $ \state@(State _ _ _ _ row col ctx) cok cerr eok eerr ->
145− eok' x s =
150+ eok' x s _ =
146− eok x s
151+ eok x s (expect row col ctx (Expecting next))
148 eerr' _ =
153 eerr' _ =
149− eerr (loneTheory row col (Expecting description))
154+ eerr (expect row col ctx (Expecting next))
151 _run parser state cok cerr eok' eerr'
156 _run parser state cok cerr eok' eerr'
154endOfFile :: Parser ()
159endOfFile :: Parser ()
155endOfFile =
160endOfFile =
156− Parser $ \state@(State _ _ length _ row col) _ _ eok eerr ->
161+ Parser $ \state@(State _ _ length _ row col ctx) _ _ eok eerr ->
157 if length == 0 then
162 if length == 0 then
158− eok () state
163+ eok () state (expect row col ctx EndOfFile)
161− eerr (noTheory row col)
166+ eerr (expect row col ctx EndOfFile)
@@ -169,8 +174,8 @@ instance Functor Parser where
169 fmap f parser =
174 fmap f parser =
170 Parser $ \state cok cerr eok eerr ->
175 Parser $ \state cok cerr eok eerr ->
172− cok' x s = cok (f x) s
177+ cok' x s e = cok (f x) s e
173− eok' x s = eok (f x) s
178+ eok' x s e = eok (f x) s e
175 _run parser state cok' cerr eok' eerr
180 _run parser state cok' cerr eok' eerr
@@ -196,18 +201,18 @@ oneOf parsers =
197allTheOptionsFailed :: Parser a
202allTheOptionsFailed :: Parser a
198allTheOptionsFailed =
203allTheOptionsFailed =
199− Parser $ \(State _ _ _ _ row col) _ _ _ eerr ->
204+ Parser $ \_ _ _ _ eerr ->
200− eerr (noTheory row col)
205+ eerr noError
203oneOfHelp :: Parser a -> Parser a -> Parser a
208oneOfHelp :: Parser a -> Parser a -> Parser a
204oneOfHelp parser1 parser2 =
209oneOfHelp parser1 parser2 =
205 Parser $ \state cok cerr eok eerr ->
210 Parser $ \state cok cerr eok eerr ->
207− eerr1 err1 =
212+ eerr1 e1 =
209− eok2 y state' = eok y state'
214+ eok2 y s e2 = eok y s (mergeErrors e1 e2)
210− eerr2 err2 = eerr (mergeErrors err1 err2)
215+ eerr2 e2 = eerr (mergeErrors e1 e2)
212 _run parser2 state cok cerr eok2 eerr2
217 _run parser2 state cok cerr eok2 eerr2
@@ -215,16 +220,30 @@ oneOfHelp parser1 parser2 =
217mergeErrors :: ParseError -> ParseError -> ParseError
222mergeErrors :: ParseError -> ParseError -> ParseError
218−mergeErrors error1@(ParseError row col problem1) error2@(ParseError _ _ problem2) =
223+mergeErrors e1@(ParseError r1 c1 p1) e2@(ParseError r2 c2 p2) =
219− case (problem1, problem2) of
224+ case compare r1 r2 of
220− (Theories theories1, Theories theories2) ->
225+ LT -> e2
221− ParseError row col (Theories (theories1 ++ theories2))
226+ GT -> e1
228+ case compare c1 c2 of
233+ (Theories _ [], Theories _ _) ->
236+ (Theories _ _, Theories _ []) ->
223− (Theories _, _) ->
239+ (Theories ctx ts1, Theories _ ts2) ->
224− error2
240+ ParseError r1 c1 (Theories ctx (ts1 ++ ts2))
242+ (Theories _ _, _) ->
226− (_, _) ->
245+ (_, _) ->
@@ -234,18 +253,26 @@ mergeErrors error1@(ParseError row col problem1) error2@(ParseError _ _ problem2
234instance Monad Parser where
253instance Monad Parser where
235 return value =
254 return value =
236 Parser $ \state _ _ eok _ ->
255 Parser $ \state _ _ eok _ ->
237− eok value state
256+ eok value state noError
239 parser >>= callback =
258 parser >>= callback =
240 Parser $ \state cok cerr eok eerr ->
259 Parser $ \state cok cerr eok eerr ->
242− cok' value newState =
261+ cok1 x s1 e1 =
263+ eok2 y s2 e2 = cok y s2 (mergeErrors e1 e2)
264+ eerr2 e2 = cerr (mergeErrors e1 e2)
243− _run (callback value) newState cok cerr cok cerr
266+ _run (callback x) s1 cok cerr eok2 eerr2
245− eok' value newState =
268+ eok1 x s1 e1 =
270+ eok2 y s2 e2 = eok y s2 (mergeErrors e1 e2)
271+ eerr2 e2 = eerr (mergeErrors e1 e2)
246− _run (callback value) newState cok cerr eok eerr
273+ _run (callback x) s1 cok cerr eok2 eerr2
248− _run parser state cok' cerr eok' eerr
275+ _run parser state cok1 cerr eok1 eerr
@@ -254,16 +281,19 @@ instance Monad Parser where
255symbol :: Text -> Parser ()
282symbol :: Text -> Parser ()
256symbol sym@(Text.Text tArray tOffset tLen) =
283symbol sym@(Text.Text tArray tOffset tLen) =
257− Parser $ \(State array offset length indent row col) cok _ _ eerr ->
284+ Parser $ \(State array offset length indent row col ctx) cok _ _ eerr ->
258 if tLen <= length && Text.equal tArray tOffset array offset tLen then
285 if tLen <= length && Text.equal tArray tOffset array offset tLen then
260 (# newRow, newCol #) =
287 (# newRow, newCol #) =
261 moveCursor tArray tOffset tLen row col
288 moveCursor tArray tOffset tLen row col
291+ State array (offset + tLen) (length - tLen) indent newRow newCol ctx
263− cok () (State array (offset + tLen) (length - tLen) indent newRow newCol)
293+ cok () newState noError
266− eerr (loneTheory row col (Symbol sym))
296+ eerr (expect row col ctx (Symbol sym))
269moveCursor :: Text.Array -> Int -> Int -> Int -> Int -> (# Int, Int #)
299moveCursor :: Text.Array -> Int -> Int -> Int -> Int -> (# Int, Int #)
@@ -291,21 +321,24 @@ moveCursor array offset length row col =
292keyword :: Text -> Parser ()
322keyword :: Text -> Parser ()
293keyword kwd@(Text.Text tArray tOffset tLen) =
323keyword kwd@(Text.Text tArray tOffset tLen) =
294− Parser $ \(State array offset length indent row col) cok _ _ eerr ->
324+ Parser $ \(State array offset length indent row col ctx) cok _ _ eerr ->
295 if tLen <= length && Text.equal tArray tOffset array offset tLen then
325 if tLen <= length && Text.equal tArray tOffset array offset tLen then
297 if isInnerVarChar (peekChar array (offset + tLen)) then
327 if isInnerVarChar (peekChar array (offset + tLen)) then
298− eerr (loneTheory row col (Keyword kwd))
328+ eerr (expect row col ctx (Keyword kwd))
302 (# newRow, newCol #) =
332 (# newRow, newCol #) =
303 moveCursor tArray tOffset tLen row col
333 moveCursor tArray tOffset tLen row col
336+ State array (offset + tLen) (length - tLen) indent newRow newCol ctx
305− cok () (State array (offset + tLen) (length - tLen) indent newRow newCol)
338+ cok () newState noError
308− eerr (loneTheory row col (Keyword kwd))
341+ eerr (expect row col ctx (Keyword kwd))
311keywords :: Set.Set Text
344keywords :: Set.Set Text
@@ -328,20 +361,20 @@ keywords =
329lowVar :: Parser Text.Text
362lowVar :: Parser Text.Text
331− varPrim Char.isLower
364+ varPrim LowVar Char.isLower
334capVar :: Parser Text.Text
367capVar :: Parser Text.Text
336− varPrim Char.isUpper
369+ varPrim CapVar Char.isUpper
339{-# INLINE varPrim #-}
372{-# INLINE varPrim #-}
340−varPrim :: (Char -> Bool) -> Parser Text.Text
373+varPrim :: Theory -> (Char -> Bool) -> Parser Text.Text
341−varPrim isGoodFirstChar =
374+varPrim theory isGoodFirstChar =
342− Parser $ \(State array offset length indent row col) cok _ _ eerr ->
375+ Parser $ \(State array offset length indent row col ctx) cok _ _ eerr ->
343 if length == 0 then
376 if length == 0 then
344− eerr (loneTheory row col Variable)
377+ eerr (expect row col ctx theory)
@@ -356,12 +389,12 @@ varPrim isGoodFirstChar =
356 copyText array offset (newOffset - offset)
389 copyText array offset (newOffset - offset)
358 if Set.member copiedText keywords then
391 if Set.member copiedText keywords then
359− eerr (loneTheory row newCol Variable)
392+ eerr (expect row newCol ctx theory)
361− cok copiedText (State array newOffset newLength indent row newCol)
394+ cok copiedText (State array newOffset newLength indent row newCol ctx) noError
364− eerr (loneTheory row col Variable)
397+ eerr (expect row col ctx theory)
367{-# INLINE copyText #-}
400{-# INLINE copyText #-}
@@ -428,16 +461,16 @@ isInnerVarChar char =
429infixOp :: Parser Text
462infixOp :: Parser Text
431− Parser $ \(State array offset length indent row col) cok cerr _ eerr ->
464+ Parser $ \(State array offset length indent row col ctx) cok cerr _ eerr ->
432 if length == 0 then
465 if length == 0 then
433− eerr (loneTheory row col InfixOp)
466+ eerr (expect row col ctx InfixOp)
437 (Text.Iter char size) = peek array offset
470 (Text.Iter char size) = peek array offset
439 if not (Help.isSymbol char) then
472 if not (Help.isSymbol char) then
440− eerr (loneTheory row col InfixOp)
473+ eerr (expect row col ctx InfixOp)
442 case infixOpHelp array (offset + size) (length - size) row (col + 1) of
475 case infixOpHelp array (offset + size) (length - size) row (col + 1) of
443 Left err ->
476 Left err ->
@@ -445,12 +478,12 @@ infixOp =
446 Right ( newOffset, newLength, newCol ) ->
479 Right ( newOffset, newLength, newCol ) ->
447 case copyText array offset (newOffset - offset) of
480 case copyText array offset (newOffset - offset) of
448− "=" -> cerr (ParseError row col Dot)
481+ "." -> cerr (ParseError row col (BadOp Dot ctx))
449− "|" -> cerr (ParseError row col Pipe)
482+ "|" -> cerr (ParseError row col (BadOp Pipe ctx))
450− ":" -> cerr (ParseError row col Arrow)
483+ "->" -> cerr (ParseError row col (BadOp Arrow ctx))
451− "." -> cerr (ParseError row col Equals)
484+ "=" -> cerr (ParseError row col (BadOp Equals ctx))
452− "->" -> cerr (ParseError row col HasType)
485+ ":" -> cerr (ParseError row col (BadOp HasType ctx))
453− op -> cok op (State array newOffset newLength indent row newCol)
486+ op -> cok op (State array newOffset newLength indent row newCol ctx) noError
456infixOpHelp :: Text.Array -> Int -> Int -> Int -> Int -> Either ParseError (Int, Int, Int)
489infixOpHelp :: Text.Array -> Int -> Int -> Int -> Int -> Either ParseError (Int, Int, Int)
@@ -474,26 +507,44 @@ infixOpHelp array offset length row col =
475getPosition :: Parser Region.Position
508getPosition :: Parser Region.Position
476getPosition =
509getPosition =
477− Parser $ \state@(State _ _ _ _ row col) _ _ eok _ ->
510+ Parser $ \state@(State _ _ _ _ row col _) _ _ eok _ ->
478− eok (Region.Position row col) state
511+ eok (Region.Position row col) state noError
481getIndent :: Parser Int
514getIndent :: Parser Int
482getIndent =
515getIndent =
483− Parser $ \state@(State _ _ _ indent _ _) _ _ eok _ ->
516+ Parser $ \state@(State _ _ _ indent _ _ _) _ _ eok _ ->
484− eok indent state
517+ eok indent state noError
487getCol :: Parser Int
520getCol :: Parser Int
489− Parser $ \state@(State _ _ _ _ _ col) _ _ eok _ ->
522+ Parser $ \state@(State _ _ _ _ _ col _) _ _ eok _ ->
490− eok col state
523+ eok col state noError
526+getContext :: Parser [E.Context]
528+ Parser $ \state@(State _ _ _ _ _ _ ctx) _ _ eok _ ->
529+ eok ctx state noError
532+pushContext :: E.Context -> Parser ()
534+ Parser $ \state@(State _ _ _ _ _ _ context) _ _ eok _ ->
535+ eok () (state { _context = ctx : context }) noError
538+popContext :: a -> Parser a
540+ Parser $ \state@(State _ _ _ _ _ _ context) _ _ eok _ ->
541+ eok value (state { _context = tail context }) noError
493setIndent :: Int -> Parser ()
544setIndent :: Int -> Parser ()
494setIndent indent =
545setIndent indent =
495 Parser $ \state _ _ eok _ ->
546 Parser $ \state _ _ eok _ ->
496− eok () (state { _indent = indent })
547+ eok () (state { _indent = indent }) noError
@@ -506,7 +557,7 @@ newtype SPos =
507whitespace :: Parser SPos
558whitespace :: Parser SPos
508whitespace =
559whitespace =
509− Parser $ \(State array offset length indent row col) cok cerr _ _ ->
560+ Parser $ \(State array offset length indent row col ctx) cok cerr _ _ ->
510 case eatSpaces array offset length row col of
561 case eatSpaces array offset length row col of
511 Left err ->
562 Left err ->
@@ -514,7 +565,8 @@ whitespace =
514 Right (newOffset, newLength, newRow, newCol) ->
565 Right (newOffset, newLength, newRow, newCol) ->
516 (SPos (Region.Position newRow newCol))
567 (SPos (Region.Position newRow newCol))
517− (State array newOffset newLength indent newRow newCol)
568+ (State array newOffset newLength indent newRow newCol ctx)
520eatSpaces :: Text.Array -> Int -> Int -> Int -> Int -> Either ParseError ( Int, Int, Int, Int )
572eatSpaces :: Text.Array -> Int -> Int -> Int -> Int -> Either ParseError ( Int, Int, Int, Int )
@@ -646,7 +698,7 @@ eatMultiCommentHelp array offset length row col openComments =
646docComment :: Parser Text
698docComment :: Parser Text
647docComment =
699docComment =
648 do symbol "{-|"
700 do symbol "{-|"
649− Parser $ \(State array offset length indent row col) cok cerr _ _ ->
701+ Parser $ \(State array offset length indent row col ctx) cok cerr _ _ ->
650 case eatMultiCommentHelp array offset length row col 1 of
702 case eatMultiCommentHelp array offset length row col 1 of
651 Left err ->
703 Left err ->
@@ -654,17 +706,21 @@ docComment =
654 Right (newOffset, newLength, newRow, newCol) ->
706 Right (newOffset, newLength, newRow, newCol) ->
656 (copyText array offset (newOffset - offset))
708 (copyText array offset (newOffset - offset))
657− (State array newOffset newLength indent newRow newCol)
709+ (State array newOffset newLength indent newRow newCol ctx)
660chompUntilDocs :: Parser Bool
713chompUntilDocs :: Parser Bool
661chompUntilDocs =
714chompUntilDocs =
662− Parser $ \(State array offset length indent row col) cok _ _ _ ->
715+ Parser $ \(State array offset length indent row col ctx) cok _ _ _ ->
664 (# isStart, newOffset, newLength, newRow, newCol #) =
717 (# isStart, newOffset, newLength, newRow, newCol #) =
665 eatDocs array offset length row col
718 eatDocs array offset length row col
721+ State array newOffset newLength indent newRow newCol ctx
667− cok isStart (State array newOffset newLength indent newRow newCol)
723+ cok isStart newState noError
670eatDocs :: Text.Array -> Int -> Int -> Int -> Int -> (# Bool, Int, Int, Int, Int #)
726eatDocs :: Text.Array -> Int -> Int -> Int -> Int -> (# Bool, Int, Int, Int, Int #)
@@ -705,16 +761,16 @@ isDocsStart array offset length =
706string :: Parser Text.Text
762string :: Parser Text.Text
708− Parser $ \(State array offset length indent row col) cok cerr _ eerr ->
764+ Parser $ \(State array offset length indent row col ctx) cok cerr _ eerr ->
709 if length == 0 then
765 if length == 0 then
710− eerr (noTheory row col)
766+ eerr noError
714 !word = Text.unsafeIndex array offset
770 !word = Text.unsafeIndex array offset
716 if word /= 0x0022 {- " -} then
772 if word /= 0x0022 {- " -} then
717− eerr (noTheory row col)
773+ eerr noError
@@ -731,7 +787,8 @@ string =
731 Right ( newOffset, newLength, newCol, builder ) ->
787 Right ( newOffset, newLength, newCol, builder ) ->
733 (LT.toStrict (LB.toLazyText builder))
789 (LT.toStrict (LB.toLazyText builder))
734− (State array newOffset newLength indent row newCol)
790+ (State array newOffset newLength indent row newCol ctx)
737{-# INLINE isQuote #-}
794{-# INLINE isQuote #-}
@@ -880,13 +937,13 @@ multiString array offset length row col initialOffset builder =
881character :: Parser Text
938character :: Parser Text
882character =
939character =
883− Parser $ \(State array offset length indent row col) cok cerr _ eerr ->
940+ Parser $ \(State array offset length indent row col ctx) cok cerr _ eerr ->
884 if length == 0 then
941 if length == 0 then
885− eerr (noTheory row col)
942+ eerr noError
888 if Text.unsafeIndex array offset /= 0x0027 {- ' -} then
945 if Text.unsafeIndex array offset /= 0x0027 {- ' -} then
889− eerr (noTheory row col)
946+ eerr noError
891 else if length < 3 then
948 else if length < 3 then
892 cerr (ParseError row col BadChar)
949 cerr (ParseError row col BadChar)
@@ -907,7 +964,8 @@ character =
909 (copyText array (offset + 1) size)
966 (copyText array (offset + 1) size)
910− (State array (newOffset + 1) (newLength - 1) indent row endCol)
967+ (State array (newOffset + 1) (newLength - 1) indent row endCol ctx)
913characterHelp :: Text.Array -> Int -> Int -> Int -> Int -> Either ParseError ( Int, Int )
971characterHelp :: Text.Array -> Int -> Int -> Int -> Int -> Either ParseError ( Int, Int )
@@ -938,9 +996,9 @@ characterHelp array offset length row col =
939digit :: Parser Int
997digit :: Parser Int
941− Parser $ \(State array offset length indent row col) cok _ _ eerr ->
999+ Parser $ \(State array offset length indent row col ctx) cok _ _ eerr ->
942 if length == 0 then
1000 if length == 0 then
943− eerr (loneTheory row col Digit)
1001+ eerr (expect row col ctx Digit)
@@ -949,9 +1007,10 @@ digit =
949 if isDigit word then
1007 if isDigit word then
951 (fromIntegral (word - 0x0030))
1009 (fromIntegral (word - 0x0030))
952− (State array (offset + 1) (length - 1) indent row (col + 1))
1010+ (State array (offset + 1) (length - 1) indent row (col + 1) ctx)
954− eerr (loneTheory row col Digit)
1013+ eerr (expect row col ctx Digit)
@@ -960,16 +1019,16 @@ digit =
961number :: Parser L.Literal
1020number :: Parser L.Literal
963− Parser $ \(State array offset length indent row col) cok cerr _ eerr ->
1022+ Parser $ \(State array offset length indent row col ctx) cok cerr _ eerr ->
964 if length == 0 then
1023 if length == 0 then
965− eerr (noTheory row col)
1024+ eerr noError
969 !word = Text.unsafeIndex array offset
1028 !word = Text.unsafeIndex array offset
971 if not (isDigit word) then
1030 if not (isDigit word) then
972− eerr (noTheory row col)
1031+ eerr noError
@@ -988,7 +1047,10 @@ number =
988 cerr (ParseError row (col + (newOffset - offset)) BadNumberEnd)
1047 cerr (ParseError row (col + (newOffset - offset)) BadNumberEnd)
991− cok literal (State array newOffset newLength indent row (col + (newOffset - offset)))
1052+ (State array newOffset newLength indent row (col + (newOffset - offset)) ctx)
994isDirtyEnd :: Text.Array -> Int -> Int -> Bool
1056isDirtyEnd :: Text.Array -> Int -> Int -> Bool
@@ -1182,7 +1244,7 @@ readFloat array startOffset endOffset =
1182shaderSource :: Parser Text
1244shaderSource :: Parser Text
1183shaderSource =
1245shaderSource =
1184 do symbol "[glsl|"
1246 do symbol "[glsl|"
1185− Parser $ \(State array offset length indent row col) cok cerr _ _ ->
1247+ Parser $ \(State array offset length indent row col ctx) cok cerr _ _ ->
1186 case eatShader array offset length row col of
1248 case eatShader array offset length row col of
1187 Nothing ->
1249 Nothing ->
1188 cerr (ParseError row col EndOfFile_Shader)
1250 cerr (ParseError row col EndOfFile_Shader)
@@ -1190,10 +1252,10 @@ shaderSource =
1190 Just ( shaderEndOffset, newRow, newCol ) ->
1252 Just ( shaderEndOffset, newRow, newCol ) ->
1192 !size = shaderEndOffset - offset
1254 !size = shaderEndOffset - offset
1256+ State array (shaderEndOffset + 2) (length - size - 2) indent newRow newCol ctx
1195− (copyText array offset size)
1258+ cok (copyText array offset size) newState noError
1196− (State array (shaderEndOffset + 2) (length - size - 2) indent newRow newCol)
1199eatShader :: Text.Array -> Int -> Int -> Int -> Int -> Maybe (Int, Int, Int)
1261eatShader :: Text.Array -> Int -> Int -> Int -> Int -> Maybe (Int, Int, Int)