mirror of
https://github.com/mrkkrp/megaparsec.git
synced 2024-12-25 17:22:33 +03:00
34 lines
798 B
Haskell
34 lines
798 B
Haskell
|
|
module Bugs.Bug2 (main) where
|
|
|
|
import Control.Applicative (empty)
|
|
import Control.Monad (void)
|
|
|
|
import Text.Megaparsec
|
|
import Text.Megaparsec.String
|
|
import qualified Text.Megaparsec.Lexer as L
|
|
|
|
import Test.Framework
|
|
import Test.Framework.Providers.HUnit
|
|
import Test.HUnit hiding (Test)
|
|
|
|
sc :: Parser ()
|
|
sc = L.space (void spaceChar) empty empty
|
|
|
|
lexeme :: Parser a -> Parser a
|
|
lexeme = L.lexeme sc
|
|
|
|
stringLiteral :: Parser String
|
|
stringLiteral = lexeme $ char '"' >> manyTill L.charLiteral (char '"')
|
|
|
|
main :: Test
|
|
main =
|
|
testCase "Control Char Parsing (#2)" $
|
|
parseString "\"test\\^Bstring\"" @?= "test\^Bstring"
|
|
where
|
|
parseString :: String -> String
|
|
parseString input =
|
|
case parse stringLiteral "Example" input of
|
|
Left{} -> error "Parse failure"
|
|
Right str -> str
|