Modules 25
Text.ParserCombinators.Parsec.Token
provisionalParsec compatibility module
data GenLanguageDef s u 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.
LanguageDef :: String -> String -> String -> Bool -> ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char -> [String] -> [String] -> Bool -> GenLanguageDef s u m
commentStart :: GenLanguageDef s u m -> String
Describes the start of a block comment. Use the empty string if the language doesn't support block comments. For example "/*".
commentEnd :: GenLanguageDef s u m -> String
Describes the end of a block comment. Use the empty string if the language doesn't support block comments. For example "*/".
commentLine :: GenLanguageDef s u m -> String
Describes the start of a line comment. Use the empty string if the language doesn't support line comments. For example "//".
nestedComments :: GenLanguageDef s u m -> Bool
Set to True if the language supports nested block comments.
identStart :: GenLanguageDef s u m -> ParsecT s u m Char
This parser should accept any start characters of identifiers. For
example letter <|> char '_'.
identLetter :: GenLanguageDef s u m -> ParsecT s u m Char
This parser should accept any legal tail characters of identifiers.
For example alphaNum <|> char '_'.
opStart :: GenLanguageDef s u m -> ParsecT s u m Char
This parser should accept any start characters of operators. For
example oneOf ":!#$%&*+./<=>?\\\^|-~"@
opLetter :: GenLanguageDef s u m -> ParsecT s u m Char
This parser should accept any legal tail characters of operators.
Note that this parser should even be defined if the language doesn't
support user-defined operators, or otherwise the reservedOp
parser won't work correctly.
reservedNames :: GenLanguageDef s u m -> [String]
The list of reserved identifiers.
reservedOpNames :: GenLanguageDef s u m -> [String]
The list of reserved operators.
caseSensitive :: GenLanguageDef s u m -> Bool
Set to True if the language is case sensitive.
type TokenParser st = GenTokenParser String st Identity
data GenTokenParser s u m
The type of the record that holds lexical parsers that work on
s streams with state u over a monad m.
TokenParser :: ParsecT s u m String -> String -> ParsecT s u m () -> ParsecT s u m String -> String -> ParsecT s u m () -> ParsecT s u m Char -> ParsecT s u m String -> ParsecT s u m Integer -> ParsecT s u m Integer -> ParsecT s u m Double -> ParsecT s u m (Either Integer Double) -> ParsecT s u m Integer -> ParsecT s u m Integer -> ParsecT s u m Integer -> String -> ParsecT s u m String -> forall a. ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m () -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> forall a. ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m String -> ParsecT s u m String -> ParsecT s u m String -> ParsecT s u m String -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> forall a. ParsecT s u m a -> ParsecT s u m [a] -> GenTokenParser s u m
identifier :: GenTokenParser s u m -> ParsecT s u m String
This lexeme parser parses a legal identifier. Returns the identifier
string. This parser will fail on identifiers that are reserved
words. Legal identifier (start) characters and reserved words are
defined in the LanguageDef that is passed to
makeTokenParser. An identifier is treated as
a single token using try.
reserved :: GenTokenParser s u m -> String -> ParsecT s u m ()
The lexeme parser reserved name parses @symbol
name, but it also checks that the name@ is not a prefix of a
valid identifier. A reserved word is treated as a single token
using try.
operator :: GenTokenParser s u m -> ParsecT s u m String
This lexeme parser parses a legal operator. Returns the name of the
operator. This parser will fail on any operators that are reserved
operators. Legal operator (start) characters and reserved operators
are defined in the LanguageDef that is passed to
makeTokenParser. An operator is treated as a
single token using try.
reservedOp :: GenTokenParser s u m -> String -> ParsecT s u m ()
The lexeme parser reservedOp name parses @symbol
name, but it also checks that the name@ is not a prefix of a
valid operator. A reservedOp is treated as a single token using
try.
charLiteral :: GenTokenParser s u m -> ParsecT s u m Char
This lexeme 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).
stringLiteral :: GenTokenParser s u m -> ParsecT s u m String
This lexeme 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).
natural :: GenTokenParser s u m -> ParsecT s u m Integer
This lexeme 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.
integer :: GenTokenParser s u m -> ParsecT s u m Integer
This lexeme 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.
float :: GenTokenParser s u m -> ParsecT s u m Double
This lexeme 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.
naturalOrFloat :: GenTokenParser s u m -> ParsecT s u m (Either Integer Double)
This lexeme 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.
decimal :: GenTokenParser s u m -> ParsecT s u m Integer
Parses a non-negative whole number in the decimal system. Returns the value of the number.
hexadecimal :: GenTokenParser s u m -> ParsecT s u 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.
octal :: GenTokenParser s u m -> ParsecT s u 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.
symbol :: GenTokenParser s u m -> String -> ParsecT s u m String
Lexeme parser symbol s parses string s and skips
trailing white space.
lexeme :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a
lexeme p first applies parser p and then the whiteSpace
parser, returning the value of p. Every lexical
token (lexeme) is defined using lexeme, this way every parse
starts at a point without white space. Parsers that use lexeme are
called lexeme 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.
mainParser = do{ whiteSpace
; ds <- many (lexeme digit)
; eof
; return (sum ds)
}whiteSpace :: GenTokenParser s u m -> ParsecT s u m ()
Parses any white space. White space consists of zero or more
occurrences of a space, a line comment or a block (multi
line) comment. Block comments may be nested. How comments are
started and ended is defined in the LanguageDef
that is passed to makeTokenParser.
parens :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a
Lexeme parser parens p parses p enclosed in parenthesis,
returning the value of p.
braces :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a
Lexeme parser braces p parses p enclosed in braces ('{' and
'}'), returning the value of p.
angles :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a
Lexeme parser angles p parses p enclosed in angle brackets ('<'
and '>'), returning the value of p.
brackets :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a
Lexeme parser brackets p parses p enclosed in brackets ('['
and ']'), returning the value of p.
squares :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m a
DEPRECATED: Use brackets.
semi :: GenTokenParser s u m -> ParsecT s u m String
Lexeme parser |semi| parses the character ';' and skips any trailing white space. Returns the string ";".
comma :: GenTokenParser s u m -> ParsecT s u m String
Lexeme parser comma parses the character ',' and skips any
trailing white space. Returns the string ",".
colon :: GenTokenParser s u m -> ParsecT s u m String
Lexeme parser colon parses the character ':' and skips any
trailing white space. Returns the string ":".
dot :: GenTokenParser s u m -> ParsecT s u m String
Lexeme parser dot parses the character '.' and skips any
trailing white space. Returns the string ".".
semiSep :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]
Lexeme parser semiSep p parses zero or more occurrences of p
separated by semi. Returns a list of values returned by
p.
semiSep1 :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]
Lexeme parser semiSep1 p parses one or more occurrences of p
separated by semi. Returns a list of values returned by p.
commaSep :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]
Lexeme parser commaSep p parses zero or more occurrences of
p separated by comma. Returns a list of values returned
by p.
commaSep1 :: GenTokenParser s u m -> forall a. ParsecT s u m a -> ParsecT s u m [a]
Lexeme parser commaSep1 p parses one or more occurrences of
p separated by comma. Returns a list of values returned
by p.
makeTokenParser :: (Stream s m Char) => GenLanguageDef s u m -> GenTokenParser s u 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
appropriate language definition and selects the lexical parsers that
are needed from the resulting GenTokenParser.
module Main where
import Text.Parsec
import qualified Text.Parsec.Token as P
import Text.Parsec.Language (haskellDef)
-- The parser
...
expr = parens expr
<|> identifier
<|> ...
-- The lexer
lexer = P.makeTokenParser haskellDef
parens = P.parens lexer
braces = P.braces lexer
identifier = P.identifier lexer
reserved = P.reserved lexer
...- Maintainer
- derek.a.elkins@gmail.com
- Portability
- portable
- Copyright
- (c) Paolo Martini 2007
- License
- BSD-style (see the LICENSE file)
Build record and source files
Community contribution. The service has not verified this documentation. The generator reported 3 diagnostics.
Target: Linux on x86-64. Some inferred types and resolved links are not available.
Generator: aihc-haddock-858b1951-web-1
Metadata snapshot: 51a8c38adf37e9558e7835b04b20868626c044e2d2e98e3527943eabd1e09c0a
Open the dependency plan · Download the documentation model
- aihc-base-4.21.2.0 · Core library · Cabal file
- aihc-internal-9.1204.0 · Core library · Cabal file
- aihc-prim-0.13.0 · Core library · Cabal file
- aihc-rts-1.0.2 · Core library · Cabal file
- aihc-template-haskell-2.23.0.0 · Core library · Cabal file
- array-0.5.8.0 · Cabal revision 2 · Cabal file · Source archive
- binary-0.8.9.3 · Cabal revision 0 · Cabal file · Source archive
- bytestring-0.12.2.0 · Cabal revision 1 · Cabal file · Source archive
- containers-0.8.1 · Cabal revision 0 · Cabal file · Source archive
- deepseq-1.5.2.0 · Cabal revision 0 · Cabal file · Source archive
- mtl-2.3.2 · Cabal revision 1 · Cabal file · Source archive
- parsec-3.1.18.0 · Cabal revision 1 · Cabal file · Source archive
- system-cxx-std-lib-1.0 · Core library · Cabal file
- text-2.1.4 · Cabal revision 0 · Cabal file · Source archive
- transformers-0.6.3.0 · Cabal revision 2 · Cabal file · Source archive