Copyright | (c) Dennis Gosnell 2016 |
---|---|
License | BSD-style (see LICENSE file) |
Maintainer | cdep.illabout@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
- type Parser = Parsec String ()
- lexer :: GenTokenParser String u Identity
- stringLiteral :: Parser String
- brackets :: Parser a -> Parser a
- braces :: Parser a -> Parser a
- parens :: Parser a -> Parser a
- commaSep :: Parser a -> Parser [a]
- lexeme :: Parser a -> Parser a
- expr :: Parser [Expr]
- expr' :: Parser Expr
- bracketsExpr :: Parser Expr
- bracesExpr :: Parser Expr
- parensExpr :: Parser Expr
- recursiveSurroundingExpr :: (forall a. Parser a -> Parser a) -> Parser (CommaSeparated [Expr])
- recursiveExpr :: Parser Expr
- stringLiteralExpr :: Parser Expr
- nonRecursiveExpr :: Parser Expr
- anyOtherText :: Parser Expr
- testString1 :: String
- testString2 :: String
- expressionParse :: String -> Either ParseError [Expr]
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 " "]]}))
bracesExpr :: Parser Expr Source #
parensExpr :: Parser Expr Source #
recursiveSurroundingExpr :: (forall a. Parser a -> Parser a) -> Parser (CommaSeparated [Expr]) Source #
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
testString1 :: String Source #
testString2 :: String Source #
expressionParse :: String -> Either ParseError [Expr] Source #