Esempio n. 1
0
File: oaa.py Progetto: jbalint/spark
 def functor(self, object):
     if object.isStruct():
         functor = getFunctor(object)
         if functor == ATOM_FUNCTOR:
             return None
         elif functor == NULLARY_FUNCTOR:
             functor = object.getTerm(0).toString()
         return functor
     elif object.isList():
         return None
     else:
         raise ConstructorValueException("Not a compound object")
Esempio n. 2
0
File: oaa.py Progetto: jbalint/spark
 def createVariable(self, start, end, string):
     name = str(string)
     if name.startswith("$$"):
         raise ConstructorValueException(
             "Cannot create an ICL variable equivalent to a captured variable"
         )
     minusDollar = name[1:]
     stripped = minusDollar.lstrip(
         "_")  # look for first character after $_*
     if stripped == "" or stripped[0] not in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
         return IclVar("_" + minusDollar)
     else:
         return IclVar(minusDollar)
Esempio n. 3
0
File: oaa.py Progetto: jbalint/spark
 def components(self, obj):
     if obj.isList():
         return [x for x in obj.iterator()]
     elif obj.isStruct():
         functor = getFunctor(obj)
         if functor == ATOM_FUNCTOR:
             return None
         elif functor == NULLARY_FUNCTOR:
             return ()
         else:
             return [x for x in obj.iterator()]
     else:
         raise ConstructorValueException("Not a compound object")
Esempio n. 4
0
File: oaa.py Progetto: jbalint/spark
 def asString(self, obj):
     if obj.isStr():
         return obj.toUnquotedString()
     elif obj.isVar():
         name = iclVarName(obj)
         stripped = name.lstrip("_")
         if stripped == "" or stripped[
                 0] not in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
             return '$' + name[1:]
         else:
             return '$' + name
     elif obj.isStruct():
         functor = getFunctor(obj)
         args = [icl_to_value(x) for x in obj.iterator()]
         if functor == ATOM_FUNCTOR and obj.getNumChildren() == 1:
             return obj.getTerm(0).toUnquotedString()
     elif obj.isIclDataQ():
         return dataq_to_string(obj, None)[1]
     else:
         raise ConstructorValueException(
             "Not a String, Variable, or Symbol")
Esempio n. 5
0
File: oaa.py Progetto: jbalint/spark
 def category(self, object):
     if object.isStr():
         return self.STRING
     elif object.isInt():
         return self.INTEGER
     elif object.isFloat():
         return self.FLOAT
     elif object.isStruct():
         functor = getFunctor(object)
         if functor == ATOM_FUNCTOR:
             return self.SYMBOL
         else:
             return self.STRUCTURE
     elif object.isList():
         return self.LIST
     elif object.isVar():
         return self.VARIABLE
     elif object.isIclDataQ():
         return self.STRING
     else:
         raise ConstructorValueException("Not a valid object")
Esempio n. 6
0
File: oaa.py Progetto: jbalint/spark
 def asBigInteger(self, obj):
     raise ConstructorValueException("Cannot handle big integers")
Esempio n. 7
0
File: oaa.py Progetto: jbalint/spark
 def asInteger(self, obj):
     try:
         i = obj.toInt()
         return int(i)
     except:
         raise ConstructorValueException("Not a valid integer: %r" % obj)
Esempio n. 8
0
File: oaa.py Progetto: jbalint/spark
 def asFloat(self, obj):
     try:
         return obj.toFloat()
     except:
         raise ConstructorValueException("Not a Float: %r" % obj)
Esempio n. 9
0
File: oaa.py Progetto: jbalint/spark
 def createBigInteger(self, start, end, integer):
     raise ConstructorValueException("Cannot handle big integers")