Exemplo n.º 1
0
 def p_type(p):
     """type : WORD
             | WORD OP_LT type OP_GT
             | OP_OPEN_BRACE typednames OP_CLOSE_BRACE
             | KW_ENUM OP_OPEN_BRACE enum_cases OP_CLOSE_BRACE
             | OP_OPEN_PAREN typelist OP_CLOSE_PAREN
             | KW_NATIVE STRINGLITERAL"""
     if len(p) == 2:
         p[0] = syntax.TNamed(p[1])
     elif len(p) == 3:
         p[0] = syntax.TNative(p[2])
     elif len(p) == 5:
         if p[1] == "enum":
             p[0] = syntax.TEnum(p[3])
         else:
             p[0] = syntax.TApp(p[1], p[3])
     elif len(p) == 4:
         if p[1] == "{":
             p[0] = syntax.TRecord(p[2])
         elif p[1] == "(":
             p[0] = syntax.TTuple(p[2])
Exemplo n.º 2
0
 def visit_EMakeRecord(self, e):
     fields = []
     for f, val in e.fields:
         self.visit(val)
         fields.append((f, val.type))
     e.type = syntax.TRecord(tuple(fields))
Exemplo n.º 3
0
 def visit_TRecord(self, t):
     return syntax.TRecord(tuple((f, self.visit(ft)) for f, ft in t.fields))