def transpile(self, mesh, path): self.path = path mesh[path + (Keyword('self'), )] = Value(repr(self)) for key, value in self.value.items(): if key == Keyword('atoms'): for i, el in enumerate(value): if isinstance(el, TypeDef): el = el.value[-1] if isinstance(el, Keyword): arg = path + (el.value, ) mesh[arg] = Keyword('placeholder') mesh['arguments'][path].append(arg) else: mesh[path + (Value(i), )] = el if isinstance(key, TypeDef): key = key.value[-1] if isinstance(key, Keyword): mesh[path + (key.value, )] = Keyword('placeholder') for key, value in self.value.items(): if isinstance(key, TypeDef): key = key.value[-1] newpath = path + (key, ) if len(value) == 1: value[0].transpile(mesh, newpath) mesh[newpath] = value[0] else: for i, vl in enumerate(value): vl.transpile(mesh, newpath) mesh[newpath] = vl
def parse(self, parser): if parser.starts_with(':'): self.key = parser.getarg() elif not parser.starts_with('('): self.value[self.key].append(parser.getarg()) if self.value[self.key][-1] is None: self.value[self.key].pop() self.key = Keyword('atoms') if parser.any_starts_with(('(', ':', ',')): parser.move() parser.parse(self, Value()) elif parser.starts_with(')'): parser.move() if (len(self.value) == 1 and len(self.value[Keyword('atoms')]) == 1): return parser.hasparsed(self.value[Keyword('atoms')][0]) parser.hasparsed(self) elif parser.starts_with('->'): parser.move(2) parser.parse(self, Value()) self.key = Keyword('self') else: parser.parse(self, Value())
def parse(self, parser): if not self.op: self.op = parser.any_starts_with(self.symbols) or None if self.op and not parser.any_starts_with(self.to_avoid): parser.move(len(self.op)) self.args.append(parser.getarg()) parser.parse(self, Value()) else: self.args.append(parser.getarg()) if (isinstance(self.args[1], Symbol) and self.priority() > self.args[1].priority()): otherobj = self.args[1] otherobj.args[0], self.args[1] = self, otherobj.args[0] parser.hasparsed(otherobj) else: parser.hasparsed(self)
def evaluate(self, mesh, interpreting, interpreted): interpreting.append( Value(self.map_to_py[self.op](interpreted.pop().value, interpreted.pop().value))) if hasattr(self, 'location'): mesh[self.location] = interpreting[-1]