Beispiel #1
0
 def check(self, context):
     itype = self.source.check(context)
     if not isinstance(itype, (ListType, TupleType, SetType)):
         raise SyntaxError("Unsupported type: " + str(itype))
     return type
Beispiel #2
0
 def checkQuery(self, context):
     if getattr(self.expression, "checkQuery", None) is None:
         raise SyntaxError("Not a predicate: " + str(self.expression))
     self.expression.checkQuery(context)
Beispiel #3
0
 def interpretQuery(self, context, query):
     if getattr(self.expression, "interpretQuery", None) is None:
         raise SyntaxError("Not a predicate: " + str(self.expression))
     self.expression.interpretQuery(context, query)
     query.Not()
Beispiel #4
0
 def check(self, context):
     actual = self.expression.check(context)
     if not self.itype.getDerivedFrom().isAssignableFrom(context, actual):
         raise SyntaxError("Cannot assign " + actual.getName() + " to " + self.itype.getDerivedFrom().getName())
     return self.itype
Beispiel #5
0
 def CompareTo(self, context, value):
     if isinstance(value, TimeValue):
         return cmp(self.value, value.value)
     else:
         raise SyntaxError("Illegal comparison: Time + " +
                           type(value).__name__)
Beispiel #6
0
 def setItem(self, context, index, value):
     if isinstance(index, TextValue):
         self.values[index.value] = value
     else:
         raise SyntaxError("No such item:" + index.toString())
Beispiel #7
0
 def register(self, context):
     actual = context.getRegisteredValue(INamedInstance, self.name)
     if actual is not None:
         raise SyntaxError("Duplicate argument: \"" + self.name + "\"")
     context.registerValue(self)
Beispiel #8
0
 def checkSlice(self, context):
     raise SyntaxError("Cannot slice " + self.typeName)
Beispiel #9
0
 def checkIterator(self, context):
     raise SyntaxError("Cannot iterate over " + self.typeName)
Beispiel #10
0
 def checkMember(self, context, name):
     from prompto.type.TextType import TextType
     if "text" == name:
         return TextType.instance
     else:
         raise SyntaxError("Cannot read member from " + self.typeName)
Beispiel #11
0
 def checkStaticMember(self, context, name):
     raise SyntaxError("Cannot read member from " + self.typeName)
Beispiel #12
0
 def checkItem(self, context, itemType):
     from prompto.type.EnumeratedNativeType import EnumeratedNativeType
     if isinstance(itemType, EnumeratedNativeType):
         return self.checkContainsAllOrAny(context, itemType.derivedFrom)
     else:
         raise SyntaxError("Cannot read item from " + self.typeName)
Beispiel #13
0
 def checkQuery(self, context):
     decl = self.left.checkAttribute(context)
     if not decl.storable:
         raise SyntaxError(decl.name + " is not storable")
     rt = self.right.check(context)
     return self.checkOperator(context, decl.getType(), rt)
Beispiel #14
0
 def asMutable(self, context, mutable: bool):
     if mutable:
         raise SyntaxError("Cannot mutate " + self.typeName)
     else:
         return self
Beispiel #15
0
 def checkFilter(self, context, itemType):
     if self.args is None or len(self.args) != 1:
         raise SyntaxError("Expecting 1 parameter only!")
     context = context.newChildContext()
     context.registerValue(Variable(self.args[0], itemType))
     return self.statements.check(context, None)
Beispiel #16
0
 def checkRange(self, context, other):
     raise SyntaxError("Cannot create range of " + self.typeName + " and " +
                       other.typeName)
Beispiel #17
0
 def getItem(self, context, index):
     if isinstance(index, TextValue):
         # TODO autocreate
         return self.values.get(index.value, NullValue.instance)
     else:
         raise SyntaxError("No such item:" + index.toString())
Beispiel #18
0
 def newRange(self, left, right):
     raise SyntaxError("Cannot create range of " + self.typeName)
Beispiel #19
0
 def Add(self, context, value):
     if isinstance(value, DocumentValue):
         return DocumentValue.merge(self, value)
     else:
         raise SyntaxError("Illegal: Document + " + type(value).__name__)
Beispiel #20
0
 def checkAssignableFrom(self, context, other):
     if not self.isAssignableFrom(context, other):
         raise SyntaxError("Type: " + self.typeName +
                           " is not compatible with: " + other.typeName)
Beispiel #21
0
 def check(self, context):
     actual = context.getRegisteredDeclaration(IMethodDeclaration,
                                               self.name)
     if actual is None:
         raise SyntaxError("Unknown method: \"" + self.name + "\"")
Beispiel #22
0
 def hasItem(self, context, value):
     if isinstance(value, TextValue):
         return self.value.get(value.value, None) is not None
     else:
         raise SyntaxError("Only Text key is supported by " +
                           type(self).__name__)
Beispiel #23
0
 def Add(self, context, value):
     if isinstance(value, PeriodValue):
         return self.plus(value)
     else:
         raise SyntaxError("Illegal: Time + " + type(value).__name__)
Beispiel #24
0
 def setItem(self, context, item, value):
     if isinstance(item, TextValue):
         self.value[item.value] = value
     else:
         raise SyntaxError("No such item:" + str(item))
Beispiel #25
0
 def check(self, context):
     itype = self.expression.check(context)
     if not isinstance(itype, BooleanType):
         raise SyntaxError("Cannot negate " + itype.getName())
     return BooleanType.instance
Beispiel #26
0
 def checkConstructorContext(self, context):
     if not isinstance(context, ResourceContext):
         raise SyntaxError("Not a resource context!")
Beispiel #27
0
 def interpretValue(self, context, val):
     if isinstance(val, BooleanValue):
         return val.getNot()
     else:
         raise SyntaxError("Illegal: not " + type(val).__name__)
Beispiel #28
0
 def checkUnique(self, context):
     actual = context.getRegisteredDeclaration(IDeclaration, self.typeName)
     if actual is not None:
         raise SyntaxError("Duplicate name: \"" + self.typeName + "\"")
Beispiel #29
0
 def check(self, context):
     itype = self.expression.check(context)
     if not CategoryType("Error").isAssignableFrom(context, itype):
         raise SyntaxError(itype.getName() + " does not extend Error")
     return VoidType.instance
Beispiel #30
0
 def interpret(self, context):
     symbol = context.getRegisteredValue(Symbol, self.name)
     if symbol is None:
         raise SyntaxError("Unknown symbol:" + self.name)
     return symbol.interpret(context)