bibpy.lexers.base_lexer module

Base class for all lexers.

class bibpy.lexers.base_lexer.BaseLexer[source]

Bases: object

Base class for all bibpy lexers.

advance(match)[source]

Advance the internal state based on a successful match.

current_char

Return the current character or None if no such character.

eos

Return True if we have reached the end of the string.

expect(token, strip_whitespace=True)[source]

Expect a token, fail otherwise.

lex(string)[source]

Lex a string and generate tokens.

lex_string(value)[source]

Lex a string and return a single token for it.

make_token(token_type, value)[source]

Create a token type with a value.

mode

Return the current mode of the lexer.

modes

Return all modes that the lexer has.

patterns

All patterns recognised by the lexer.

raise_error(msg)[source]

Raise a lexer error with the given message.

raise_unbalanced()[source]

Raise an error for unbalanced braces.

raise_unexpected(token)[source]

Raise an error for an unexpected token.

reset(string)[source]

Reset the internal state of the lexer.

scan(search_type='search')[source]

Scan until any token recognised by this lexer is found.

Return the part of the string that was scanned past and the token itself. The latter is the entire rest of the string if the token was not found.

until(token)[source]

Scan until a particular token is found.

Return the part of the string that was scanned past and the string value of the token. The latter is the entire rest of the string if the token was not found.

exception bibpy.lexers.base_lexer.LexerError(msg, pos, char, lnum, brace_level, line)[source]

Bases: Exception

General lexer error.