home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / python-support / python-rdflib / rdflib / sparql / bison / FunctionLibrary.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  1.9 KB  |  64 lines

  1. """
  2. [28] FunctionCall ::= IRIref ArgList
  3. http://www.w3.org/TR/rdf-sparql-query/#evaluation
  4. """
  5. from Util import ListRedirect
  6.  
  7. STR         = 0
  8. LANG        = 1
  9. LANGMATCHES = 2
  10. DATATYPE    = 3
  11. BOUND       = 4
  12. isIRI       = 5
  13. isURI       = 6
  14. isBLANK     = 7
  15. isLITERAL   = 8
  16.  
  17. FUNCTION_NAMES = {
  18.     STR : 'STR',
  19.     LANG : 'LANG',
  20.     LANGMATCHES : 'LANGMATCHES',
  21.     DATATYPE : 'DATATYPE',
  22.     BOUND : 'BOUND',
  23.     isIRI : 'isIRI',
  24.     isURI : 'isURI',
  25.     isBLANK : 'isBLANK',
  26.     isLITERAL : 'isLITERAL',
  27. }
  28.  
  29. class FunctionCall(object):
  30.     def __init__(self,name,arguments=None):
  31.         self.name = name
  32.         self.arguments = arguments is None and [] or arguments
  33.  
  34.     def __repr__(self):
  35.         return "%s(%s)"%(self.name,','.join([isinstance(i,ListRedirect) and i.reduce() or i for i in self.arguments]))
  36.  
  37. class ParsedArgumentList(ListRedirect):
  38.     def __init__(self,arguments):
  39.         self._list = arguments
  40.  
  41. class ParsedREGEXInvocation(object):
  42.     def __init__(self,arg1,arg2,arg3=None):
  43.         self.arg1 = arg1
  44.         self.arg2 = arg2
  45.         self.arg3 = arg3
  46.  
  47.     def __repr__(self):
  48.         return "REGEX(%s,%s%s)"%(
  49.                                  isinstance(self.arg1,ListRedirect) and self.arg1.reduce() or self.arg1,
  50.                                  isinstance(self.arg2,ListRedirect) and self.arg2.reduce() or self.arg2,
  51.                                  isinstance(self.arg3,ListRedirect) and self.arg3.reduce() or self.arg3,)
  52.  
  53. class BuiltinFunctionCall(FunctionCall):
  54.     def __init__(self,name,arg1,arg2=None):
  55.         if arg2:
  56.             arguments = [arg1,arg2]
  57.         else:
  58.             arguments = [arg1]
  59.         super(BuiltinFunctionCall,self).__init__(name,arguments)
  60.  
  61.     def __repr__(self):
  62.         #print self.name
  63.         #print [type(i) for i in self.arguments]
  64.         return "%s(%s)"%(FUNCTION_NAMES[self.name],','.join([isinstance(i,ListRedirect) and str(i.reduce()) or i for i in self.arguments]))