lexer-applicative-1.1.1: Simple lexer based on applicative regular expressions

Safe HaskellNone
LanguageHaskell2010

Language.Lexer.Applicative

Description

Synopsis

Documentation

tokens Source

Arguments

:: RE Char token

regular expression for tokens

-> RE Char ()

regular expression for whitespace and comments

-> String

source file name (used in locations)

-> String

source text

-> [L token] 

The lexer.

In case of a lexical error, throws the LexicalError exception. This may seem impure compared to using Either, but it allows to consume the token list lazily.

Both token and whitespace regexes consume as many characters as possible (the maximal munch rule). When a regex returns without consuming any characters, a lexical error is signaled.

tokensEither Source

Arguments

:: RE Char token

regular expression for tokens

-> RE Char ()

regular expression for whitespace and comments

-> String

source file name (used in locations)

-> String

source text

-> Either LexicalError [L token] 

Like tokens, but returns Left instead of throwing an exception.

This function may be useful occasionally, but most of the time you should be using tokens instead. If you want to catch LexicalError, catch it after you plug tokens into a parser, not before, like this function does.

data LexicalError Source

The lexical error exception

Constructors

LexicalError !Pos