Пример #1
0
 def resolveConstructor(self, context):
     from prompto.type.CategoryType import CategoryType
     try:
         ctor = ConstructorExpression(CategoryType(self.name), None, None)
         ctor.check(context)
         return ctor
     except SyntaxError as e:
         return None
Пример #2
0
 def populateError(self, e, context):
     error = e.getExpression(context)
     if error == None:
         exp = ConstructorExpression(CategoryType("Error"), None, None)
         args = ArgumentList()
         args.append(Argument(UnresolvedParameter("name"), TextLiteral(type(e).__name__)))
         args.append(Argument(UnresolvedParameter("text"), TextLiteral(e.getMessage())))
         exp.setArguments(args)
         error = exp
     if context.getRegisteredValue(INamedInstance, self.errorName) == None:
         context.registerValue(ErrorVariable(self.errorName))
     if isinstance(error, IExpression):
         error = error.interpret(context)
     context.setValue(self.errorName, error)
     return error
Пример #3
0
 def resolveUnresolvedDeclaration(self, context, name):
     decl = context.getRegisteredDeclaration(IDeclaration, name)
     if decl is None:
         raise SyntaxError("Unknown name:" + name)
     if isinstance(decl, CategoryDeclaration):
         return ConstructorExpression(CategoryType(name), None, self.arguments)
     else:
         return MethodCall(MethodSelector(name), self.arguments)
Пример #4
0
 def interpret(self, context, errorName):
     exp = self.getExpression(context)
     if exp is None:
         from prompto.grammar.Argument import Argument
         from prompto.grammar.ArgumentList import ArgumentList
         from prompto.expression.ConstructorExpression import ConstructorExpression
         from prompto.param.UnresolvedParameter import UnresolvedParameter
         from prompto.literal.TextLiteral import TextLiteral
         from prompto.type.CategoryType import CategoryType
         args = ArgumentList()
         args.append(
             Argument(UnresolvedParameter("name"),
                      TextLiteral(type(self).__name__)))
         args.append(
             Argument(UnresolvedParameter("text"),
                      TextLiteral(self.message)))
         exp = ConstructorExpression(CategoryType("Error"), args, None)
     if context.getRegisteredValue(object, errorName) is None:
         from prompto.runtime.ErrorVariable import ErrorVariable
         context.registerValue(ErrorVariable(errorName))
     error = exp.interpret(context)
     context.setValue(errorName, error)
     return error