formula.Tokenizer

A tokenizer for Excel worksheet formulae.

Usage

Source

formula.Tokenizer()

Converts a str string representing an Excel formula (in A1 notation) into a sequence of Token objects.

formula: The str string to tokenize

Tokenizer defines a method ._parse() to parse the formula into tokens, which can then be accessed through the .items attribute.

Methods

Name Description
assert_empty_token() Ensure that there’s no token currently being parsed.
check_scientific_notation() Consumes a + or - character if part of a number in sci. notation.
render() Convert the parsed tokens back to a string.
save_token() If there’s a token being parsed, add it to the item list.

assert_empty_token()

Ensure that there’s no token currently being parsed.

Usage

Source

assert_empty_token(can_follow=())

Or if there is a token being parsed, it must end with a character in can_follow.

If there are unconsumed token contents, it means we hit an unexpected token transition. In this case, we raise a TokenizerError


check_scientific_notation()

Consumes a + or - character if part of a number in sci. notation.

Usage

Source

check_scientific_notation()

Returns True if the character was consumed and self.offset was updated, False otherwise.


render()

Convert the parsed tokens back to a string.

Usage

Source

render()

save_token()

If there’s a token being parsed, add it to the item list.

Usage

Source

save_token()