Module

Text.Parsing.Parser.Token

Functions for working with streams of tokens.

#token

token :: forall m a. Monad m => (a -> Position) -> ParserT (List a) m a

Create a parser which Returns the first token in the stream.

#when

when :: forall m a. Monad m => (a -> Position) -> (a -> Boolean) -> ParserT (List a) m a

Create a parser which matches any token satisfying the predicate.

#match

match :: forall a m. Monad m => Eq a => (a -> Position) -> a -> ParserT (List a) m a

Match the specified token at the head of the stream.

#GenLanguageDef

newtype GenLanguageDef s m

The GenLanguageDef type is a record that contains all parameterizable features of the "Text.Parsec.Token" module. The module Text.Parsec.Language contains some default definitions.

Constructors

#unGenLanguageDef

unGenLanguageDef :: forall s m. GenLanguageDef s m -> { caseSensitive :: Boolean, reservedOpNames :: Array String, reservedNames :: Array String, opLetter :: ParserT s m Char, opStart :: ParserT s m Char, identLetter :: ParserT s m Char, identStart :: ParserT s m Char, nestedComments :: Boolean, commentLine :: String, commentEnd :: String, commentStart :: String }

#GenTokenParser

type GenTokenParser s m = { identifier :: ParserT s m String, reserved :: String -> ParserT s m Unit, operator :: ParserT s m String, reservedOp :: String -> ParserT s m Unit, charLiteral :: ParserT s m Char, stringLiteral :: ParserT s m String, natural :: ParserT s m Int, integer :: ParserT s m Int, float :: ParserT s m Number, naturalOrFloat :: ParserT s m (Either Int Number), decimal :: ParserT s m Int, hexadecimal :: ParserT s m Int, octal :: ParserT s m Int, symbol :: String -> ParserT s m String, lexeme :: forall a. ParserT s m a -> ParserT s m a, whiteSpace :: ParserT s m Unit, parens :: forall a. ParserT s m a -> ParserT s m a, braces :: forall a. ParserT s m a -> ParserT s m a, angles :: forall a. ParserT s m a -> ParserT s m a, brackets :: forall a. ParserT s m a -> ParserT s m a, semi :: ParserT s m String, comma :: ParserT s m String, colon :: ParserT s m String, dot :: ParserT s m String, semiSep :: forall a. ParserT s m a -> ParserT s m (List a), semiSep1 :: forall a. ParserT s m a -> ParserT s m (List a), commaSep :: forall a. ParserT s m a -> ParserT s m (List a), commaSep1 :: forall a. ParserT s m a -> ParserT s m (List a) }

The type of the record that holds lexical parsers that work on s streams over a monad m.

#makeTokenParser

makeTokenParser :: forall m. Monad m => GenLanguageDef String m -> GenTokenParser String m

The expression makeTokenParser language creates a GenTokenParser record that contains lexical parsers that are defined using the definitions in the language record.

The use of this function is quite stylized - one imports the appropiate language definition and selects the lexical parsers that are needed from the resulting GenTokenParser.

module Main where

import Text.Parsing.Parser.Language (haskellDef)
import Text.Parsing.Parser.Token (makeTokenParser)

-- The parser
expr = parens expr
   <|> identifier
   <|> ...


-- The lexer
tokenParser = makeTokenParser haskellDef
parens      = tokenParser.parens
braces      = tokenParser.braces
identifier  = tokenParser.identifier
reserved    = tokenParser.reserved
...

#digit

digit :: forall m. Monad m => ParserT String m Char

Parse a digit. Matches any char that satisfies Data.Char.Unicode.isDigit.

#hexDigit

hexDigit :: forall m. Monad m => ParserT String m Char

Parse a hex digit. Matches any char that satisfies Data.Char.Unicode.isHexDigit.

#octDigit

octDigit :: forall m. Monad m => ParserT String m Char

Parse an octal digit. Matches any char that satisfies Data.Char.Unicode.isOctDigit.

#upper

upper :: forall m. Monad m => ParserT String m Char

Parse an uppercase letter. Matches any char that satisfies Data.Char.Unicode.isUpper.

#space

space :: forall m. Monad m => ParserT String m Char

Parse a space character. Matches any char that satisfies Data.Char.Unicode.isSpace.

#letter

letter :: forall m. Monad m => ParserT String m Char

Parse an alphabetical character. Matches any char that satisfies Data.Char.Unicode.isAlpha.

#alphaNum

alphaNum :: forall m. Monad m => ParserT String m Char

Parse an alphabetical or numerical character. Matches any char that satisfies Data.Char.Unicode.isAlphaNum.

Modules