1 -----------------------------------------------------------------------------
3 -- Module : Distribution.Lex
4 -- Copyright : Ben Gamari 2015-2019
6 -- Maintainer : cabal-devel@haskell.org
7 -- Portability : portable
9 -- This module contains a simple lexer supporting quoted strings
11 module Distribution
.Lex
(
16 import Distribution
.Compat
.Prelude
17 import Distribution
.Compat
.DList
19 tokenizeQuotedWords
:: String -> [String]
20 tokenizeQuotedWords
= filter (not . null) . go
False mempty
22 go
:: Bool -- ^ in quoted region
23 -> DList
Char -- ^ accumulator
24 -> String -- ^ string to be parsed
25 -> [String] -- ^ parse result
28 |
otherwise = [accum']
29 where accum' = runDList
accum
32 |
isSpace c
= runDList
accum : go
False mempty cs
33 | c
== '"' = go True accum cs
36 | c == '"' = go
False accum cs
38 go quoted
accum (c
:cs
)
39 = go quoted
(accum `mappend` singleton c
) cs