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:
9090 tests/issue_119.x
9191 tests/issue_141.x
9292 tests/issue_197.x
93+ tests/issue_262.x
9394 tests/strict_text_typeclass.x
9495 tests/posn_typeclass_strict_text.x
9596 tests/tokens_monadUserState_strict_text.x
Original file line number Diff line number Diff line change @@ -94,7 +94,12 @@ data AlexReturn a
9494
9595-- alexScan :: AlexInput -> StartCode -> AlexReturn a
9696alexScan 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 #-}
98103
99104alexScanUser user__ input__ IBOX (sc)
100105 = 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 = \
5858 issue_119.x \
5959 issue_141.x \
6060 issue_197.x \
61+ issue_262.x \
6162 monad_typeclass.x \
6263 monad_typeclass_bytestring.x \
6364 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