def expand(self, values, previous): """ Expand macro with actual values, returns a list of expanded tokens """ tokens = [] for token in self.tokens: if token.kind == IDENTIFIER and token.value in self.args: idx = self.args.index(token.value) value = values[idx] tokens += value else: tokens.append(token) return [Token(tok.kind, tok.value, add_previous(tok.location, previous)) for tok in tokens]