def _show_mixfix(self, opr, args): res = [] for part in lexer.operator_to_parts(opr): if part == '': res.append(args.pop(0).showp()) else: res.append(part) return ' '.join(res)
def is_status_prefix_in_level(self, key, status): if status in [[], ['']]: return True level = self._table[key] for operator in level.operators(): if is_prefix(status, lexer.operator_to_parts(operator)): return True return False
def show_arrow_type(self): parts = [] res = self while res.is_arrow_type(): parts.append(res.fun.arg.showp()) res = res.arg parts.append(res.show()) [_, arrow, _] = lexer.operator_to_parts(common.OP_ARROW) return ' {arrow} '.format(arrow=arrow).join(parts)
def declare_operator(self, fixity, precedence, name, position=None): if not common.is_operator(name): self.fail('not-an-operator', name=name, position=position) if name in self._operators: self.fail('operator-already-exists', name=name, position=position) for part in lexer.operator_to_parts(name): if part != '': self._parts.add(part) self._operators.add(name) key = precedence, fixity if key not in self._table: self._table[key] = PrecedenceLevel(fixity, precedence) self._table_keys = sorted(self._table.keys()) self._table[key].declare_operator(name)
def _operator_arity(self, opr): arity = 0 for part in lexer.operator_to_parts(opr): if part == '': arity += 1 return arity
def is_binary_operator(name): parts = lexer.operator_to_parts(name) return len(parts) == 3 \ and parts[0] == '' \ and parts[1] != '' \ and parts[2] == ''
def is_binop_in_level(self, key, name): level = self._table[key] for operator in level.operators(): if lexer.operator_to_parts(operator) == ['', name, '']: return True return False
def is_status_in_level(self, key, status): level = self._table[key] for operator in level.operators(): if status == lexer.operator_to_parts(operator): return True return False