def completeElement(self, ctx):
		try:
			parsedFields = utils.pyparseString(self._fieldsGrammar, self.content_)
		except pyparsing.ParseBaseException, ex:
			raise base.ui.logOldExc(base.LiteralParseError("binaryRecordDef", 
				re.sub("\s+", " ", self.content_),
				pos=str(ex.loc), hint="The parser said: '%s'"%str(ex)))
Пример #2
0
def parseDateExprToMJD(str,
                       baseSymbol=getComplexGrammar(_DATE_LITERAL_DT,
                                                    _makeMJDPmNode,
                                                    floatLiteral, MJDNode)):
    """returns a parse tree for vizier-like expression of ISO dates with
	parsed values in MJD.
	"""
    return utils.pyparseString(baseSymbol, str)[0]
Пример #3
0
def parseDateExpr(str,
                  baseSymbol=getComplexGrammar(_DATE_LITERAL_DT,
                                               _makeDatePmNode, floatLiteral,
                                               DateNode)):
    """returns a parse tree for vizier-like expressions over ISO dates.

	Note that the semantic validity of the date (like, month<13) is not
	checked by the grammar.
	"""
    return utils.pyparseString(baseSymbol, str)[0]
Пример #4
0
def getREForShPat(shPat):
    r"""returns a POSIX RE for a POSIX shell pattern.

	>>> getREForShPat(r"ZU?\*[!A-Z]*")
	'ZU.\\*[^A\\-Z].*'
	>>> getREForShPat("no[*")
	'no\\[.*'
	"""
    return "".join(
        utils.pyparseString(_getShPatGrammar(), shPat, parseAll=True))
Пример #5
0
def parseUploadString(uploadString):
    """iterates over pairs of tableName, uploadSource from a TAP upload string.
	"""
    try:
        res = utils.pyparseString(getUploadGrammar(), uploadString).asList()
        return res
    except ParseException, ex:
        raise base.ValidationError(
            "Syntax error in UPLOAD parameter (near %s)" % (ex.loc),
            "UPLOAD",
            hint=
            "Note that we only allow regular SQL identifiers as table names,"
            " i.e., basically only alphanumerics are allowed.")
Пример #6
0
 def _parseColDefs(self, ctx):
     # the handler for colDefs -- parse shortcut colDefs
     try:
         for key, range in utils.pyparseString(self._getColDefGrammar(),
                                               self.colDefs):
             self.colRanges[key] = self._cols.itemAttD.parse(range)
     except pyparsing.ParseException, ex:
         raise base.LiteralParseError(
             "colDefs",
             self.colDefs,
             hint="colDefs is a whitespace-separated list of key:range pairs."
             " Your literal doesn't look like this, and here's what the"
             " parser had to complain: %s" % ex)
Пример #7
0
	def parse(s):
		if s is None or not s.strip(): # special service: Null values
			return None
		if isinstance(s, pgsphere.PgSAdapter):
			return s

		try:
			res = utils.pyparseString(region, s, parseAll=True)[0]
			if not res.cooSys or res.cooSys.lower()=='unknownframe':  # Sigh.
				res.cooSys = "UNKNOWN"
			return res
		except (ParseException, ParseSyntaxException), msg:
			raise common.STCSParseError("Invalid STCS (%s)"%str(msg))
Пример #8
0
def processXML(document, manipulator):
    """processes an XML-document with manipulator.

	document is a string containing the XML, and the function returns 
	serialized an XML.  You're doing yourself a favour if document is
	a unicode string.

	manipulator is an instance of a derivation of Manipulator below.
	There's a secret handshake between Manipulator and the grammar, so
	you really need to inherit, just putting in the two methods won't do.
	"""
    syms = getXMLGrammar(manipulator)
    #	from gavo.adql import grammar; grammar.enableDebug(syms)
    res = utils.pyparseString(syms["document"], document)
    return flatten(res)
Пример #9
0
def getCST(literal, grammarFactory=None):
    """returns a CST for an STC-S expression.

	grammarFactory is a function returning the grammar, in this case
	either getGrammar (which gets used if the argument is left out) or 
	getColrefGrammar.
	"""
    # special case: the empty input yields an empty CST
    if not literal.strip():
        return {}

    if grammarFactory is None:
        grammarFactory = getGrammar
    try:
        tree = makeTree(
            utils.pyparseString(grammarFactory()["stcsPhrase"], literal))
    except (ParseException, ParseSyntaxException), ex:
        raise common.STCSParseError("Invalid STCS expression (%s at %s)" %
                                    (ex.msg, ex.loc),
                                    expr=literal,
                                    pos=ex.loc)
Пример #10
0
def parseStringExpr(str, baseSymbol=getStringGrammar()):
    return utils.pyparseString(baseSymbol, str)[0]
Пример #11
0
def parseNumericExpr(str,
                     baseSymbol=getComplexGrammar(floatLiteral, _makePmNode)):
    """returns a parse tree for vizier-like expressions over floats.
	"""
    return utils.pyparseString(baseSymbol, str)[0]
Пример #12
0
def parseModel(modelDescr):
    """returns a MetaValidator for a model description.

	model descriptions are covered in the module docstring.
	"""
    return utils.pyparseString(_getModelGrammar(), modelDescr)[0]
Пример #13
0
 def _prepare(self, script):
     self.statements = utils.pyparseString(getSQLScriptGrammar(),
                                           script.getSource())
Пример #14
0
def parseUnit(unitStr, unitGrammar=getUnitGrammar()):
    try:
        return utils.pyparseString(unitGrammar, unitStr, parseAll=True)[0]
    except pyparsing.ParseException, msg:
        raise utils.logOldExc(
            BadUnit("%s at col. %d" % (repr(unitStr), msg.column)))