@@ -73,6 +73,7 @@ module Text.Lexer.Inchworm
7373 , Scanner
7474
7575 -- * Generic Scanning
76+ , scanList
7677 , scanListIO
7778
7879 -- ** Source Construction
@@ -101,15 +102,30 @@ where
101102import Text.Lexer.Inchworm.Source
102103import Text.Lexer.Inchworm.Scanner
103104import Text.Lexer.Inchworm.Combinator
105+ import System.IO.Unsafe
104106
105107
106108-- | Scan a list of generic input tokens in the IO monad,
107109-- returning the source location of the final input token,
108110-- along with the remaining input.
109111--
110112-- NOTE: If you just want to scan a `String` of characters
111- -- use @scanStringIO @ from "Text.Lexer.Inchworm.Char"
113+ -- use @scanString @ from "Text.Lexer.Inchworm.Char"
112114--
115+ scanList
116+ :: Eq i
117+ => loc -- ^ Starting source location.
118+ -> (i -> loc -> loc ) -- ^ Function to bump the current location by one input token.
119+ -> [i ] -- ^ List of input tokens.
120+ -> Scanner IO loc [i ] a -- ^ Scanner to apply.
121+ -> ([a ], loc , [i ])
122+
123+ scanList loc bump input scanner
124+ = unsafePerformIO $ scanListIO loc bump input scanner
125+
126+
127+ -- | Implementation for `scanList`,
128+ -- that uses the IO monad to manage its state.
113129scanListIO
114130 :: Eq i
115131 => loc -- ^ Starting source location.
@@ -121,3 +137,5 @@ scanListIO
121137scanListIO loc bump input scanner
122138 = do src <- makeListSourceIO loc bump input
123139 scanSourceToList src scanner
140+
141+
0 commit comments