class documentation

class Level: (source)

Constructor: Level()

View In Hierarchy

Parser helper tracking mask branches within a parenthesized level.

starts, ends and active are sets: one mask occurs one time at most. Two different masks never share a child. Thus, the size of each set is not more than the number of masks in the result.

Method __init__ Create a new parsing level with a fresh root mask.
Method add_any Advance active masks by adding/entering a wildcard branch.
Method add_key Advance active masks by adding/entering the given key.
Method new_mask Start a new top-level mask branch (after a comma).
Method pop_level Exit to the previous level, merging active branches.
Method push_level Enter a nested parenthesized level.
Instance Variable active Masks that are currently being extended.
Instance Variable ends Finished masks retained when a suffix can extend them.
Instance Variable pos Source position of the opening parenthesis.
Instance Variable prev Previous level in the nesting stack.
Instance Variable starts Masks that represent branch starts for the current level.
Method _finish Move the active masks to ends.
Instance Variable _collect_ends True when a key or a wildcard can extend the masks that this level finishes. Only then the level fills ends.
Instance Variable _ended Identities of the masks in ends.
def __init__(self): (source)

Create a new parsing level with a fresh root mask.

def add_any(self): (source)

Advance active masks by adding/entering a wildcard branch.

Each active mask gets its own child.

def add_key(self, k: FieldKey): (source)

Advance active masks by adding/entering the given key.

Each active mask gets its own child.

Parameters
k:FieldKeyField key to add at the current level.
def new_mask(self): (source)

Start a new top-level mask branch (after a comma).

def pop_level(self) -> Level | None: (source)

Exit to the previous level, merging active branches.

The previous level gets no masks when this level does not collect them, because no token can use them.

def push_level(self, pos: int, before_dot: bool = False) -> Level: (source)

Enter a nested parenthesized level.

Parameters
pos:intSource position of the opening parenthesis.
before_dot:boolTrue when a dot follows the closing parenthesis of the new level.
Returns
LevelNew Level instance.

Masks that are currently being extended.

Finished masks retained when a suffix can extend them.

Source position of the opening parenthesis.

Previous level in the nesting stack.

Masks that represent branch starts for the current level.

def _finish(self): (source)

Move the active masks to ends.

Branches that end at the same mask add it one time.

_collect_ends: bool = (source)

True when a key or a wildcard can extend the masks that this level finishes. Only then the level fills ends.

Identities of the masks in ends.