Package lepl :: Package stream :: Module facade :: Class HelperFacade
[hide private]
[frames] | no frames]

Class HelperFacade

source code


A facade that delegates all calls to the underlying delegate stream.
Instance Methods [hide private]
 
__init__(self, delegate) source code
 
__repr__(self)
Simplify for comparison in tests
source code
 
__eq__(self, other) source code
 
__hash__(self) source code
 
key(self, state, other)
Generate an object that can be hashed (implements __hash__ and __eq__).
source code
 
kargs(self, state, prefix='', kargs=None)
Generate a dictionary of values that describe the stream.
source code
 
fmt(self, state, template, prefix='', kargs=None)
fmt a message using the expensive kargs function.
source code
 
debug(self, state)
Generate an inexpensive debug message.
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)
Return (values, stream) where values correspond to something like "the rest of the line" from the current point and stream is advanced to the point after the line ends.
source code
 
len(self, state)
Return the remaining length of the stream.
source code
 
stream(self, state, value, id_=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
 
delta(self, state)
Return the offset, lineno and char of the current point, relative to the entire stream, as a tuple.
source code
 
eq(self, state1, state2)
Are the two states equal?
source code
 
new_max(self, state)
Return (old max, new stream), where new stream uses a new max.
source code
 
cacheable(self)
Is this stream cacheable?
source code
Method Details [hide private]

__init__(self, delegate)
(Constructor)

source code 
Overrides: core.StreamHelper.__init__

__repr__(self)
(Representation operator)

source code 
Simplify for comparison in tests
Overrides: core.StreamHelper.__repr__
(inherited documentation)

__eq__(self, other)
(Equality operator)

source code 
Overrides: core.StreamHelper.__eq__

__hash__(self)
(Hashing function)

source code 
Overrides: core.StreamHelper.__hash__

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.

prefix modifies the property names

kargs allows values to be provided. These are not overwritten, so if there is a name clash the provided value remains.

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

The following names will be defined (at a minimum).

For these value the "global" prefix indicates the underlying stream when, for example, tokens are used (other values will be relative to the token). If tokens etc are not in use then global and non-global values will agree. - data: a line representing the data, highlighting the current offset - global_data: as data, but for the entire sequence - text: as data, but without a "[...]" at the end - global_text: as text, but for the entire sequence - type: the type of the sequence - global_type: the type of the entire sequence - global_offset: a 0-based index into the underlying sequence

These values are always local: - offset: a 0-based index into the sequence - rest: the data following the current point - repr: the current value, or <EOS> - str: the current value, or an empty string

These values are always global: - filename: a filename, if available, or the type - lineno: a 1-based line number for the current offset - char: a 1-based character count within the line for the current offset - location: a summary of the current location

Overrides: core.StreamHelper.kargs
(inherited documentation)

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

source code 
fmt a message using the expensive kargs function.
Overrides: core.StreamHelper.fmt
(inherited documentation)

debug(self, state)

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

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 

Return (values, stream) where values correspond to something like "the rest of the line" from the current point and stream is advanced to the point after the line ends.

If empty_ok is true and we are at the end of a line, return an empty line, otherwise advance (and maybe raise a StopIteration).

Overrides: core.StreamHelper.line
(inherited documentation)

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)

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)

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)

eq(self, state1, state2)

source code 
Are the two states equal?
Overrides: core.StreamHelper.eq
(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)

cacheable(self)

source code 
Is this stream cacheable?
Overrides: core.StreamHelper.cacheable
(inherited documentation)