testString1 and testString2 are convenient to use in GHCi when playing around with how parsing works.
Modulepretty-simple-4.1.3.0Haskell2010
Text.Pretty.Simple.Internal.ExprParser
- 10 values
- Packagepretty-simple-4.1.3.0
- Exports10
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceExprParser.hs
See testString1.
Parse multiple expressions.
parseExprs "Just 'a'"([Other "Just ",CharLit "a"],"")
Handle escaped characters correctly
parseExprs $ "Foo \"hello \\\"world!\""([Other "Foo ",StringLit "hello \\\"world!"],"")parseExprs $ "'\\''"([CharLit "\\'"],"")
Parse string literals until a trailing double quote.
parseStringLit "foobar\" baz"("foobar"," baz")
Keep literal back slashes:
parseStringLit "foobar\\\" baz\" after"("foobar\\\" baz"," after")
Parse character literals until a trailing single quote.
parseCharLit "a' foobar"("a"," foobar")
Keep literal back slashes:
parseCharLit "\\'' hello"("\\'"," hello")
Parses integers and reals, like 123 and 45.67.
To be more precise, any numbers matching the regex \d+(\.\d+)? should
get parsed by this function.
parseNumberLit '3' "456hello world []"("3456","hello world []")parseNumberLit '0' ".12399880 foobar"("0.12399880"," foobar")
This function consumes input, stopping only when it hits a special
character or a digit. However, if the digit is in the middle of a
Haskell-style identifier (e.g. foo123), then keep going
anyway.
This is almost the same as the function
parseOtherSimple = span $ \c ->
notElem c ("{[()]}\"," :: String) && not (isDigit c) && (c /= '\'')except parseOther ignores digits and single quotes that appear in Haskell-like identifiers.
parseOther "hello world []"("hello world ","[]")parseOther "hello234 world"("hello234 world","")parseOther "hello 234 world"("hello ","234 world")parseOther "hello{[ 234 world"("hello","{[ 234 world")parseOther "H3110 World"("H3110 World","")parseOther "Node' (Leaf' 1) (Leaf' 2)"("Node' ","(Leaf' 1) (Leaf' 2)")parseOther "I'm One"("I'm One","")parseOther "I'm 2"("I'm ","2")