on master help sign in
Make it cheaper to parse symbols
6397e12Evan Czaplicki
src/Parse/Helpers.hs+15−17
@@ -71,55 +71,55 @@ qualifiedVarHelp altEnding vars =
71-- COMMON SYMBOLS
71-- COMMON SYMBOLS
72
72
73
73
74−{-# INLINE equals #-}
74+{-# NOINLINE equals #-}
75equals :: Parser ()
75equals :: Parser ()
76equals =
76equals =
77 symbol "="
77 symbol "="
78
78
79
79
80−{-# INLINE rightArrow #-}
80+{-# NOINLINE rightArrow #-}
81rightArrow :: Parser ()
81rightArrow :: Parser ()
82rightArrow =
82rightArrow =
83 symbol "->"
83 symbol "->"
84
84
85
85
86−{-# INLINE hasType #-}
86+{-# NOINLINE hasType #-}
87hasType :: Parser ()
87hasType :: Parser ()
88hasType =
88hasType =
89 symbol ":"
89 symbol ":"
90
90
91
91
92−{-# INLINE comma #-}
92+{-# NOINLINE comma #-}
93comma :: Parser ()
93comma :: Parser ()
94comma =
94comma =
95 symbol ","
95 symbol ","
96
96
97
97
98−{-# INLINE pipe #-}
98+{-# NOINLINE pipe #-}
99pipe :: Parser ()
99pipe :: Parser ()
100pipe =
100pipe =
101 symbol "|"
101 symbol "|"
102
102
103
103
104−{-# INLINE cons #-}
104+{-# NOINLINE cons #-}
105cons :: Parser ()
105cons :: Parser ()
106cons =
106cons =
107 symbol "::"
107 symbol "::"
108
108
109
109
110−{-# INLINE dot #-}
110+{-# NOINLINE dot #-}
111dot :: Parser ()
111dot :: Parser ()
112dot =
112dot =
113 symbol "."
113 symbol "."
114
114
115
115
116−{-# INLINE minus #-}
116+{-# NOINLINE minus #-}
117minus :: Parser ()
117minus :: Parser ()
118minus =
118minus =
119 symbol "-"
119 symbol "-"
120
120
121
121
122−{-# INLINE lambda #-}
122+{-# NOINLINE lambda #-}
123lambda :: Parser ()
123lambda :: Parser ()
124lambda =
124lambda =
125 oneOf [ symbol "\\", symbol "\x03BB" ]
125 oneOf [ symbol "\\", symbol "\x03BB" ]
@@ -129,45 +129,43 @@ lambda =
129-- ENCLOSURES
129-- ENCLOSURES
130
130
131
131
132−{-# INLINE leftParen #-}
132+{-# NOINLINE leftParen #-}
133leftParen :: Parser ()
133leftParen :: Parser ()
134leftParen =
134leftParen =
135 symbol "("
135 symbol "("
136
136
137
137
138−{-# INLINE rightParen #-}
138+{-# NOINLINE rightParen #-}
139rightParen :: Parser ()
139rightParen :: Parser ()
140rightParen =
140rightParen =
141 symbol ")"
141 symbol ")"
142
142
143
143
144−{-# INLINE leftSquare #-}
144+{-# NOINLINE leftSquare #-}
145leftSquare :: Parser ()
145leftSquare :: Parser ()
146leftSquare =
146leftSquare =
147 symbol "["
147 symbol "["
148
148
149
149
150−{-# INLINE rightSquare #-}
150+{-# NOINLINE rightSquare #-}
151rightSquare :: Parser ()
151rightSquare :: Parser ()
152rightSquare =
152rightSquare =
153 symbol "]"
153 symbol "]"
154
154
155
155
156−{-# INLINE leftCurly #-}
156+{-# NOINLINE leftCurly #-}
157leftCurly :: Parser ()
157leftCurly :: Parser ()
158leftCurly =
158leftCurly =
159 symbol "{"
159 symbol "{"
160
160
161
161
162−{-# INLINE rightCurly #-}
162+{-# NOINLINE rightCurly #-}
163rightCurly :: Parser ()
163rightCurly :: Parser ()
164rightCurly =
164rightCurly =
165 symbol "}"
165 symbol "}"
166
166
167
167
168
168
169−
170−
171-- LOCATION
169-- LOCATION
172
170
173
171
src/Parse/Module.hs+14−2
@@ -28,13 +28,25 @@ header =
28
28
29kernelHeader :: Parser [Module.UserImport]
29kernelHeader :: Parser [Module.UserImport]
30kernelHeader =
30kernelHeader =
31− do symbol "/*"
31+ do headerOpen
32 freshLine
32 freshLine
33 imports <- chompImports []
33 imports <- chompImports []
34− symbol "*/"
34+ headerClose
35 return imports
35 return imports
36
36
37
37
38+{-# NOINLINE headerOpen #-}
39+headerOpen :: Parser ()
40+headerOpen =
41+ symbol "/*"
42+
43+
44+{-# NOINLINE headerClose #-}
45+headerClose :: Parser ()
46+headerClose =
47+ symbol "*/"
48+
49+
38
50
39-- HEADER DECL
51-- HEADER DECL
40
52
src/Parse/Primitives.hs+17−3
@@ -302,8 +302,10 @@ instance Monad Parser where
302-- TEXT
302-- TEXT
303
303
304
304
305+{-# INLINE symbol #-}
305symbol :: Text -> Parser ()
306symbol :: Text -> Parser ()
306symbol sym@(Text.Text tArray tOffset tLen) =
307symbol sym@(Text.Text tArray tOffset tLen) =
308+ let !theory = Symbol sym in
307 Parser $ \(State array offset length indent row col ctx) cok _ _ eerr ->
309 Parser $ \(State array offset length indent row col ctx) cok _ _ eerr ->
308 if tLen <= length && Text.equal tArray tOffset array offset tLen then
310 if tLen <= length && Text.equal tArray tOffset array offset tLen then
309 let
311 let
@@ -316,7 +318,7 @@ symbol sym@(Text.Text tArray tOffset tLen) =
316 cok () newState noError
318 cok () newState noError
317
319
318 else
320 else
319− eerr (expect row col ctx (Symbol sym))
321+ eerr (expect row col ctx theory)
320
322
321
323
322moveCursor :: Text.Array -> Int -> Int -> Int -> Int -> (# Int, Int #)
324moveCursor :: Text.Array -> Int -> Int -> Int -> Int -> (# Int, Int #)
@@ -738,7 +740,7 @@ eatMultiCommentHelp array offset length row col openComments =
738
740
739docComment :: Parser Text
741docComment :: Parser Text
740docComment =
742docComment =
741− do symbol "{-|"
743+ do docCommentOpen
742 Parser $ \(State array offset length indent row col ctx) cok cerr _ _ ->
744 Parser $ \(State array offset length indent row col ctx) cok cerr _ _ ->
743 case eatMultiCommentHelp array offset length row col 1 of
745 case eatMultiCommentHelp array offset length row col 1 of
744 Left err ->
746 Left err ->
@@ -751,6 +753,12 @@ docComment =
751 noError
753 noError
752
754
753
755
756+{-# NOINLINE docCommentOpen #-}
757+docCommentOpen :: Parser ()
758+docCommentOpen =
759+ symbol "{-|"
760+
761+
754chompUntilDocs :: Parser Bool
762chompUntilDocs :: Parser Bool
755chompUntilDocs =
763chompUntilDocs =
756 Parser $ \(State array offset length indent row col ctx) cok _ _ _ ->
764 Parser $ \(State array offset length indent row col ctx) cok _ _ _ ->
@@ -1375,7 +1383,7 @@ stepHex word hexNumber =
1375
1383
1376shaderSource :: Parser Text
1384shaderSource :: Parser Text
1377shaderSource =
1385shaderSource =
1378− do symbol "[glsl|"
1386+ do shaderSourceOpen
1379 Parser $ \(State array offset length indent row col ctx) cok cerr _ _ ->
1387 Parser $ \(State array offset length indent row col ctx) cok cerr _ _ ->
1380 case eatShader array offset length row col of
1388 case eatShader array offset length row col of
1381 Nothing ->
1389 Nothing ->
@@ -1390,6 +1398,12 @@ shaderSource =
1390 cok (copyText array offset size) newState noError
1398 cok (copyText array offset size) newState noError
1391
1399
1392
1400
1401+{-# NOINLINE shaderSourceOpen #-}
1402+shaderSourceOpen :: Parser ()
1403+shaderSourceOpen =
1404+ symbol "[glsl|"
1405+
1406+
1393eatShader :: Text.Array -> Int -> Int -> Int -> Int -> Maybe (Int, Int, Int)
1407eatShader :: Text.Array -> Int -> Int -> Int -> Int -> Maybe (Int, Int, Int)
1394eatShader array offset length row col =
1408eatShader array offset length row col =
1395 if length < 2 then
1409 if length < 2 then