MCPcopy Create free account
hub / github.com/webpy/webpy / consume_till

Method consume_till

web/template.py:504–537  ·  view source on GitHub ↗

Consumes tokens till colon. >>> tok = PythonTokenizer('for i in range(10): hello $i') >>> tok.consume_till(':') >>> tok.text[:tok.index] 'for i in range(10):' >>> tok.text[tok.index:] ' hello $i'

(self, delim)

Source from the content-addressed store, hash-verified

502 self.index = 0
503
504 def consume_till(self, delim):
505 """Consumes tokens till colon.
506
507 >>> tok = PythonTokenizer('for i in range(10): hello $i')
508 >>> tok.consume_till(':')
509 >>> tok.text[:tok.index]
510 'for i in range(10):'
511 >>> tok.text[tok.index:]
512 ' hello $i'
513 """
514 try:
515 while True:
516 t = next(self)
517 if t.value == delim:
518 break
519 elif t.value == "(":
520 self.consume_till(")")
521 elif t.value == "[":
522 self.consume_till("]")
523 elif t.value == "{":
524 self.consume_till("}")
525
526 # if end of line is found, it is an exception.
527 # Since there is no easy way to report the line number,
528 # leave the error reporting to the python parser later
529 # @@ This should be fixed.
530 if t.value == "\n":
531 break
532 except:
533 # raise ParseError, "Expected %s, found end of line." % repr(delim)
534
535 # raising ParseError doesn't show the line number.
536 # if this error is ignored, then it will be caught when compiling the python code.
537 return
538
539 def __next__(self):
540 type, t, begin, end, line = next(self.tokens)

Callers 2

read_statementMethod · 0.95
__init__Method · 0.95

Calls 1

nextFunction · 0.85

Tested by

no test coverage detected