HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleparsers-0.12.12Haskell2010

Text.Parser.Token

Parsers that comprehend whitespace and identifier styles

idStyle    = haskellIdents { styleReserved = ... }
identifier = ident idStyle
reserved   = reserve idStyle
  • 4 types
  • 1 class
  • 43 values
  • Packageparsers-0.12.12
  • Exports48
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceToken.hs

Token Parsing

26 declarations
valuewhiteSpace :: TokenParsing m => m ()
#

Skip zero or more bytes worth of white space. More complex parsers are free to consider comments as white space.

valuecharLiteral :: TokenParsing m => m Char
#

This token parser parses a single literal character. Returns the literal character value. This parsers deals correctly with escape sequences. The literal character is parsed according to the grammar rules defined in the Haskell report (which matches most programming languages quite closely).

valuestringLiteral :: (TokenParsing m, IsString s) => m s
#

This token parser parses a literal string. Returns the literal string value. This parsers deals correctly with escape sequences and gaps. The literal string is parsed according to the grammar rules defined in the Haskell report (which matches most programming languages quite closely).

valuenatural :: TokenParsing m => m Integer
#

This token parser parses a natural number (a non-negative whole number). Returns the value of the number. The number can be specified in decimal, hexadecimal or octal. The number is parsed according to the grammar rules in the Haskell report.

valueinteger :: TokenParsing m => m Integer
#

This token parser parses an integer (a whole number). This parser is like natural except that it can be prefixed with sign (i.e. '-' or '+'). Returns the value of the number. The number can be specified in decimal, hexadecimal or octal. The number is parsed according to the grammar rules in the Haskell report.

valuedouble :: TokenParsing m => m Double
#

This token parser parses a floating point value. Returns the value of the number. The number is parsed according to the grammar rules defined in the Haskell report.

This token parser parses either natural or a float. Returns the value of the number. This parsers deals with any overlap in the grammar rules for naturals and floats. The number is parsed according to the grammar rules defined in the Haskell report.

valuescientific :: TokenParsing m => m Scientific
#

This token parser parses a floating point value. Returns the value of the number. The number is parsed according to the grammar rules defined in the Haskell report.

valueparens :: TokenParsing m => m a -> m a
#

Token parser parens p parses p enclosed in parenthesis, returning the value of p.

valuebraces :: TokenParsing m => m a -> m a
#

Token parser braces p parses p enclosed in braces ('{' and '}'), returning the value of p.

valueangles :: TokenParsing m => m a -> m a
#

Token parser angles p parses p enclosed in angle brackets ('<' and '>'), returning the value of p.

valuebrackets :: TokenParsing m => m a -> m a
#

Token parser brackets p parses p enclosed in brackets ('[' and ']'), returning the value of p.

valuecomma :: TokenParsing m => m Char
#

Token parser comma parses the character ',' and skips any trailing white space. Returns the string ",".

valuecolon :: TokenParsing m => m Char
#

Token parser colon parses the character ':' and skips any trailing white space. Returns the string ":".

valuedot :: TokenParsing m => m Char
#

Token parser dot parses the character '.' and skips any trailing white space. Returns the string ".".

valuesemiSep :: TokenParsing m => m a -> m [a]
#

Token parser semiSep p parses zero or more occurrences of p separated by semi. Returns a list of values returned by p.

valuesemiSep1 :: TokenParsing m => m a -> m [a]
#

Token parser semiSep1 p parses one or more occurrences of p separated by semi. Returns a list of values returned by p.

valuecommaSep :: TokenParsing m => m a -> m [a]
#

Token parser commaSep p parses zero or more occurrences of p separated by comma. Returns a list of values returned by p.

valuecommaSep1 :: TokenParsing m => m a -> m [a]
#

Token parser commaSep1 p parses one or more occurrences of p separated by comma. Returns a list of values returned by p.

Token Parsing Class

classclass CharParsing m => TokenParsing (m :: Type -> Type) where
#

Additional functionality that is needed to tokenize input while ignoring whitespace.

Methods

  • someSpace :: m ()

    Usually, someSpace consists of one or more occurrences of a space. Some parsers may choose to recognize line comments or block (multi line) comments as white space as well.

  • nesting :: m a -> m a

    Called when we enter a nested pair of symbols. Overloadable to enable disabling layout

  • semi :: m Char

    The token parser |semi| parses the character ';' and skips any trailing white space. Returns the character ';'. Overloadable to permit automatic semicolon insertion or Haskell-style layout.

  • highlight :: Highlight -> m a -> m a

    Tag a region of parsed text with a bit of semantic information. Most parsers won't use this, but it is indispensible for highlighters.

  • token :: m a -> m a

    token p first applies parser p and then the whiteSpace parser, returning the value of p. Every lexical token (token) is defined using token, this way every parse starts at a point without white space. Parsers that use token are called token parsers in this document.

    The only point where the whiteSpace parser should be called explicitly is the start of the main parser in order to skip any leading white space.

    Alternatively, one might define token as first parsing whiteSpace and then parser p. By parsing whiteSpace first, the parser is able to return before parsing additional whiteSpace, improving laziness.

    mainParser  = sum <$ whiteSpace <*> many (token digit) <* eof
Instances14TokenParsing, …

Token Parsing Transformers

newtypenewtype Unspaced (m :: Type -> Type) a
#

This is a parser transformer you can use to disable the automatic trailing space consumption of a Token parser.

Constructors

Instances12MonadTrans, MonadReader, MonadState, MonadWriter, Monad, Functor, …
newtypenewtype Unlined (m :: Type -> Type) a
#

This is a parser transformer you can use to disable the automatic trailing newline (but not whitespace-in-general) consumption of a Token parser.

Constructors

Instances12MonadTrans, MonadReader, MonadState, MonadWriter, Monad, Functor, …
newtypenewtype Unhighlighted (m :: Type -> Type) a
#

This is a parser transformer you can use to disable syntax highlighting over a range of text you are parsing.

Instances12MonadTrans, MonadReader, MonadState, MonadWriter, Monad, Functor, …

Non-Token Parsers

valuedecimal :: TokenParsing m => m Integer
#

Parses a non-negative whole number in the decimal system. Returns the value of the number.

This parser does NOT swallow trailing whitespace

valuehexadecimal :: TokenParsing m => m Integer
#

Parses a non-negative whole number in the hexadecimal system. The number should be prefixed with "x" or "X". Returns the value of the number.

This parser does NOT swallow trailing whitespace

valueoctal :: TokenParsing m => m Integer
#

Parses a non-negative whole number in the octal system. The number should be prefixed with "o" or "O". Returns the value of the number.

This parser does NOT swallow trailing whitespace

valuecharacterChar :: TokenParsing m => m Char
#

This parser parses a character literal without the surrounding quotation marks.

This parser does NOT swallow trailing whitespace

valueinteger' :: TokenParsing m => m Integer
#

This parser parses an integer (a whole number). This parser is like natural except that it can be prefixed with sign (i.e. '-' or '+'). Returns the value of the number. The number can be specified in decimal, hexadecimal or octal. The number is parsed according to the grammar rules in the Haskell report.

This parser does NOT swallow trailing whitespace.

Also, unlike the integer parser, this parser does not admit spaces between the sign and the number.

Identifiers

5 declarations

Lenses and Traversals