API#
The package exports one class, BeancountLexer, and its version, pygments_beancount.__version__.
Attribute |
Value |
|---|---|
|
|
|
|
|
|
|
|
Entry point |
|
- class pygments_beancount.BeancountLexer(*args, **kwds)[source]#
Bases:
RegexLexerLexer for Beancount ledgers.
Beancount is line-oriented, so the lexer needs context in three places only: the first column of a line, the token right after a date, and the inside of a string. The
directivestate handles the token after a date, thestringstate handles strings, which may span lines, and every other token is matched by thevaluesrules.- name = 'Beancount'#
Full name of the lexer, in human-readable form
- url = 'https://beancount.github.io/docs/beancount_language_syntax/'#
URL of the language specification/definition. Used in the Pygments documentation. Set to an empty string to disable.
- aliases = ['beancount', 'bean']#
A list of short, unique identifiers that can be used to look up the lexer from a list, e.g., using get_lexer_by_name().
- filenames = ['*.beancount', '*.bean']#
A list of fnmatch patterns that match filenames which contain content for this lexer. The patterns in this list should be unique among all lexers.
- mimetypes = ['text/x-beancount']#
A list of MIME types for content that can be lexed with this lexer.
- static analyse_text(text)#
Score how likely text is a Beancount ledger.
Pygments wraps it so the result is always a float from 0.0 to 1.0 (
pygments.util.make_analysator). The score grows by 0.3 for each kind of characteristic line found: a datedopen,close,balance,price,commodityorpadline; a dated transaction whose flag is followed by a string; anoptionline. It stays at 0.9 or below so the lexer does not claim files that only resemble a ledger.- Parameters:
text – The text to score.
- Returns:
A score from 0.0 to 0.9.
The Beancount lexer.
The token patterns follow Beancount’s own scanner, lexer.l, and the
places where each token may appear follow its grammar, grammar.y:
The lexer highlights; it never validates. It emits no
Error token, because Sphinx refuses to highlight a
block that contains one, and documentation snippets often hold placeholders
such as ....