The target module

A Target describes where to go.

In a lexicon rule, you can specify destinations using integers or lexicons. A Target generalizes this in two values/attributes: pop and push.

pop is zero or a negative integer, determining how many lexicons to pop off the current state/context.

push is a list of zero or more lexicons, determining which lexicons to add to the current state.

You can sort of “add” targets using a TargetFactory, which can create single Target objects combining multiple targets in once.

class Target(pop, push)

Bases: tuple

Used by the lexer to describe lexicon changes.

pop

A negative integer or 0, describing how many lexicons to leave.

push

A list of zero or more Lexicons to enter.

class TargetFactory[source]

Bases: object

Maintains a current target and allows you to store changes.

Call get() to get the final Target, and to reset the factory’s internal state.

add(target)[source]

Add a Target to this factory.

get()[source]

Return the current Target.

Returns None if there is nothing to pop and push. After this the current target is reset.

push(*lexicons)[source]

Enter one or more lexicon(s).

pop(pop=- 1)[source]

Pop off one (or more) lexicon(s).

classmethod make(lexicon, rule)[source]

Create a Target of a rule.