Package lepl :: Package stream :: Module simple :: Class SequenceHelper
[hide private]
[frames] | no frames]

Class SequenceHelper

source code


Instance Methods [hide private]
 
__init__(self, sequence, id=None, factory=None, max=None, global_kargs=None, cache_level=None, delta=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
key(self, state, other)
Generate an object that can be hashed (implements __hash__ and __eq__).
source code
 
_fmt(self, sequence, offset, maxlen=60, left='', right='', index=True)
fmt a possibly long subsection of data.
source code
 
_location(self, kargs, prefix)
Location (separate method so subclasses can replace).
source code
 
_typename(self, instance) source code
 
kargs(self, state, prefix='', kargs=None)
Generate a dictionary of values that describe the stream.
source code
 
next(self, state, count=1)
Return (value, stream) where value is the next value (or values if count > 1) from the stream and stream is advanced to the next character.
source code
 
join(self, state, *values)
Join sequences of values into a single sequence.
source code
 
empty(self, state)
Return true if no more data available.
source code
 
line(self, state, empty_ok)
Returns the rest of the data.
source code
 
len(self, state)
Return the remaining length of the stream.
source code
 
stream(self, state, value, id_=None, max=None)
Return a new stream that encapsulates the value given, starting at state.
source code
 
deepest(self)
Return a stream that represents the deepest match.
source code
 
debug(self, state)
Generate an inexpensive debug message.
source code
 
delta(self, state)
Return the offset, lineno and char of the current point, relative to the entire stream, as a tuple.
source code
 
new_max(self, state)
Return (old max, new stream), where new stream uses a new max.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Inherited from core.StreamHelper: __eq__, cacheable, eq, fmt

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, sequence, id=None, factory=None, max=None, global_kargs=None, cache_level=None, delta=None)
(Constructor)

source code 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: core.StreamHelper.__init__

key(self, state, other)

source code 
Generate an object that can be hashed (implements __hash__ and __eq__). See HashKey.
Overrides: core.StreamHelper.key
(inherited documentation)

kargs(self, state, prefix='', kargs=None)

source code 

Generate a dictionary of values that describe the stream. These may be extended by subclasses. They are provided to syntax_error_kargs, for example.

Note: Calculating this can be expensive; use only for error messages, not debug messages (that may be discarded).

Implementation note: Because some values are

Overrides: core.StreamHelper.kargs

next(self, state, count=1)

source code 

Return (value, stream) where value is the next value (or values if count > 1) from the stream and stream is advanced to the next character. Note that value is always a sequence (so if the stream is a list of integers, and `count`=1, then it will be a unitary list, for example).

Should raise StopIteration when no more data are available.

Overrides: core.StreamHelper.next
(inherited documentation)

join(self, state, *values)

source code 
Join sequences of values into a single sequence.
Overrides: core.StreamHelper.join
(inherited documentation)

empty(self, state)

source code 
Return true if no more data available.
Overrides: core.StreamHelper.empty
(inherited documentation)

line(self, state, empty_ok)

source code 
Returns the rest of the data.
Overrides: core.StreamHelper.line

len(self, state)

source code 
Return the remaining length of the stream. Streams of unknown length (iterables) should raise a TypeError.
Overrides: core.StreamHelper.len
(inherited documentation)

stream(self, state, value, id_=None, max=None)

source code 

Return a new stream that encapsulates the value given, starting at state. IMPORTANT: the stream used is the one that corresponds to the start of the value.

For example:

(line, next_stream) = s_line(stream, False) token_stream = s_stream(stream, line) # uses stream, not next_stream

This is used when processing Tokens, for example, or columns (where fragments in the correct column area are parsed separately).

Overrides: core.StreamHelper.stream
(inherited documentation)

deepest(self)

source code 
Return a stream that represents the deepest match. The stream may be incomplete in some sense (it may not be possible to use it for parsing more data), but it will have usable fmt and kargs methods.
Overrides: core.StreamHelper.deepest
(inherited documentation)

debug(self, state)

source code 
Generate an inexpensive debug message.
Overrides: core.StreamHelper.debug
(inherited documentation)

delta(self, state)

source code 
Return the offset, lineno and char of the current point, relative to the entire stream, as a tuple.
Overrides: core.StreamHelper.delta
(inherited documentation)

new_max(self, state)

source code 
Return (old max, new stream), where new stream uses a new max. This is used when we want to read from the stream without affecting the max (eg when looking ahead to generate tokens).
Overrides: core.StreamHelper.new_max
(inherited documentation)