Esempio n. 1
0
 def record(self, is_result, text):
     '''
     Record the data.
     '''
     try:
         stream = self.generator.stream
         try:
             depth = s_delta(stream)[0]
         except AttributeError: # no .depth()
             depth = -1
         if depth >= self._deepest and is_result:
             self._deepest = depth
             self._countdown_result = self.n_results_after
             self._countdown_done = self.n_done_after
             self._before = list(self._limited)
             self._results_after = []
             self._done_after = []
         elif is_result and self._countdown_result:
             self._countdown_result -= 1
             self._results_after.append(text)
         elif not is_result and self._countdown_done:
             self._countdown_done -= 1
             self._done_after.append(text)
         self._limited.append(text)
     except StopIteration: # end of iterator stream
         pass
Esempio n. 2
0
 def record(self, is_result, text):
     '''
     Record the data.
     '''
     try:
         stream = self.generator.stream
         try:
             depth = s_delta(stream)[0]
         except AttributeError:  # no .depth()
             depth = -1
         if depth >= self._deepest and is_result:
             self._deepest = depth
             self._countdown_result = self.n_results_after
             self._countdown_done = self.n_done_after
             self._before = list(self._limited)
             self._results_after = []
             self._done_after = []
         elif is_result and self._countdown_result:
             self._countdown_result -= 1
             self._results_after.append(text)
         elif not is_result and self._countdown_done:
             self._countdown_done -= 1
             self._done_after.append(text)
         self._limited.append(text)
     except StopIteration:  # end of iterator stream
         pass
Esempio n. 3
0
 def _next_line(self, cons, empty_line_stream):
     delta = s_delta(empty_line_stream)
     delta = (delta[OFFSET], delta[LINE_NO] + 1, 1)
     return self.factory(cons.head,
                         id=self.id,
                         factory=self.factory,
                         max=self.max,
                         global_kargs=self.global_kargs,
                         delta=delta)
Esempio n. 4
0
 def len(self, cons):
     if self._len is None:
         self._error('len(tokens)')
         raise TypeError
     else:
         try:
             (_, line_stream) = cons.head
             return self._len - s_delta(line_stream)[OFFSET]
         except StopIteration:
             return 0
Esempio n. 5
0
 def len(self, cons):
     if self._len is None:
         self._error('len(tokens)')
         raise TypeError
     else:
         try:
             (_, line_stream) = cons.head
             return self._len - s_delta(line_stream)[OFFSET]
         except StopIteration:
             return 0
Esempio n. 6
0
 def stream(self, state, value, id_=None, max=None):
     (cons, line_stream) = state
     id_ = self.id if id_ is None else id_
     max = max if max else self.max
     next_line_stream = \
         self.factory(value, id=id_, factory=self.factory, max=max,
                      global_kargs=self.global_kargs,
                      cache_level=self.cache_level+1,
                      delta=s_delta(line_stream))
     return ((cons, next_line_stream), self)
Esempio n. 7
0
 def key(self, state, other):
     try:
         line_stream = state_to_line_stream(state)
         offset = s_delta(line_stream)[OFFSET]
     except StopIteration:
         self._warn('Default hash')
         offset = -1
     key = HashKey(self.id ^ offset ^ hash(other), (self.id, other))
     #self._debug(fmt('Hash at {0!r} ({1}): {2}', state, offset, hash(key)))
     return key
Esempio n. 8
0
 def stream(self, state, value, id_=None, max=None):
     (cons, line_stream) = state
     id_ = self.id if id_ is None else id_
     max = max if max else self.max
     next_line_stream = \
         self.factory(value, id=id_, factory=self.factory, max=max, 
                      global_kargs=self.global_kargs, 
                      cache_level=self.cache_level+1,
                      delta=s_delta(line_stream))
     return ((cons, next_line_stream), self)
Esempio n. 9
0
 def key(self, state, other):
     try:
         line_stream = state_to_line_stream(state)
         offset = s_delta(line_stream)[OFFSET]
     except StopIteration:
         self._warn('Default hash')
         offset = -1
     key = HashKey(self.id ^ offset ^ hash(other), (self.id, other))
     #self._debug(fmt('Hash at {0!r} ({1}): {2}', state, offset, hash(key)))
     return key
Esempio n. 10
0
 def fmt_stream(self):
     '''
     Provide a standard fmt for location.
     '''
     try:
         (offset, line_no, char) = s_delta(self.generator.stream)
         locn = fmt('{0}/{1}.{2}', offset, line_no, char)
         try:
             stream = sample('', s_line(self.generator.stream, False)[0], 9)
         except StopIteration:
             stream = '<EOS>'
         return (stream, offset, locn)
     except StopIteration:
         return ('<EOS>', -1, '')
     except TypeError:
         return (self.generator.stream, -1, '')
Esempio n. 11
0
 def fmt_stream(self):
     '''
     Provide a standard fmt for location.
     '''
     try:
         (offset, lineno, char) = s_delta(self.generator.stream)
         locn = fmt('{0}/{1}.{2}', offset, lineno, char)
         try:
             stream = sample('', s_line(self.generator.stream, False)[0], 9)
         except StopIteration:
             stream = '<EOS>'
         return (stream, offset, locn)
     except StopIteration:
         return ('<EOS>', -1, '')
     except TypeError:
         return (self.generator.stream, -1, '')
Esempio n. 12
0
 def _match(self, in_stream):
     '''
     Implement matching - pass token stream to tokens.
     '''
     (max, clean_stream) = s_new_max(in_stream)
     try:
         length = s_len(in_stream)
     except TypeError:
         length = None
     factory = s_factory(in_stream)
     token_stream = factory.to_token(
                         self._tokens(clean_stream, max), 
                         id=s_id(in_stream), factory=factory, 
                         max=s_max(in_stream), 
                         global_kargs=s_global_kargs(in_stream),
                         delta=s_delta(in_stream), len=length,
                         cache_level=s_cache_level(in_stream)+1) 
     in_stream = None
     generator = self.matcher._match(token_stream)
     while True:
         yield (yield generator)
Esempio n. 13
0
 def _match(self, in_stream):
     '''
     Implement matching - pass token stream to tokens.
     '''
     (max, clean_stream) = s_new_max(in_stream)
     try:
         length = s_len(in_stream)
     except TypeError:
         length = None
     factory = s_factory(in_stream)
     token_stream = factory.to_token(self._tokens(clean_stream, max),
                                     id=s_id(in_stream),
                                     factory=factory,
                                     max=s_max(in_stream),
                                     global_kargs=s_global_kargs(in_stream),
                                     delta=s_delta(in_stream),
                                     len=length,
                                     cache_level=s_cache_level(in_stream) +
                                     1)
     in_stream = None
     generator = self.matcher._match(token_stream)
     while True:
         yield (yield generator)
Esempio n. 14
0
 def delta(self, state):
     line_stream = state_to_line_stream(state)
     return s_delta(line_stream)
Esempio n. 15
0
 def _next_line(self, cons, empty_line_stream):
     delta = s_delta(empty_line_stream)
     delta = (delta[OFFSET], delta[LINE_NO]+1, 1)
     return self.factory(cons.head, id=self.id, factory=self.factory,
                         max=self.max, global_kargs=self.global_kargs, 
                         delta=delta)
Esempio n. 16
0
 def delta(self, state):
     line_stream = state_to_line_stream(state)
     return s_delta(line_stream)