Esempio n. 1
0
 def inferType(self, context):
     inferred = None
     # first pass: get less specific type
     for current in self.values():
         if inferred is None or inferred is NullType.instance:
             inferred = current
         elif inferred.isAssignableFrom(context, current):
             inferred = current if current is DecimalType.instance else inferred
         elif current.isAssignableFrom(context, inferred):
             inferred = current
         else:
             common = self.inferCommonBaseType(context, inferred, current)
             if common is not None:
                 inferred = common
             else:
                 raise SyntaxError("Incompatible types: " +
                                   inferred.typeName + " and " +
                                   current.typeName)
     if inferred is None:
         return VoidType.instance
     # second pass: check compatible
     for current in self.values():
         if not inferred.isAssignableFrom(context, current):
             raise SyntaxError("Incompatible types: " + inferred.typeName +
                               " and " + current.typeName)
     return inferred
Esempio n. 2
0
 def check(self, context):
     if not context.isWithResourceContext():
         raise SyntaxError("Not a resource context!")
     sourceType = self.resource.check(context)
     if not isinstance(sourceType, ResourceType):
         raise SyntaxError("Not a readable resource!")
     return TextType.instance
Esempio n. 3
0
 def checkQuery(self, context):
     if getattr(self.left, "checkQuery", None) is None:
         raise SyntaxError("Not a predicate: " + str(self.left))
     if getattr(self.right, "checkQuery", None) is None:
         raise SyntaxError("Not a predicate: " + str(self.right))
     self.left.checkQuery(context)
     self.right.checkQuery(context)
Esempio n. 4
0
 def checkAttribute(self, context):
     decl = context.findAttribute(self.name)
     if decl is None:
         raise SyntaxError("Expected an attribute, found: " + self.name)
     if not decl.storable:
         raise SyntaxError(self.name + " is not storable")
     return decl
Esempio n. 5
0
 def inferType(self, context):
     if len(self) == 0:
         return VoidType.instance
     inferred = None
     # first pass: get less specific type
     for t in self.values():
         if t is NullType.instance:
             continue
         elif inferred is None:
             inferred = t
         elif inferred.isAssignableFrom(context, t):
             continue
         elif t.isAssignableFrom(context, inferred):
             inferred = t
         else:
             raise SyntaxError("Incompatible types: " + inferred.typeName +
                               " and " + t.typeName)
     if inferred is None:
         return NullType.instance
     # second pass: check compatible
     for t in self.itervalues():
         if not inferred.isAssignableFrom(context, t):
             raise SyntaxError("Incompatible types: " + inferred.typeName +
                               " and " + t.typeName)
     return inferred
Esempio n. 6
0
 def interpretQuery(self, context, query):
     if getattr(self.left, "interpretQuery", None) is None:
         raise SyntaxError("Not a predicate: " + str(self.left))
     self.left.interpretQuery(context, query)
     if getattr(self.right, "interpretQuery", None) is None:
         raise SyntaxError("Not a predicate: " + str(self.right))
     self.right.interpretQuery(context, query)
     query.And()
Esempio n. 7
0
 def check(self, context):
     try:
         value = context.getValue(self.name)
         if isinstance(value, CodeValue):
             return value.check(context)
         else:
             raise SyntaxError("Expected code, found:" + str(value))
     except PromptoError, e:
         raise SyntaxError(e.getMessage())
Esempio n. 8
0
 def getStaticMemberValue(self, context, name):
     from prompto.declaration.EnumeratedCategoryDeclaration import EnumeratedCategoryDeclaration
     decl = context.getRegisteredDeclaration(IDeclaration, self.typeName)
     if not isinstance(decl, EnumeratedCategoryDeclaration):
         raise SyntaxError(self.typeName + " is not an enumerated type!")
     if "symbols" == name:
         return decl.getSymbols()
     else:
         raise SyntaxError("Unknown member:" + name)
Esempio n. 9
0
 def check(self, context):
     firstType = None if self.first is None else self.first.check(context)
     lastType = None if self.last is None else self.last.check(context)
     if firstType is not None and not isinstance(firstType, IntegerType):
         raise SyntaxError(str(firstType) + " is not an integer")
     if lastType is not None and not isinstance(lastType, IntegerType):
         raise SyntaxError(str(lastType) + " is not an integer")
     parentType = self.parent.check(context)
     return parentType.checkSlice(context)
Esempio n. 10
0
 def interpretValue(self, context, lval, rval):
     if isinstance(lval, BooleanValue):
         if isinstance(rval, BooleanValue):
             return BooleanValue.ValueOf(lval.getValue() or rval.getValue())
         else:
             raise SyntaxError("Illegal: Boolean and " +
                               type(rval).__name__)
     else:
         raise SyntaxError("Illegal: " + type(lval).__name__ + " + " +
                           type(rval).__name__)
Esempio n. 11
0
 def check(self, context):
     listType = self.source.check(context)
     if not isinstance(listType, IterableType):
         raise SyntaxError("Expecting an iterable type as data source!")
     itemType = listType.itemType
     arrow = self.predicate.toArrowExpression()
     filterType = arrow.checkFilter(context, itemType)
     if filterType is not BooleanType.instance:
         raise SyntaxError("Filtering expression must return a boolean!")
     return ListType(itemType)
Esempio n. 12
0
 def interpret(self, context):
     lval = self.left.interpret(context)
     if not isinstance(lval, BooleanValue):
         raise SyntaxError("Illegal: " + type(lval).__name__ +
                           " and ..., expected a Boolean ")
     if lval is BooleanValue.FALSE:
         return lval
     rval = self.right.interpret(context)
     if not isinstance(rval, BooleanValue):
         raise SyntaxError("Illegal: Boolean and " + type(rval).__name__)
     return rval
Esempio n. 13
0
 def toPredicate(self, context):
     decl = context.findAttribute(self.name)
     if decl is None:
         raise SyntaxError("Unknown identifier:" + self.name)
     elif decl.getType(context)!=BooleanType.instance:
         raise SyntaxError("Expected a Boolean, found: " + decl.getType(context).typeName)
     else:
         from prompto.expression.EqualsExpression import EqualsExpression
         from prompto.grammar.EqOp import EqOp
         from prompto.literal.BooleanLiteral import BooleanLiteral
         return EqualsExpression(self, EqOp.EQUALS, BooleanLiteral("true"))
Esempio n. 14
0
def getTargetAtomicType(context, itype):
    decl = context.getRegisteredDeclaration(IDeclaration, itype.typeName)
    if decl is None:
        raise SyntaxError("Unknown identifier: " + itype.typeName)
    elif isinstance(decl, MethodDeclarationMap):
        if len(decl) == 1:
            return MethodType(decl.getFirst())
        else:
            raise SyntaxError("Ambiguous identifier: " + itype.typeName)
    else:
        return decl.getType(context)
 def doProcessCategory(self, annotation, context, declaration):
     fieldName = annotation.getArgument("name")
     fieldType = annotation.getArgument("type")
     if not isinstance(fieldName, TextLiteral):
         raise SyntaxError("WidgetField requires a Text value for argument 'name'")
     elif not isinstance(fieldType, (TypeExpression, TypeLiteral)):
         raise SyntaxError("WidgetField requires a Type value for argument 'type'")
     else:
         name = str(fieldName)
         typ = fieldType.typ
         context.registerValue(Variable(name[1:-1], typ), False)
Esempio n. 16
0
 def getCategoryCandidates(self, context):
     from prompto.declaration.ConcreteCategoryDeclaration import ConcreteCategoryDeclaration
     from prompto.type.CategoryType import CategoryType
     itype = self.checkParent(context)
     if not isinstance(itype, CategoryType):
         raise SyntaxError(self.parent.toString() + " is not a category")
     cd = context.getRegisteredDeclaration(ConcreteCategoryDeclaration,
                                           itype.typeName)
     if cd is None:
         raise SyntaxError("Unknown category:" + itype.typeName)
     return cd.getMemberMethods(context, self.name)
Esempio n. 17
0
 def checkAttribute(self, context, name):
     decl = context.getRegisteredDeclaration(IDeclaration, self.typeName)
     if decl is None:
         raise SyntaxError("Unknown category:" + self.typeName)
     from prompto.declaration.CategoryDeclaration import CategoryDeclaration
     from prompto.declaration.EnumeratedNativeDeclaration import EnumeratedNativeDeclaration
     if isinstance(decl, EnumeratedNativeDeclaration):
         return decl.typ.checkMember(context, name)
     elif isinstance(decl, CategoryDeclaration):
         return self.checkCategoryMember(context, decl, name)
     else:
         raise SyntaxError("Not a category:" + self.typeName)
Esempio n. 18
0
    def checkStaticMember(self, context, name):
        from prompto.declaration.SingletonCategoryDeclaration import SingletonCategoryDeclaration

        decl = context.getRegisteredDeclaration(IDeclaration, self.typeName)
        if decl is None:
            raise SyntaxError("Unknown category:" + self.typeName)
        if isinstance(decl, IEnumeratedDeclaration):
            return decl.getType(context).checkStaticMember(context, name)
        elif isinstance(decl, SingletonCategoryDeclaration):
            return self.checkCategoryMember(context, decl, name)
        else:
            raise SyntaxError("No attribute:" + name + " in category:" +
                              self.typeName)
Esempio n. 19
0
 def makeArgument(self, context, declaration):
     parameter = self.parameter
     # when 1st argument, can be unnamed
     if parameter is None:
         if len(declaration.getArguments()) == 0:
             raise SyntaxError("Method has no argument")
         parameter = declaration.getArguments()[0]
     else:
         parameter = declaration.getArguments().find(self.getName())
     if parameter is None:
         raise SyntaxError("Method has no argument:" + self.getName())
     expression = ContextualExpression(context, self.getExpression())
     return Argument(parameter, expression)
Esempio n. 20
0
 def check(self, context):
     resContext = context if isinstance(
         context, ResourceContext) else context.newResourceContext()
     resourceType = self.resource.check(resContext)
     if not isinstance(resourceType, ResourceType):
         raise SyntaxError("Not a resource!")
     if self.thenWith is None:
         return VoidType.instance
     else:
         if isinstance(context, ResourceContext):
             raise SyntaxError(
                 "Then with is only supported in simple read !")
         return self.thenWith.check(resContext, TextType.instance)
Esempio n. 21
0
 def interpret(self, context):
     o = self.parent.interpret(context)
     if o is None:
         raise NullReferenceError()
     if isinstance(o, ISliceable):
         fi = None if self.first is None else self.first.interpret(context)
         if fi is not None and not isinstance(fi, IntegerValue):
             raise SyntaxError("Illegal sliced type: " + str(fi))
         li = None if self.last is None else self.last.interpret(context)
         if li is not None and not isinstance(li, IntegerValue):
             raise SyntaxError("Illegal sliced type: " + str(li))
         return o.slice(fi, li)
     else:
         raise SyntaxError("Illegal sliced object: " + self.parent)
Esempio n. 22
0
 def Multiply(self, context, value):
     from prompto.value.IntegerValue import IntegerValue
     if isinstance(value, IntegerValue):
         from prompto.value.TextValue import TextValue
         count = value.IntegerValue()
         if count < 0:
             raise SyntaxError("Negative repeat count:" + count)
         if count == 0:
             return TextValue("")
         if count == 1:
             return TextValue(self.value)
         return TextValue(self.value * count)
     else:
         raise SyntaxError("Illegal: Character * " + type(value).__name__)
Esempio n. 23
0
 def check(self, context):
     from prompto.declaration.EnumeratedCategoryDeclaration import EnumeratedCategoryDeclaration
     cd = context.getRegisteredDeclaration(EnumeratedCategoryDeclaration,
                                           self.itype.typeName)
     if cd is None:
         raise SyntaxError("Unknown category " + self.itype.typeName)
     if self.arguments is not None:
         context = context.newLocalContext()
         for argument in self.arguments:
             if not cd.hasAttribute(context, argument.getName()):
                 raise SyntaxError("\"" + argument.getName() + \
                                   "\" is not an attribute of " + self.itype.typeName)
             argument.check(context)
     return self.itype
Esempio n. 24
0
 def Multiply(self, context, value):
     if isinstance(value, IntegerValue):
         count = value.IntegerValue()
         if count < 0:
             raise SyntaxError("Negative repeat count:" + count)
         elif count == 0:
             return ListValue(self.itype.itemType)
         elif count == 1:
             return self
         else:
             result = []
             for i in range(1, count + 1):
                 result.extend(self.items)
             return ListValue(self.itype.itemType, items=result)
     else:
         raise SyntaxError("Illegal: List * " + type(value).__name__)
Esempio n. 25
0
 def filter(o):
     local.setValue(self.args[0], o)
     result = self.statements.interpret(local)
     if isinstance(result, BooleanValue):
         return result.value
     else:
         raise SyntaxError("Expecting a Boolean result!")
Esempio n. 26
0
 def __lt__(self, other):
     self.context.setValue(self.arrow.args[0], self.value)
     self.context.setValue(self.arrow.args[1], other.value)
     result = self.arrow.statements.interpret(self.context)
     if not isinstance(result, IntegerValue):
         raise SyntaxError("Expected an Integer, got a " + result.itype)
     return result.value < 0
Esempio n. 27
0
 def Add(self, context, value):
     if isinstance(value, PeriodValue):
         return self.plusPeriod(value)
     elif isinstance(value, TimeValue):
         return self.plusTime(value)
     else:
         raise SyntaxError("Illegal: Date + " + type(value).__name__)
Esempio n. 28
0
 def getMemberMethods(self, context, name):
     from prompto.declaration.ConcreteCategoryDeclaration import ConcreteCategoryDeclaration
     cd = self.getDeclaration(context)
     if not isinstance(cd, ConcreteCategoryDeclaration):
         raise SyntaxError("Unknown category:" + self.typeName)
     else:
         return cd.getMemberMethodsMap(context, name).values()
Esempio n. 29
0
 def checkDerived(self, context):
     if self.derivedFrom is not None:
         for category in self.derivedFrom:
             cd = context.getRegisteredDeclaration(
                 ConcreteCategoryDeclaration, category)
             if cd is None:
                 raise SyntaxError("Unknown category: \"" + category + "\"")
Esempio n. 30
0
 def getSortKeyReader(self, context, itemType):
     if len(self.args) == 1:
         return self.getSortKeyReader1Arg(context, itemType)
     elif len(self.args) == 2:
         return self.getSortKeyReader2Args(context, itemType)
     else:
         raise SyntaxError("Expecting 1 or 2 parameters only!")