Paper Office
paper-xlsxAPI referenceformula.tokenizer

Tokenizer

paper-xlsx 0.2.1 API reference

A tokenizer for Excel worksheet formulae.

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.

Tokenizer(formula)

Attributes

ERROR_CODES

attributeERROR_CODES
= EXCEL_ERROR_CODES

SN_RE

attributeSN_RE
= re.compile('^[1-9](\\.[0-9]+)?[Ee]$')

STRING_REGEXES

attributeSTRING_REGEXES
= {'"': re.compile('"(?:[^"]*"")*[^"]*"(?!")'), "'": re.compile("'(?:[^']*'')*[^']*'(?!')")}

TOKEN_ENDERS

attributeTOKEN_ENDERS
= ',;}) +-*/^&=><%'

WSPACE_RE

attributeWSPACE_RE
= re.compile('[ \\n]+')

formula

attributeformula
= formula

items

attributeitems
= []

offset

attributeoffset
= 0

token

attributetoken
= []

token_stack

attributetoken_stack
= []

Functions

assert_empty_token

funcassert_empty_token(can_follow=())

Ensure that there's no token currently being parsed.

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

paramcan_follow
= ()

check_scientific_notation

funccheck_scientific_notation()

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

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

render

funcrender()

Convert the parsed tokens back to a string.

save_token

funcsave_token()

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

On this page