File tree Expand file tree Collapse file tree 4 files changed +36
-1
lines changed Expand file tree Collapse file tree 4 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ extra-source-files:
90
90
tests/issue_119.x
91
91
tests/issue_141.x
92
92
tests/issue_197.x
93
+ tests/issue_262.x
93
94
tests/strict_text_typeclass.x
94
95
tests/posn_typeclass_strict_text.x
95
96
tests/tokens_monadUserState_strict_text.x
Original file line number Diff line number Diff line change @@ -94,7 +94,12 @@ data AlexReturn a
94
94
95
95
-- alexScan :: AlexInput -> StartCode -> AlexReturn a
96
96
alexScan input__ IBOX (sc)
97
- = alexScanUser undefined input__ IBOX (sc)
97
+ = alexScanUser (error " alex rule requiring context was invoked by alexScan; use alexScanUser instead?" ) input__ IBOX (sc)
98
+
99
+ -- If the generated alexScan/alexScanUser functions are called multiple times
100
+ -- in the same file, alexScanUser gets broken out into a separate function and
101
+ -- increases memory usage. Make sure GHC inlines this function and optimizes it.
102
+ {-# INLINE alexScanUser #-}
98
103
99
104
alexScanUser user__ input__ IBOX (sc)
100
105
= case alex_scan_tkn user__ input__ ILIT (0 ) input__ sc AlexNone of
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ TESTS = \
58
58
issue_119.x \
59
59
issue_141.x \
60
60
issue_197.x \
61
+ issue_262.x \
61
62
monad_typeclass.x \
62
63
monad_typeclass_bytestring.x \
63
64
monadUserState_typeclass.x \
Original file line number Diff line number Diff line change
1
+ {
2
+ -- https:// github.com/haskell/alex/pull/262
3
+ -- https:// gitlab.haskell.org/ghc/ghc/-/issues/25609
4
+ --
5
+ -- Error happens when using alexScan with a lexer that
6
+ -- inspects the context.
7
+
8
+ {-# LANGUAGE ScopedTypeVariables #-}
9
+
10
+ import Control.Exception
11
+ import Data.List (isInfixOf)
12
+ }
13
+
14
+ %wrapper " basic"
15
+
16
+ :-
17
+ .* / { \state _ _ _ -> state == ' x' } { id }
18
+
19
+ {
20
+ main :: IO ()
21
+ main = do
22
+ result <- try $ evaluate $ alexScan (' \n ' , [], " " ) 0 `seq` ()
23
+ case result of
24
+ Left (e :: SomeException)
25
+ | " use alexScanUser instead" `isInfixOf` show e
26
+ -> pure ()
27
+ _ -> error $ " Got unexpected result: " ++ show result
28
+ }
You can’t perform that action at this time.
0 commit comments