def evaluate(self, settings, adjustment=0, exclude=()): from line import EmptyLine output = [] falltag = None falldata = {} for statement in self.statements: if isinstance(statement, EmptyLine): # Empty lines can not raise FallThrough and should not # consume FallThrough data output.append(statement.evaluate(settings)) continue if exclude and isinstance(statement.node, exclude): continue if not statement.accepts(settings, falltag): if falltag is None: # The don't accept us sending no data # This must be a follower-only function called alone raise ConversionError( 'Function %s can not be called on its own.' % statement.name) falldata = {} try: result = statement.evaluate(settings, **falldata) falltag, falldata = None, {} except FallThrough as e: result, falltag, falldata = e.result, e.tag, e.data except ConversionError as e: e.contexts.append(statement) raise except Exception as e: raise convert(e, statement) output.append(result) return settings.join(output)
def parse(self, input): lexer = Lexer().build(debug=self.debug, optimize=self.optimize, lextab='cm.lexer.output.lextab') try: return self.parser.parse(input, lexer=lexer, debug=self.debug) except SyntaxError as e: raise convert(e, self.context)
def include(filename, settings, **context): try: return settings.render(filename, context) except Exception as e: from cm.exceptions import convert raise convert(e, filename)