HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulepretty-simple-4.1.3.0Haskell2010

Text.Pretty.Simple.Internal.ExprParser

  • 10 values
valueparseExprs :: String -> ([Expr], String)
#

Parse multiple expressions.

Example1 expression
parseExprs "Just 'a'"([Other "Just ",CharLit "a"],"")

Handle escaped characters correctly

Example2 expressions
parseExprs $ "Foo \"hello \\\"world!\""([Other "Foo ",StringLit "hello \\\"world!"],"")parseExprs $ "'\\''"([CharLit "\\'"],"")
valueparseStringLit :: String -> (String, String)
#

Parse string literals until a trailing double quote.

Example1 expression
parseStringLit "foobar\" baz"("foobar"," baz")

Keep literal back slashes:

Example1 expression
parseStringLit "foobar\\\" baz\" after"("foobar\\\" baz"," after")
valueparseCharLit :: String -> (String, String)
#

Parse character literals until a trailing single quote.

Example1 expression
parseCharLit "a' foobar"("a"," foobar")

Keep literal back slashes:

Example1 expression
parseCharLit "\\'' hello"("\\'"," hello")
valueparseNumberLit :: Char -> String -> (String, String)
#

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.

Example2 expressions
parseNumberLit '3' "456hello world []"("3456","hello world []")parseNumberLit '0' ".12399880 foobar"("0.12399880"," foobar")
valueparseOther :: String -> (String, String)
#

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.

Example8 expressions
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")