pretty-simple-2.0.2.0: pretty printer for data types with a 'Show' instance.

Copyright(c) Dennis Gosnell 2016
LicenseBSD-style (see LICENSE file)
Maintainercdep.illabout@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Text.Pretty.Simple.Internal.ExprParser

Description

 

Synopsis

Documentation

>>> import Data.Either (isLeft)
>>> :{
let test :: Parser a -> String -> Either ParseError a
    test parser = runParser parser () "(no source)"
:}

bracketsExpr :: Parser Expr Source #

Parse brackets around a list of expressions.

>>> test bracketsExpr "[hello\"what\", foo]"
Right (Brackets (CommaSeparated {unCommaSeparated = [[Other "hello",StringLit "what"],[Other "foo"]]}))
>>> test bracketsExpr "[[] ]"
Right (Brackets (CommaSeparated {unCommaSeparated = [[Brackets (CommaSeparated {unCommaSeparated = []}),Other " "]]}))

stringLiteralExpr :: Parser Expr Source #

Parse a string literal.

>>> test stringLiteralExpr "\"hello\""
Right (StringLit "hello")
>>> isLeft $ test stringLiteralExpr " \"hello\""
True

anyOtherText :: Parser Expr Source #

Parse anything that doesn't get parsed by the parsers above.

>>> test anyOtherText " Foo "
Right (Other " Foo ")

Parse empty strings.

>>> test anyOtherText " "
Right (Other " ")

Stop parsing if we hit [, ], (, ), {, }, ", or ,.

>>> test anyOtherText "hello["
Right (Other "hello")

Don't parse the empty string.

>>> isLeft $ test anyOtherText ""
True
>>> isLeft $ test anyOtherText ","
True