Base lexer classes.
copyright: | Copyright 2006-2013 by the Pygments team, see AUTHORS. |
---|---|
license: | BSD, see LICENSE for details. |
Lexer for a specific language.
Basic options recognized: stripnl
Strip leading and trailing newlines from the input (default: True).
Secondary file name globs
Shortcuts for the lexer
Has to return a float between 0 and 1 that indicates if a lexer wants to highlight this text. Used by guess_lexer. If this method returns 0 it won’t highlight it in any case, if it returns 1 highlighting with this lexer is guaranteed.
The LexerMeta metaclass automatically wraps this function so that it works like a static method (no self or cls parameter) and the return value is automatically converted to float. If the return value is an object that is boolean False it’s the same as if the return values was 0.0.
File name globs
Return an iterable of (tokentype, value) pairs generated from text. If unfiltered is set to True, the filtering mechanism is bypassed even if filters are defined.
Also preprocess the text, i.e. expand tabs and strip it if wanted and applies registered filters.
Return an iterable of (tokentype, value) pairs. In subclasses, implement this method as a generator to maximize effectiveness.
MIME types
Name of the lexer
Priority, should multiple lexers match and no content is provided
Base for simple stateful regular expression-based lexers. Simplifies the lexing process so that you need only provide a list of states and regular expressions.
Flags for compiling the regular expressions. Defaults to MULTILINE.
Split text into (tokentype, text) pairs.
stack is the inital stack (default: ['root'])
Dict of {'state': [(regex, tokentype, new_state), ...], ...}
The initial state is ‘root’. new_state can be omitted to signify no state transition. If it is a string, the state is pushed on the stack and changed. If it is a tuple of strings, all states are pushed on the stack and the current state will be the topmost. It can also be combined('state1', 'state2', ...) to signify a new, anonymous state combined from the rules of two or more existing ones. Furthermore, it can be ‘#pop’ to signify going back one step in the state stack, or ‘#push’ to push the current state on the stack again.
The tuple can also be replaced with include('state'), in which case the rules from the state named by the string are included in the current one.
A RegexLexer that uses a context object to store its state.
This lexer takes two lexer as arguments. A root lexer and a language lexer. First everything is scanned using the language lexer, afterwards all Other tokens are lexed using the root lexer.
The lexers from the template lexer package use this base lexer.
A helper object that holds lexer position data.
Indicates that a state should include rules from another state.
Callback that yields multiple actions for each group in the match.
Callback that processes the match with a different lexer.
The keyword arguments are forwarded to the lexer, except state which is handled separately.
state specifies the state that the new lexer will start in, and can be an enumerable such as (‘root’, ‘inline’, ‘string’) or a simple string which is assumed to be on top of the root state.
Note: For that to work, _other must not be an ExtendedRegexLexer.