| 70 | SEQUENCE = enum.auto() |
| 71 | |
| 72 | class Field(AST): |
| 73 | def __init__(self, type, name=None, quantifiers=None): |
| 74 | self.type = type |
| 75 | self.name = name |
| 76 | self.seq = False |
| 77 | self.opt = False |
| 78 | self.quantifiers = quantifiers or [] |
| 79 | if len(self.quantifiers) > 0: |
| 80 | self.seq = self.quantifiers[-1] is Quantifier.SEQUENCE |
| 81 | self.opt = self.quantifiers[-1] is Quantifier.OPTIONAL |
| 82 | |
| 83 | def __str__(self): |
| 84 | extra = "" |
| 85 | for mod in self.quantifiers: |
| 86 | if mod is Quantifier.SEQUENCE: |
| 87 | extra += "*" |
| 88 | elif mod is Quantifier.OPTIONAL: |
| 89 | extra += "?" |
| 90 | |
| 91 | return "{}{} {}".format(self.type, extra, self.name) |
| 92 | |
| 93 | def __repr__(self): |
| 94 | if self.quantifiers: |
| 95 | texts = [] |
| 96 | for mod in self.quantifiers: |
| 97 | if mod is Quantifier.SEQUENCE: |
| 98 | texts.append("SEQUENCE") |
| 99 | elif mod is Quantifier.OPTIONAL: |
| 100 | texts.append("OPTIONAL") |
| 101 | extra = ", quantifiers=[{}]".format(", ".join(texts)) |
| 102 | else: |
| 103 | extra = "" |
| 104 | |
| 105 | if self.name is None: |
| 106 | return 'Field({0.type}{1})'.format(self, extra) |
| 107 | else: |
| 108 | return 'Field({0.type}, {0.name}{1})'.format(self, extra) |
| 109 | |
| 110 | class Sum(AST): |
| 111 | def __init__(self, types, attributes=None): |
no outgoing calls
no test coverage detected
searching dependent graphs…