def parse(self, loc, l, parent): if self.parent_contents: contents_from = parent else: contents_from = self rv = self.node_type(loc) condition = l.require(l.python_expression) l.require(':') block = slast.SLBlock(loc) contents_from.parse_contents(l, block, block_only=True) rv.entries.append((condition, block)) state = l.checkpoint() while l.advance(): loc = l.get_location() if l.keyword("elif"): condition = l.require(l.python_expression) l.require(':') block = slast.SLBlock(loc) contents_from.parse_contents(l, block, block_only=True) rv.entries.append((condition, block)) state = l.checkpoint() elif l.keyword("else"): condition = None l.require(':') block = slast.SLBlock(loc) contents_from.parse_contents(l, block, block_only=True) rv.entries.append((condition, block)) state = l.checkpoint() break else: l.revert(state) break return rv
def parse(self, l, parent): rv = slast.SLIf() condition = l.require(l.python_expression) l.require(':') block = slast.SLBlock() parent.parse_contents(l, block, block_only=True) rv.entries.append((condition, block)) state = l.checkpoint() while l.advance(): if l.keyword("elif"): condition = l.require(l.python_expression) l.require(':') block = slast.SLBlock() parent.parse_contents(l, block, block_only=True) rv.entries.append((condition, block)) state = l.checkpoint() elif l.keyword("else"): condition = None l.require(':') block = slast.SLBlock() parent.parse_contents(l, block, block_only=True) rv.entries.append((condition, block)) state = l.checkpoint() break else: l.revert(state) break return rv
def parse(self, loc, l, parent, keyword): arguments = [] # Parse positional arguments. for _i in range(self.positional): expr = l.require(l.simple_expression) arguments.append((None, expr)) # Parser keyword arguments and children. block = slast.SLBlock(loc) can_has = (self.nchildren == 1) self.parse_contents(l, block, can_has=can_has, can_tag=False) # Add the keyword arguments, and create an ArgumentInfo object. arguments.extend(block.keyword) block.keyword = [] args = renpy.ast.ArgumentInfo(arguments, None, None) # We only need a SLBlock if we have children. if not block.children: block = None # Create the Use statement. return slast.SLUse(loc, self.screen, args, None, block)
def parse(self, loc, l, parent, keyword): if l.keyword('expression'): target = l.require(l.simple_expression) l.keyword('pass') else: target = l.require(l.word) args = renpy.parser.parse_arguments(l) if l.keyword('id'): id_expr = l.simple_expression() else: id_expr = None if l.match(':'): l.expect_eol() l.expect_block("use statement") block = slast.SLBlock(loc) self.parse_contents(l, block, can_has=True, block_only=True) else: l.expect_eol() l.expect_noblock("use statement") block = None return slast.SLUse(loc, target, args, id_expr, block)
def parse(self, loc, l, parent, keyword): arguments = [] # Parse positional arguments. for _i in self.positional: expr = l.simple_expression() if expr is None: break arguments.append(expr) # Parser keyword arguments and children. block = slast.SLBlock(loc) can_has = (self.nchildren == 1) self.parse_contents(l, block, can_has=can_has, can_tag=False) if len(arguments) != len(self.positional): if not block.keyword_exist("arguments"): l.error( "{} statement expects {} positional arguments, got {}.". format(self.name, len(self.positional), len(arguments))) return slast.SLCustomUse(loc, self.screen, arguments, block)