def transformUnresolvedSym(self, node): assert isinstance(node, term.UnresolvedSym) if node.sym not in self.variables: t = term.TermLiteral(term.TermLiteralKind.Variable, node.sym) #self.context.add_lit_term(t) return t expecteddepth = self.variables[node.sym] actualdepth = 0 param = self.symgen.get(node.sym) # definitely a pattern variable now, topmost entry on the stack is this node. for t in reversed(self.path): if isinstance(t, term.UnresolvedSym): if expecteddepth == 0: self.add_annotation_to(t, term.TermAttribute.MatchRead, (node.sym, param)) break self.add_annotation_to(t, term.TermAttribute.InArg, param) if isinstance(t, term.TermSequence) or isinstance(t, term.InHole): if expecteddepth == actualdepth: self.add_annotation_to(t, term.TermAttribute.MatchRead, (node.sym, param)) break else: self.add_annotation_to(t, term.TermAttribute.InArg, param) if isinstance(t, term.Repeat): actualdepth += 1 self.add_annotation_to(t, term.TermAttribute.ForEach, (param, actualdepth)) if actualdepth != expecteddepth: raise Exception( 'inconsistent ellipsis depth for pattern variable {}: expected {} actual {}' .format(node.sym, expecteddepth, actualdepth)) return self.complete_annotation(node, term.PatternVariable(node.sym))
def p_term_template_hole(t): 'term-template : HOLE' t[0] = term.TermLiteral(term.TermLiteralKind.Hole, t[1])
def p_term_template_boolean(p): 'term-template : BOOLEAN' p[0] = term.TermLiteral(term.TermLiteralKind.Boolean, normalizeboolean(p[1]))
def p_term_template_string(p): 'term-template : STRING' escaped = p[1].replace('"', '\\"') p[0] = term.TermLiteral(term.TermLiteralKind.String, escaped)
def p_term_template_integer(t): 'term-template : INTEGER' t[0] = term.TermLiteral(term.TermLiteralKind.Integer, t[1])
def p_term_template_decimal(t): 'term-template : FLOAT' t[0] = term.TermLiteral(term.TermLiteralKind.Float, t[1])