Skip zero or more bytes worth of white space. More complex parsers are free to consider comments as white space.
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 declarationsThis 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).
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).
This token parser behaves as stringLiteral, but for single-quoted strings.
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.
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.
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.
This token parser is like naturalOrDouble, but handles
leading - or +.
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 scientific. 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.
This token parser is like naturalOrScientific, but handles
leading - or +.
Token parser symbol s parses string s and skips
trailing white space.
Token parser textSymbol t parses text s and skips
trailing white space.
Token parser symbolic s parses char s and skips
trailing white space.
Token parser parens p parses p enclosed in parenthesis,
returning the value of p.
Token parser braces p parses p enclosed in braces ('{' and
'}'), returning the value of p.
Token parser angles p parses p enclosed in angle brackets ('<'
and '>'), returning the value of p.
Token parser brackets p parses p enclosed in brackets ('['
and ']'), returning the value of p.
Token parser comma parses the character ',' and skips any
trailing white space. Returns the string ",".
Token parser colon parses the character ':' and skips any
trailing white space. Returns the string ":".
Token parser dot parses the character '.' and skips any
trailing white space. Returns the string ".".
Token parser semiSep p parses zero or more occurrences of p
separated by semi. Returns a list of values returned by p.
Token parser semiSep1 p parses one or more occurrences of p
separated by semi. Returns a list of values returned by p.
Token parser commaSep p parses zero or more occurrences of
p separated by comma. Returns a list of values returned
by p.
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
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 aCalled when we enter a nested pair of symbols. Overloadable to enable disabling layout
semi :: m CharThe 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 aTag 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 atoken pfirst applies parserpand then the whiteSpace parser, returning the value ofp. Every lexical token (token) is defined usingtoken, this way every parse starts at a point without white space. Parsers that usetokenare 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, …
TokenParsing ReadPDefined in parsers-0.12.12 · Text.Parser.TokenChunk t => TokenParsing (Parser t)Defined in parsers-0.12.12 · Text.Parser.TokenTokenParsing m => TokenParsing (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenTokenParsing m => TokenParsing (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenTokenParsing m => TokenParsing (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.Token(TokenParsing m, MonadPlus m) => TokenParsing (IdentityT m)Defined in parsers-0.12.12 · Text.Parser.Token(TokenParsing m, MonadPlus m) => TokenParsing (ReaderT e m)Defined in parsers-0.12.12 · Text.Parser.Token(TokenParsing m, MonadPlus m) => TokenParsing (StateT s m)Defined in parsers-0.12.12 · Text.Parser.Token(TokenParsing m, MonadPlus m) => TokenParsing (StateT s m)Defined in parsers-0.12.12 · Text.Parser.Token(TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (WriterT w m)Defined in parsers-0.12.12 · Text.Parser.Token(TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (WriterT w m)Defined in parsers-0.12.12 · Text.Parser.TokenStream s m Char => TokenParsing (ParsecT s u m)Defined in parsers-0.12.12 · Text.Parser.Token(TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (RWST r w s m)Defined in parsers-0.12.12 · Text.Parser.Token(TokenParsing m, MonadPlus m, Monoid w) => TokenParsing (RWST r w s m)Defined in parsers-0.12.12 · Text.Parser.Token
Token Parsing Transformers
This is a parser transformer you can use to disable the automatic trailing space consumption of a Token parser.
Constructors
UnspacedrunUnspaced :: m a
Instances12MonadTrans, MonadReader, MonadState, MonadWriter, Monad, Functor, …
MonadTrans UnspacedDefined in parsers-0.12.12 · Text.Parser.TokenMonadReader e m => MonadReader e (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.TokenMonadState s m => MonadState s (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.TokenMonadWriter e m => MonadWriter e (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.TokenMonad m => Monad (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.TokenFunctor m => Functor (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.TokenApplicative m => Applicative (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.TokenAlternative m => Alternative (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.TokenMonadPlus m => MonadPlus (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.TokenCharParsing m => CharParsing (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.TokenParsing m => Parsing (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.TokenTokenParsing m => TokenParsing (Unspaced m)Defined in parsers-0.12.12 · Text.Parser.Token
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
UnlinedrunUnlined :: m a
Instances12MonadTrans, MonadReader, MonadState, MonadWriter, Monad, Functor, …
MonadTrans UnlinedDefined in parsers-0.12.12 · Text.Parser.TokenMonadReader e m => MonadReader e (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenMonadState s m => MonadState s (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenMonadWriter e m => MonadWriter e (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenMonad m => Monad (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenFunctor m => Functor (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenApplicative m => Applicative (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenAlternative m => Alternative (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenMonadPlus m => MonadPlus (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenCharParsing m => CharParsing (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenParsing m => Parsing (Unlined m)Defined in parsers-0.12.12 · Text.Parser.TokenTokenParsing m => TokenParsing (Unlined m)Defined in parsers-0.12.12 · Text.Parser.Token
This is a parser transformer you can use to disable syntax highlighting over a range of text you are parsing.
Constructors
Instances12MonadTrans, MonadReader, MonadState, MonadWriter, Monad, Functor, …
MonadTrans UnhighlightedDefined in parsers-0.12.12 · Text.Parser.TokenMonadReader e m => MonadReader e (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenMonadState s m => MonadState s (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenMonadWriter e m => MonadWriter e (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenMonad m => Monad (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenFunctor m => Functor (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenApplicative m => Applicative (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenAlternative m => Alternative (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenMonadPlus m => MonadPlus (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenCharParsing m => CharParsing (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenParsing m => Parsing (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.TokenTokenParsing m => TokenParsing (Unhighlighted m)Defined in parsers-0.12.12 · Text.Parser.Token
Non-Token Parsers
Parses a non-negative whole number in the decimal system. Returns the value of the number.
This parser does NOT swallow trailing whitespace
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
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
This parser parses a character literal without the surrounding quotation marks.
This parser does NOT swallow trailing whitespace
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 declarationsUsed to describe an input style for constructors, values, operators, etc.
Constructors
Lift an identifier style into a monad transformer
Using over from the lens package:
liftIdentifierStyle = over styleChars liftParse a non-reserved identifier or symbol
parse a reserved operator or identifier using a given style
parse a reserved operator or identifier using a given style given Text.
Lenses and Traversals
This lens can be used to update the name for this style of identifier.
styleName :: Lens' (IdentifierStyle m) StringThis lens can be used to update the action used to recognize the first letter in an identifier.
styleStart :: Lens' (IdentifierStyle m) (m Char)This lens can be used to update the action used to recognize subsequent letters in an identifier.
styleLetter :: Lens' (IdentifierStyle m) (m Char)This is a traversal of both actions in contained in an IdentifierStyle.
styleChars :: Traversal (IdentifierStyle m) (IdentifierStyle n) (m Char) (n Char)This is a lens that can be used to modify the reserved identifier set.
styleReserved :: Lens' (IdentifierStyle m) (HashSet String)This is a lens that can be used to modify the highlight used for this identifier set.
styleHighlight :: Lens' (IdentifierStyle m) HighlightThis is a lens that can be used to modify the highlight used for reserved identifiers in this identifier set.
styleReservedHighlight :: Lens' (IdentifierStyle m) HighlightThis is a traversal that can be used to modify the highlights used for both non-reserved and reserved identifiers in this identifier set.
styleHighlights :: Traversal' (IdentifierStyle m) Highlight