on master help sign in
Make it cheaper to parse symbols
commit6397e120ac921949afbd2835f872618f89a8504d authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 4 Oct 2017, 22:49 (9 years ago) parent765f61a
3 files changed+46−22
src/Parse/Helpers.hs+15−17 src/Parse/Module.hs+14−2 src/Parse/Primitives.hs+17−3
src/Parse/Helpers.hs+15−17
@@ -71,55 +71,55 @@ qualifiedVarHelp altEnding vars =
7171-- COMMON SYMBOLS
7272
7373
74−{-# INLINE equals #-}
74+{-# NOINLINE equals #-}
7575equals :: Parser ()
7676equals =
7777 symbol "="
7878
7979
80−{-# INLINE rightArrow #-}
80+{-# NOINLINE rightArrow #-}
8181rightArrow :: Parser ()
8282rightArrow =
8383 symbol "->"
8484
8585
86−{-# INLINE hasType #-}
86+{-# NOINLINE hasType #-}
8787hasType :: Parser ()
8888hasType =
8989 symbol ":"
9090
9191
92−{-# INLINE comma #-}
92+{-# NOINLINE comma #-}
9393comma :: Parser ()
9494comma =
9595 symbol ","
9696
9797
98−{-# INLINE pipe #-}
98+{-# NOINLINE pipe #-}
9999pipe :: Parser ()
100100pipe =
101101 symbol "|"
102102
103103
104−{-# INLINE cons #-}
104+{-# NOINLINE cons #-}
105105cons :: Parser ()
106106cons =
107107 symbol "::"
108108
109109
110−{-# INLINE dot #-}
110+{-# NOINLINE dot #-}
111111dot :: Parser ()
112112dot =
113113 symbol "."
114114
115115
116−{-# INLINE minus #-}
116+{-# NOINLINE minus #-}
117117minus :: Parser ()
118118minus =
119119 symbol "-"
120120
121121
122−{-# INLINE lambda #-}
122+{-# NOINLINE lambda #-}
123123lambda :: Parser ()
124124lambda =
125125 oneOf [ symbol "\\", symbol "\x03BB" ]
@@ -129,45 +129,43 @@ lambda =
129129-- ENCLOSURES
130130
131131
132−{-# INLINE leftParen #-}
132+{-# NOINLINE leftParen #-}
133133leftParen :: Parser ()
134134leftParen =
135135 symbol "("
136136
137137
138−{-# INLINE rightParen #-}
138+{-# NOINLINE rightParen #-}
139139rightParen :: Parser ()
140140rightParen =
141141 symbol ")"
142142
143143
144−{-# INLINE leftSquare #-}
144+{-# NOINLINE leftSquare #-}
145145leftSquare :: Parser ()
146146leftSquare =
147147 symbol "["
148148
149149
150−{-# INLINE rightSquare #-}
150+{-# NOINLINE rightSquare #-}
151151rightSquare :: Parser ()
152152rightSquare =
153153 symbol "]"
154154
155155
156−{-# INLINE leftCurly #-}
156+{-# NOINLINE leftCurly #-}
157157leftCurly :: Parser ()
158158leftCurly =
159159 symbol "{"
160160
161161
162−{-# INLINE rightCurly #-}
162+{-# NOINLINE rightCurly #-}
163163rightCurly :: Parser ()
164164rightCurly =
165165 symbol "}"
166166
167167
168168
169−
170−
171169-- LOCATION
172170
173171
src/Parse/Module.hs+14−2
@@ -28,13 +28,25 @@ header =
2828
2929kernelHeader :: Parser [Module.UserImport]
3030kernelHeader =
31− do symbol "/*"
31+ do headerOpen
3232 freshLine
3333 imports <- chompImports []
34− symbol "*/"
34+ headerClose
3535 return imports
3636
3737
38+{-# NOINLINE headerOpen #-}
39+headerOpen :: Parser ()
40+headerOpen =
41+ symbol "/*"
42+
43+
44+{-# NOINLINE headerClose #-}
45+headerClose :: Parser ()
46+headerClose =
47+ symbol "*/"
48+
49+
3850
3951-- HEADER DECL
4052
src/Parse/Primitives.hs+17−3
@@ -302,8 +302,10 @@ instance Monad Parser where
302302-- TEXT
303303
304304
305+{-# INLINE symbol #-}
305306symbol :: Text -> Parser ()
306307symbol sym@(Text.Text tArray tOffset tLen) =
308+ let !theory = Symbol sym in
307309 Parser $ \(State array offset length indent row col ctx) cok _ _ eerr ->
308310 if tLen <= length && Text.equal tArray tOffset array offset tLen then
309311 let
@@ -316,7 +318,7 @@ symbol sym@(Text.Text tArray tOffset tLen) =
316318 cok () newState noError
317319
318320 else
319− eerr (expect row col ctx (Symbol sym))
321+ eerr (expect row col ctx theory)
320322
321323
322324moveCursor :: Text.Array -> Int -> Int -> Int -> Int -> (# Int, Int #)
@@ -738,7 +740,7 @@ eatMultiCommentHelp array offset length row col openComments =
738740
739741docComment :: Parser Text
740742docComment =
741− do symbol "{-|"
743+ do docCommentOpen
742744 Parser $ \(State array offset length indent row col ctx) cok cerr _ _ ->
743745 case eatMultiCommentHelp array offset length row col 1 of
744746 Left err ->
@@ -751,6 +753,12 @@ docComment =
751753 noError
752754
753755
756+{-# NOINLINE docCommentOpen #-}
757+docCommentOpen :: Parser ()
758+docCommentOpen =
759+ symbol "{-|"
760+
761+
754762chompUntilDocs :: Parser Bool
755763chompUntilDocs =
756764 Parser $ \(State array offset length indent row col ctx) cok _ _ _ ->
@@ -1375,7 +1383,7 @@ stepHex word hexNumber =
13751383
13761384shaderSource :: Parser Text
13771385shaderSource =
1378− do symbol "[glsl|"
1386+ do shaderSourceOpen
13791387 Parser $ \(State array offset length indent row col ctx) cok cerr _ _ ->
13801388 case eatShader array offset length row col of
13811389 Nothing ->
@@ -1390,6 +1398,12 @@ shaderSource =
13901398 cok (copyText array offset size) newState noError
13911399
13921400
1401+{-# NOINLINE shaderSourceOpen #-}
1402+shaderSourceOpen :: Parser ()
1403+shaderSourceOpen =
1404+ symbol "[glsl|"
1405+
1406+
13931407eatShader :: Text.Array -> Int -> Int -> Int -> Int -> Maybe (Int, Int, Int)
13941408eatShader array offset length row col =
13951409 if length < 2 then