Stream primitives: Module parsing.stream

class pyrser.parsing.stream.Position(index, lineno, col_offset)

Bases: tuple

__getnewargs__(self)

Return self as a plain tuple. Used by copy and pickle.

__getstate__(self)

Exclude the OrderedDict from pickling

static __new__(_cls, index, lineno, col_offset)

Create new instance of Position(index, lineno, col_offset)

__repr__(self)

Return a nicely formatted representation string

__slots__ = ()
_asdict(self)

Return a new OrderedDict which maps field names to their values.

_fields = ('index', 'lineno', 'col_offset')
classmethod _make(iterable, new= <built-in method __new__ of type object at 0x8490e0>, len= <built-in function len>)

Make a new Position object from a sequence or iterable

_replace(_self, kwds)

Return a new Position object replacing specified fields with new values

col_offset

Alias for field number 2

index

Alias for field number 0

lineno

Alias for field number 1

class pyrser.parsing.stream.Cursor(position: pyrser.parsing.stream.Position=Position(index=0, lineno=1, col_offset=1))[source]

Bases: object

A mutable position in a Stream.

It can be initialized or set from an immutable Position.

__init__(self, position: Position= Position(index=0, lineno=1, col_offset=1))[source]
index

The current index of the cursor.

lineno

The current line number of the cursor.

col_offset

The current column offset of the cursor.

position

The current position of the cursor.

max_readed_position

The index of the deepest character readed.

step_next_char(self)[source]

Puts the cursor on the next character.

step_prev_char(self)[source]

Puts the cursor on the previous character.

step_next_line(self)[source]

Sets cursor as beginning of next line.

step_prev_line(self)[source]

Sets cursor as end of previous line.

class pyrser.parsing.stream.Tag(stream: str, begin: int, end=0)[source]

Bases: object

Provide capture facilities

__init__(self, stream: str, begin: int, end= 0)[source]
set_begin(self, begin: int)[source]
set_end(self, end: int)[source]
__str__(self) → str[source]
__repr__(self) → str[source]
class pyrser.parsing.stream.Stream(content: str=None, name: str=None)[source]

Bases: object

Helps keep track of stream processing progress.

__init__(self, content: str= None, name: str= None)[source]
__len__(self) → int[source]
__getitem__(self, key: int) → str[source]
name

Name of the stream.

eos_index

End Of Stream index.

index

The current position index.

lineno

The current position line number.

col_offset

The current position column offset.

peek_char

The current position character value.

last_readed_line

Usefull string to compute error message.

incpos(self, length: int= 1) → int[source]

Increment the cursor to the next character.

decpos(self, length: int= 1) → int[source]
save_context(self) → bool[source]

Save current position.

restore_context(self) → bool[source]

Rollback to previous saved position.

validate_context(self) → bool[source]

Discard previous saved position.