| 1 | """ |
| 2 | A parser for ADQL. |
| 3 | |
| 4 | The grammar follows the official BNF grammar quite closely, except where |
| 5 | pyparsing makes a different approach desirable; the names should mostly |
| 6 | match except for the obvious underscore to camel case map. |
| 7 | |
| 8 | The grammar given in the spec has some nasty rules when you're parsing |
| 9 | without backtracking and by recursive descent (which is what pyparsing |
| 10 | does). I need some reformulations. The more interesting of those |
| 11 | include: |
| 12 | |
| 13 | TableReference |
| 14 | -------------- |
| 15 | |
| 16 | Trouble is that table_reference is left-recursive in the following rules:: |
| 17 | |
| 18 | <table_reference> ::= |
| 19 | <table_name> [ <correlation_specification> ] |
| 20 | | <derived_table> <correlation_specification> |
| 21 | | <joined_table> |
| 22 | |
| 23 | <joined_table> ::= |
| 24 | <qualified_join> |
| 25 | | <left_paren> <joined_table> <right_paren> |
| 26 | |
| 27 | <qualified_join> ::= |
| 28 | <table_reference> [ NATURAL ] [ <join_type> ] JOIN |
| 29 | <table_reference> [ <join_specification> ] |
| 30 | |
| 31 | We fix this by adding rules:: |
| 32 | |
| 33 | <sub_join> ::= '(' <joinedTable> ')' |
| 34 | <join_opener> ::= |
| 35 | <table_name> [ <correlation_specification> ] |
| 36 | | <derived_table> <correlation_specification> |
| 37 | | <sub_join> |
| 38 | |
| 39 | and then writing:: |
| 40 | |
| 41 | <qualified_join> ::= |
| 42 | <join_opener> [ NATURAL ] [ <join_type> ] JOIN |
| 43 | <table_reference> [ <join_specification> ] |
| 44 | |
| 45 | |
| 46 | |
| 47 | statement |
| 48 | --------- |
| 49 | |
| 50 | I can't have StringEnd appended to querySpecification since it's used |
| 51 | in subqueries, but I need to have it to keep pyparsing from just matching |
| 52 | parts of the input. Thus, the top-level production is for "statement". |
| 53 | |
| 54 | |
| 55 | trig_function, math_function, system_defined_function |
| 56 | ----------------------------------------------------- |
| 57 | |
| 58 | I think it's a bit funny to have the arity of functions in the syntax, but |
| 59 | there you go. Anyway, I don't want to have the function names in separate |
| 60 | symbols since they are expensive but go for a Regex (trig1ArgFunctionName). |
| 61 | The only exception is ATAN since it has a different arity from the rest of the |
| 62 | lot. |
| 63 | |
| 64 | Similarly, for math_function I group symbols by arity. |
| 65 | |
| 66 | The system defined functions are also regrouped to keep the number of |
| 67 | symbols reasonable. |
| 68 | |
| 69 | column_reference and below |
| 70 | -------------------------- |
| 71 | |
| 72 | Here the lack of backtracking hurts badly, since once, say, schema name |
| 73 | is matched with a dot that's it, even if the dot should really have separated |
| 74 | schema and table. |
| 75 | |
| 76 | Hence, we don't assign semantic labels in the grammar but leave that to |
| 77 | whatever interprets the tokens. |
| 78 | |
| 79 | The important rules here are:: |
| 80 | |
| 81 | <column_name> ::= <identifier> |
| 82 | <correlation_name> ::= <identifier> |
| 83 | <catalog_name> ::= <identifier> |
| 84 | <unqualified_schema name> ::= <identifier> |
| 85 | <schema_name> ::= [ <catalog_name> <period> ] <unqualified_schema name> |
| 86 | <table_name> ::= [ <schema_name> <period> ] <identifier> |
| 87 | <qualifier> ::= <table_name> | <correlation_name> |
| 88 | <column_reference> ::= [ <qualifier> <period> ] <column_name> |
| 89 | |
| 90 | By substitution, one has:: |
| 91 | |
| 92 | <schema_name> ::= [ <identifier> <period> ] <identifier> |
| 93 | |
| 94 | hence:: |
| 95 | |
| 96 | <table_name> ::= [[ <identifier> <period> ] <identifier> <period> ] |
| 97 | <identifier> |
| 98 | |
| 99 | hence:: |
| 100 | |
| 101 | <qualifier> ::= [[ <identifier> <period> ] <identifier> <period> ] |
| 102 | <identifier> |
| 103 | |
| 104 | (which matches both table_name and correlation_name) and thus:: |
| 105 | |
| 106 | <column_reference> ::= [[[ <identifier> <period> ] <identifier> <period> ] |
| 107 | <identifier> <period> ] <identifier> |
| 108 | |
| 109 | We need the table_name, qualifier, and column_reference productions. |
| 110 | |
| 111 | |
| 112 | generalLiterals in unsigngedLiterals |
| 113 | ------------------------------------ |
| 114 | |
| 115 | One point I'm deviating from the published grammar is that I disallow |
| 116 | generalLiterals in unsignedLiterals. Allowing them would let pyparsing |
| 117 | match a string literal as a numericValueLiteral, which messes up |
| 118 | string expressions. I'm not sure why generalLiterals are allowed |
| 119 | in there anyway. If this bites at some point, we'll face a major rewrite |
| 120 | of the grammar (or we need to dump pyparsing). |
| 121 | |
| 122 | To make the whole thing work, I added the generalLiteral to the |
| 123 | characterPrimary production. |
| 124 | """ |
| 125 | |
| 126 | #c Copyright 2008-2025, the GAVO project <[email protected]> |
| 127 | #c |
| 128 | #c This program is free software, covered by the GNU GPL. See the |
| 129 | #c COPYING file in the source distribution. |
| 130 | |
| 131 | |
| 132 | import functoolsscip-python python python-stdlib 3.11 functools/__init__: |
| 133 | |
| 134 | from gavo.utils.parsetricksscip-python python gavodachs 2.13 `gavo.utils.parsetricks`/__init__: import ( |
| 135 | Wordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Word#, Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#, Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#, alphasscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/alphas., CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#, |
| 136 | ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#, OneOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/OneOrMore#, StringEndscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/StringEnd#, |
| 137 | Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#, |
| 138 | MatchFirstWithSaneErrorscip-python python gavodachs 2.13 `gavo.utils.parsetricks`/MatchFirstWithSaneError#, # temporary hack, see parsetricks |
| 139 | CaselessLiteralscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessLiteral#, ParseExceptionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseException#, ParseFatalExceptionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseFatalException#, |
| 140 | Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#, sglQuotedStringscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/sglQuotedString., alphanumsscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/alphanums., |
| 141 | Whitescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/White#, |
| 142 | ParseExpressionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseExpression#, |
| 143 | Suppressscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Suppress#, pyparsingWhitecharsscip-python python gavodachs 2.13 `gavo.utils.parsetricks`/pyparsingWhitechars().) |
| 144 | from gavo.utils.parsetricksscip-python python gavodachs 2.13 `gavo.utils.parsetricks`/__init__: import ParseSyntaxExceptionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseSyntaxException# #noflake: exported name |
| 145 | |
| 146 | from gavoscip-python python gavodachs 2.13 gavo/__init__: import utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__: |
| 147 | from gavoscip-python python gavodachs 2.13 gavo/__init__: import stcscip-python python gavodachs 2.13 `gavo.stc`/__init__: |
| 148 | from gavo.adqlscip-python python gavodachs 2.13 `gavo.adql`/__init__: import bindinggrammarscip-python python gavodachs 2.13 `gavo.adql.bindinggrammar`/__init__: |
| 149 | |
| 150 | __docformat__scip-python python gavodachs 2.13 `gavo.adql.grammar`/__docformat__. = "restructuredtext en" |
| 151 | |
| 152 | import sysscip-python python python-stdlib 3.11 sys/__init__: |
| 153 | |
| 154 | # all SQL and ADQL reserved words are expected in uppercase by this and |
| 155 | # other modules. |
| 156 | ADQL_RESERVED_WORDSscip-python python gavodachs 2.13 `gavo.adql.grammar`/ADQL_RESERVED_WORDS. = setscip-python python python-stdlib 3.11 builtins/set#([ "ABS", "ACOS", "AREA", "ASIN", "ATAN", "ATAN2", |
| 157 | "CEILING", "CENTROID", "CIRCLE", "CONTAINS", "COS", "DEGREES", "DISTANCE", |
| 158 | "EXP", "FLOOR", "INTERSECTS", "LATITUDE", "LOG", "LOG10", "COORD1", |
| 159 | "COORD2", "COORDSYS", "BOX", |
| 160 | "MOD", "PI", "POINT", "POLYGON", "POWER", "RADIANS", "REGION", |
| 161 | "RAND", "ROUND", "SIN", "SQUARE", "SQRT", "TOP", "TAN", "TRUNCATE", |
| 162 | "OFFSET", "BITWISE_AND", "BITWISE_OR", "BITWISE_XOR", "BITWISE_NOT", |
| 163 | "MOC", "STDDEV"]) |
| 164 | |
| 165 | SQL_RESERVED_WORDSscip-python python gavodachs 2.13 `gavo.adql.grammar`/SQL_RESERVED_WORDS. = setscip-python python python-stdlib 3.11 builtins/set#([ |
| 166 | "ABSOLUTE", "ACTION", "ADD", "ALL", "ALLOCATE", "ALTER", "AND", "ANY", |
| 167 | "ARE", "AS", "ASC", "ASSERTION", "AT", "AUTHORIZATION", "AVG", "BEGIN", |
| 168 | "BETWEEN", "BIT", "BIT_LENGTH", "BOTH", "BY", "CASCADE", "CASCADED", |
| 169 | "CASE", "CAST", "CATALOG", "CHAR", "CHARACTER", "CHAR_LENGTH", |
| 170 | "CHARACTER_LENGTH", "CHECK", "CLOSE", "COALESCE", "COLLATE", |
| 171 | "COLLATION", "COLUMN", "COMMIT", "CONNECT", "CONNECTION", "CONSTRAINT", |
| 172 | "CONSTRAINTS", "CONTINUE", "CONVERT", "CORRESPONDING", "COUNT", |
| 173 | "CREATE", "CROSS", "CURRENT", "CURRENT_DATE", "CURRENT_TIME", |
| 174 | "CURRENT_TIMESTAMP", "CURRENT_USER", "CURSOR", "DATE", "DAY", |
| 175 | "DEALLOCATE", "DECIMAL", "DECLARE", "DEFAULT", "DEFERRABLE", "DEFERRED", |
| 176 | "DELETE", "DESC", "DESCRIBE", "DESCRIPTOR", "DIAGNOSTICS", "DISCONNECT", |
| 177 | "DISTINCT", "DOMAIN", "DOUBLE", "DROP", "ELSE", "END", "END-EXEC", |
| 178 | "ESCAPE", "EXCEPT", "EXCEPTION", "EXEC", "EXECUTE", "EXISTS", |
| 179 | "EXTERNAL", "EXTRACT", "FALSE", "FETCH", "FIRST", "FLOAT", "FOR", |
| 180 | "FOREIGN", "FOUND", "FROM", "FULL", "GET", "GLOBAL", "GO", "GOTO", |
| 181 | "GRANT", "GROUP", "HAVING", "HOUR", "IDENTITY", "IMMEDIATE", "IN", |
| 182 | "INDICATOR", "INITIALLY", "INNER", "INPUT", "INSENSITIVE", "INSERT", |
| 183 | "INT", "INTEGER", "INTERSECT", "INTERVAL", "INTO", "IS", "ISOLATION", |
| 184 | "JOIN", "KEY", "LANGUAGE", "LAST", "LEADING", "LEFT", "LEVEL", "LIKE", |
| 185 | "LOCAL", "LOWER", "MATCH", "MAX", "MIN", "MINUTE", "MODULE", "MONTH", |
| 186 | "NAMES", "NATIONAL", "NATURAL", "NCHAR", "NEXT", "NO", "NOT", "NULL", |
| 187 | "NULLIF", "NUMERIC", "OCTET_LENGTH", "OF", "ON", "ONLY", "OPEN", |
| 188 | "OPTION", "OR", "ORDER", "OUTER", "OUTPUT", "OVERLAPS", "PAD", |
| 189 | "PARTIAL", "POSITION", "PRECISION", "PREPARE", "PRESERVE", "PRIMARY", |
| 190 | "PRIOR", "PRIVILEGES", "PROCEDURE", "PUBLIC", "READ", "REAL", |
| 191 | "REFERENCES", "RELATIVE", "RESTRICT", "REVOKE", "RIGHT", "ROLLBACK", |
| 192 | "ROWS", "SCHEMA", "SCROLL", "SECOND", "SECTION", "SELECT", "SESSION", |
| 193 | "SESSION_USER", "SET", "SIZE", "SMALLINT", "SOME", "SPACE", "SQL", |
| 194 | "SQLCODE", "SQLERROR", "SQLSTATE", "SUBSTRING", "SUM", "SYSTEM_USER", |
| 195 | "TABLE", "TEMPORARY", "THEN", "TIME", "TIMESTAMP", "TIMEZONE_HOUR", |
| 196 | "TIMEZONE_MINUTE", "TO", "TRAILING", "TRANSACTION", "TRANSLATE", |
| 197 | "TRANSLATION", "TRIM", "TRUE", "UNION", "UNIQUE", "UNKNOWN", "UPDATE", |
| 198 | "UPPER", "USAGE", "USER", "USING", "VALUE", "VALUES", "VARCHAR", |
| 199 | "VARYING", "VIEW", "WHEN", "WHENEVER", "WHERE", "WITH", "WORK", "WRITE", |
| 200 | "YEAR", "ZONE", "TABLESAMPLE"]) |
| 201 | |
| 202 | ALL_RESERVED_WORDSscip-python python gavodachs 2.13 `gavo.adql.grammar`/ALL_RESERVED_WORDS. = ADQL_RESERVED_WORDSscip-python python gavodachs 2.13 `gavo.adql.grammar`/ADQL_RESERVED_WORDS. | SQL_RESERVED_WORDSscip-python python gavodachs 2.13 `gavo.adql.grammar`/SQL_RESERVED_WORDS. |
| 203 | |
| 204 | |
| 205 | # A regular expression for prefixes of user defined functions |
| 206 | userFunctionPrefixscip-python python gavodachs 2.13 `gavo.adql.grammar`/userFunctionPrefix. = "(gavo|ivo)" |
| 207 | |
| 208 | |
| 209 | def _makeQuotedNamescip-python python gavodachs 2.13 `gavo.adql.grammar`/_makeQuotedName().(sscip-python python gavodachs 2.13 `gavo.adql.grammar`/_makeQuotedName().(s), pscip-python python gavodachs 2.13 `gavo.adql.grammar`/_makeQuotedName().(p), tscip-python python gavodachs 2.13 `gavo.adql.grammar`/_makeQuotedName().(t)): |
| 210 | # Parse action for delimitedIdentifer. No longer necessary when we can |
| 211 | # rely on working pyparsing QuotedString |
| 212 | return utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.QuotedNamescip-python python gavodachs 2.13 `gavo.utils.misctricks`/QuotedName#(strscip-python python python-stdlib 3.11 builtins/str#(tscip-python python gavodachs 2.13 `gavo.adql.grammar`/_makeQuotedName().(t)[0])[1:-1].replacescip-python python python-stdlib 3.11 builtins/str#replace().('""', '"')) |
| 213 | |
| 214 | |
| 215 | def _parseVOUnitscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(sscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(s), pscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(p), tscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(t)): |
| 216 | # parse action for unitLiteral; in particular, this converts exceptions |
| 217 | # so we drop ParseSyntaxExceptions rather than BadUnits |
| 218 | # I can't import base top-level because ADQL is "lower" than base and |
| 219 | # we're breaking this already in ufunctions. Let's see how we'll |
| 220 | # refactor this to avoid the in-function import. |
| 221 | # Or perhaps we should defer all this and take it out of the grammar? |
| 222 | # We don't need the parse tree anyway... |
| 223 | from gavo.basescip-python python gavodachs 2.13 `gavo.base`/__init__: import unitconvscip-python python gavodachs 2.13 `gavo.base.unitconv`/__init__: |
| 224 | try: |
| 225 | tree = unitconvscip-python python gavodachs 2.13 `gavo.base.unitconv`/__init__:.parseUnitscip-python python gavodachs 2.13 `gavo.base.unitconv`/parseUnit().(tscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(t)[0][1:-1]) |
| 226 | except unitconvscip-python python gavodachs 2.13 `gavo.base.unitconv`/__init__:.BadUnitscip-python python gavodachs 2.13 `gavo.base.unitconv`/BadUnit# as exc: |
| 227 | raise ParseFatalExceptionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseFatalException#(sscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(s), pscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(p), f"Cannot parse unit: {exc}") |
| 228 | if not tree.isValidscip-python python gavodachs 2.13 `gavo.base.unitconv`/Expression#isValid.: |
| 229 | raise ParseFatalExceptionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseFatalException#(sscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(s), pscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(p), |
| 230 | f"Non-VOUnits unit in {tscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(t)[0]}: if you really" |
| 231 | " want to keep an unknown unit, put it in single quotes") |
| 232 | return tscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().(t)[0][1:-1] |
| 233 | |
| 234 | |
| 235 | def Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(pyparseSymbolscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(pyparseSymbol)): |
| 236 | """wraps pyparseSymbol such that matches get added to an args list |
| 237 | on the parent node. |
| 238 | """ |
| 239 | return pyparseSymbolscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(pyparseSymbol).setResultsName("args", listAllMatches=True) |
| 240 | |
| 241 | |
| 242 | class RegularIdentifierscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#(Wordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Word#): |
| 243 | """regular identifiers are all C-style identifiers except reserved |
| 244 | words. |
| 245 | |
| 246 | Filtering these in the parse action doesn't always work properly for |
| 247 | all versions of pyparsing, thus this special class. |
| 248 | |
| 249 | reservedWords are assumed to be in upper case, but matching |
| 250 | case-insensitively. |
| 251 | """ |
| 252 | def __init__scip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#__init__().(selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#__init__().(self), reservedWordsscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#__init__().(reservedWords)): |
| 253 | selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#__init__().(self).reservedWordsscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#reservedWords. = reservedWordsscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#__init__().(reservedWords) |
| 254 | superscip-python python python-stdlib 3.11 builtins/super#(RegularIdentifierscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#, selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#__init__().(self)).__init__scip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Word#__init__().(alphasscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/alphas.+"_", alphanumsscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/alphanums.+"_") |
| 255 | # oh wow. in pyparsing 2.4, Word sets __class__, which we |
| 256 | # can't have. Let's undo the damage. |
| 257 | selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#__init__().(self).__class__scip-python python python-stdlib 3.11 builtins/object#__class__(). = RegularIdentifierscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier# |
| 258 | |
| 259 | def parseImplscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(self), instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(instring), locscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(loc), doActionsscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(doActions)=True): |
| 260 | locNew, match = superscip-python python python-stdlib 3.11 builtins/super#(RegularIdentifierscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#, selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(self)).parseImplscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Word#parseImpl().(instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(instring), |
| 261 | locscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(loc), doActionsscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(doActions)) |
| 262 | if match.upper() in selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(self).reservedWordsscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#reservedWords.: |
| 263 | raise ParseExceptionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseException#(instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(instring), locscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#parseImpl().(loc), "Reserved word not allowed here") |
| 264 | return locNew, match |
| 265 | |
| 266 | |
| 267 | class LongestMatchscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#(ParseExpressionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseExpression#): |
| 268 | """pyparsing's Or, except that ParseFatalExceptions are still propagated. |
| 269 | """ |
| 270 | def __init__scip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__init__().(selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__init__().(self), exprsscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__init__().(exprs), savelistscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__init__().(savelist)=False): |
| 271 | superscip-python python python-stdlib 3.11 builtins/super#(LongestMatchscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#, selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__init__().(self)).__init__scip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseExpression#__init__().(exprsscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__init__().(exprs), savelistscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__init__().(savelist)) |
| 272 | selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__init__().(self).mayReturnEmptyscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#mayReturnEmpty. = False |
| 273 | for e in selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__init__().(self).exprsscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseExpression#exprs.: |
| 274 | if e.mayReturnEmptyscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#mayReturnEmpty.: |
| 275 | selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__init__().(self).mayReturnEmptyscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#mayReturnEmpty. = True |
| 276 | break |
| 277 | |
| 278 | def parseImplscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(self), instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(instring), locscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(loc), doActionsscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(doActions)=True): |
| 279 | maxExcLoc = -1 |
| 280 | maxMatchLoc = -1 |
| 281 | maxException = None |
| 282 | for e in selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(self).exprsscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseExpression#exprs.: |
| 283 | try: |
| 284 | loc2 = e._parsescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#_parse.(instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(instring), locscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(loc), doActions=False)[0] |
| 285 | except ParseExceptionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseException# as err: |
| 286 | if err.locscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseBaseException#loc.>maxExcLoc: |
| 287 | maxException = err |
| 288 | maxExcLoc = err.locscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseBaseException#loc. |
| 289 | except IndexErrorscip-python python python-stdlib 3.11 builtins/IndexError#: |
| 290 | if len(instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(instring))>maxExcLoc: |
| 291 | maxException = ParseExceptionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseException#( |
| 292 | instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(instring), len(instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(instring)), e.errmsgscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#errmsg., selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(self)) |
| 293 | maxExcLoc = len(instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(instring)) |
| 294 | else: |
| 295 | if loc2>maxMatchLoc: |
| 296 | maxMatchLoc = loc2 |
| 297 | maxMatchExp = e |
| 298 | |
| 299 | if maxMatchLoc<0: |
| 300 | if maxException is not None: |
| 301 | raise maxException |
| 302 | else: |
| 303 | raise ParseExceptionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseException#(instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(instring), locscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(loc), |
| 304 | "no defined alternatives to match", selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(self)) |
| 305 | |
| 306 | return maxMatchExp._parsescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#_parse.(instringscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(instring), locscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(loc), doActionsscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#parseImpl().(doActions)) |
| 307 | |
| 308 | def __str__scip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__str__().( selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__str__().(self) ): |
| 309 | if hasattr(selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__str__().(self),"name"): |
| 310 | return selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__str__().(self).namescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#name. |
| 311 | |
| 312 | if selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__str__().(self).strReprscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#strRepr. is None: |
| 313 | selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__str__().(self).strReprscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#strRepr. = "{" + " ^ ".joinscip-python python python-stdlib 3.11 builtins/str#join().( [ strscip-python python python-stdlib 3.11 builtins/str#(e) for e in selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__str__().(self).exprsscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseExpression#exprs. ] ) + "}" |
| 314 | |
| 315 | return selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#__str__().(self).strReprscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#strRepr. |
| 316 | |
| 317 | def checkRecursionscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#checkRecursion().( selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#checkRecursion().(self), parseElementListscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#checkRecursion().(parseElementList) ): |
| 318 | subRecCheckList = parseElementListscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#checkRecursion().(parseElementList)[:] + [ selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#checkRecursion().(self) ] |
| 319 | for e in selfscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#checkRecursion().(self).exprsscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParseExpression#exprs.: |
| 320 | e.checkRecursionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#checkRecursion().( subRecCheckList ) |
| 321 | |
| 322 | |
| 323 | def getADQLGrammarCopyscip-python python gavodachs 2.13 `gavo.adql.grammar`/getADQLGrammarCopy().(nodesscip-python python gavodachs 2.13 `gavo.adql.grammar`/getADQLGrammarCopy().(nodes)): |
| 324 | """returns a pair symbols, selectSymbol for a grammar parsing ADQL. |
| 325 | |
| 326 | You should only use this if you actually require a fresh copy |
| 327 | of the ADQL grammar. Otherwise, use getADQLGrammar or a wrapper |
| 328 | function defined by a client module. |
| 329 | """ |
| 330 | g = bindinggrammarscip-python python gavodachs 2.13 `gavo.adql.bindinggrammar`/__init__:.AutoBindingGrammarscip-python python gavodachs 2.13 `gavo.adql.bindinggrammar`/AutoBindingGrammar#(nodesscip-python python gavodachs 2.13 `gavo.adql.grammar`/getADQLGrammarCopy().(nodes)) |
| 331 | |
| 332 | with pyparsingWhitecharsscip-python python gavodachs 2.13 `gavo.utils.parsetricks`/pyparsingWhitechars().("\n\t\r "): |
| 333 | |
| 334 | # Fundamental syntactic units and literals |
| 335 | g.sqlComment = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("--[^\n\r]*") |
| 336 | g.whitespace = Wordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Word#(" \t\n") # need that as a hack now and then to keep |
| 337 | # numbers and identifiers from sticking |
| 338 | |
| 339 | g.unsignedInteger = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#(r"\d+") |
| 340 | g.unsignedInteger.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("unsigned integer") |
| 341 | exactNumericRE = r"\d+(\.(\d+)?)?|\.\d+" |
| 342 | g.exactNumericLiteral = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#(exactNumericRE) |
| 343 | g.approximateNumericLiteral = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#(r"(?i)(%s)E[+-]?\d+"%exactNumericRE) |
| 344 | g.unsignedHexadecimal = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("0[xX][0-9A-Fa-f]+" |
| 345 | ).addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().(lambda s,p,t: strscip-python python python-stdlib 3.11 builtins/str#(intscip-python python python-stdlib 3.11 builtins/int#(t[0], 16)) |
| 346 | ) |
| 347 | g.unsignedHexadecimal.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("numeric literal") |
| 348 | g.unsignedNumericLiteral = ( |
| 349 | g.unsignedHexadecimal |
| 350 | | g.approximateNumericLiteral |
| 351 | | g.exactNumericLiteral) |
| 352 | g.unsignedNumericLiteral.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("numericLiteral") |
| 353 | g.characterStringLiteral = sglQuotedStringscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/sglQuotedString. + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#( sglQuotedStringscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/sglQuotedString. ) |
| 354 | g.generalLiteral = g.characterStringLiteral.copyscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#copy().() |
| 355 | g.literalWithUnit = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 356 | g.unsignedLiteral = g.literalWithUnit ^ g.unsignedNumericLiteral |
| 357 | # !!! DEVIATION: we're not accepting | generalLiteral here. |
| 358 | g.sign = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("+") | "-" |
| 359 | g.signedInteger = (Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#( g.sign ) |
| 360 | + g.unsignedInteger) |
| 361 | g.signedInteger.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("signed integer") |
| 362 | g.nullLiteral = CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("NULL") |
| 363 | g.nullLiteral.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("NULL") |
| 364 | |
| 365 | g.regularIdentifier = RegularIdentifierscip-python python gavodachs 2.13 `gavo.adql.grammar`/RegularIdentifier#(ALL_RESERVED_WORDSscip-python python gavodachs 2.13 `gavo.adql.grammar`/ALL_RESERVED_WORDS.) |
| 366 | g.regularIdentifier.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("identifier") |
| 367 | # There's a bug with QuotedString in some versions of pyparsing. |
| 368 | # So, don't use this: |
| 369 | # delimitedIdentifier = QuotedString(quoteChar='"', escQuote='"', |
| 370 | # unquoteResults=True).addParseAction( |
| 371 | # lambda s,p,t: utils.QuotedName(str(t))) |
| 372 | # but rather |
| 373 | g.delimitedIdentifier = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#('("[^"]*")+').addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().( |
| 374 | _makeQuotedNamescip-python python gavodachs 2.13 `gavo.adql.grammar`/_makeQuotedName().) |
| 375 | g.delimitedIdentifier.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("delimited identifier") |
| 376 | g.identifier = g.regularIdentifier | g.delimitedIdentifier |
| 377 | |
| 378 | # Operators |
| 379 | g.compOp = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("=|!=|<=|>=|<>|<|>") |
| 380 | g.compOp.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("comparison operator") |
| 381 | g.multOperator = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("*") | Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("/") |
| 382 | g.addOperator = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("+") | Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("-") |
| 383 | g.notKeyword = CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("NOT") |
| 384 | |
| 385 | # Column names and such |
| 386 | g.columnName = g.identifier.copyscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#copy().() |
| 387 | g.columnName.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("column name") |
| 388 | g.correlationName = g.identifier.copyscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#copy().() |
| 389 | g.qualifier = (g.identifier |
| 390 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#( "." + g.identifier ) |
| 391 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#( "." + g.identifier )) |
| 392 | g.tableName = g.qualifier("tableName") |
| 393 | g.uploadTableName = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("tap_user") |
| 394 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#( "." + g.identifier ) |
| 395 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#( "." + g.identifier ))("tableName") |
| 396 | g.columnReferenceByUCD = ( |
| 397 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("UCDCOL") |
| 398 | + '(' + g.characterStringLiteral + ')') |
| 399 | g.columnReference = ( |
| 400 | g.columnReferenceByUCD |
| 401 | | g.identifier |
| 402 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#( "." + g.identifier ) |
| 403 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#( "." + g.identifier ) |
| 404 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#( "." + g.identifier )) |
| 405 | g.columnReference.setName("column reference") |
| 406 | g.asClause = Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("AS")) + g.columnName("alias") |
| 407 | |
| 408 | g.valueExpression = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 409 | |
| 410 | # set functions |
| 411 | g.setFunctionType = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)AVG|MAX|MIN|SUM|COUNT|STDDEV") |
| 412 | g.setQuantifier = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)DISTINCT|ALL") |
| 413 | g.generalSetFunction = (g.setFunctionType("fName") |
| 414 | + '(' + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.setQuantifier) + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.valueExpression) + ')') |
| 415 | g.countAll = (CaselessLiteralscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessLiteral#("COUNT")("fName") |
| 416 | + '(' + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#('*')) + ')') |
| 417 | g.setFunctionSpecification = (g.countAll | g.generalSetFunction) |
| 418 | |
| 419 | # cast |
| 420 | g.castOperand = ( |
| 421 | g.valueExpression |
| 422 | | g.nullLiteral) |
| 423 | g.castOperand.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("value to cast") |
| 424 | g.length = g.unsignedInteger | '*' |
| 425 | g.sqlTypeLength = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("(") - g.length - Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#(")") |
| 426 | g.sqlAtomType = ( |
| 427 | ((CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("CHAR") | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("VARCHAR")) |
| 428 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.sqlTypeLength)) |
| 429 | | (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("NATIONAL") - CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("CHAR") |
| 430 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.sqlTypeLength)) |
| 431 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("INTEGER") |
| 432 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("BIGINT") |
| 433 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("SMALLINT") |
| 434 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("REAL") |
| 435 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("DOUBLE") + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("PRECISION") |
| 436 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("TIMESTAMP") |
| 437 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("POINT") |
| 438 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("CIRCLE") |
| 439 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("POLYGON")) |
| 440 | g.sqlArraySpec = (Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("[") |
| 441 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.unsignedInteger) |
| 442 | + Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("]")) |
| 443 | g.castTarget = (g.sqlAtomType |
| 444 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.sqlArraySpec)).addParseAction( |
| 445 | lambda s,p,t: " ".joinscip-python python python-stdlib 3.11 builtins/str#join().(t).upperscip-python python python-stdlib 3.11 builtins/str#upper().()) |
| 446 | g.castSpecification = ( |
| 447 | CaselessLiteralscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessLiteral#("CAST") |
| 448 | - "(" + g.castOperand.setResultsNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setResultsName().("value") |
| 449 | - CaselessLiteralscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessLiteral#("AS") |
| 450 | + g.castTarget.setResultsName("newType") - ')') |
| 451 | |
| 452 | # new-style units |
| 453 | g.unitLiteral = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#(r"\{[^}]+\}").addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().(_parseVOUnitscip-python python gavodachs 2.13 `gavo.adql.grammar`/_parseVOUnit().) |
| 454 | g.unitCoercion = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#('@') |
| 455 | g.literalWithUnit << g.unsignedNumericLiteral - g.unitLiteral |
| 456 | |
| 457 | # value expressions |
| 458 | g.arrayReference = ( |
| 459 | g.columnReference |
| 460 | + Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#('[') |
| 461 | + g.valueExpression |
| 462 | + Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#(']')) |
| 463 | g.valueExpressionPrimary = ( |
| 464 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("NULL") |
| 465 | | g.unsignedLiteral |
| 466 | | g.arrayReference |
| 467 | | g.columnReference |
| 468 | | g.setFunctionSpecification |
| 469 | # this should allow whole character value expressions by the |
| 470 | # spec. If we ever actually want that, we'd have to see how |
| 471 | # to avoid infinite recursion. |
| 472 | | g.generalLiteral |
| 473 | | '(' + g.valueExpression + ')' |
| 474 | | g.castSpecification) |
| 475 | g.valueExpressionPrimary.setName("value expression") |
| 476 | |
| 477 | # string literal stuff |
| 478 | g.characterPrimary = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 479 | g.characterPrimary.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("String expression") |
| 480 | g.characterFactor = g.characterPrimary |
| 481 | g.characterValueExpression = (g.characterFactor + |
| 482 | ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#("||" + g.characterFactor)) |
| 483 | g.stringValueExpression = g.characterValueExpression |
| 484 | |
| 485 | # numeric expressions/terms |
| 486 | g.numericValueExpression = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 487 | g.numericValueExpression.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("Numeric expression") |
| 488 | g.numericValueFunction = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 489 | g.numericValueFunction.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("Numeric value function") |
| 490 | g.numericExpressionPrimary = ( |
| 491 | g.unsignedLiteral |
| 492 | | g.columnReference |
| 493 | | g.setFunctionSpecification |
| 494 | | '(' + g.valueExpression + ')') |
| 495 | g.numericPrimary = ( |
| 496 | g.numericValueFunction |
| 497 | | g.valueExpressionPrimary) |
| 498 | g.numericPrimary.setName("numeric expression") |
| 499 | g.plainFactor = Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.sign) + g.numericPrimary |
| 500 | g.coercedFactor = ( |
| 501 | g.plainFactor - g.unitCoercion - g.unitLiteral("toUnit")) |
| 502 | |
| 503 | g.factor = g.coercedFactor ^ g.plainFactor |
| 504 | g.factor.setName("Numeric factor") |
| 505 | g.term = (g.factor |
| 506 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(g.multOperator + g.factor)) |
| 507 | g.term.setName("Numeric term") |
| 508 | g.numericValueExpression << ( |
| 509 | g.term + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(g.addOperator + g.term)) |
| 510 | g.numericValueExpression.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("numeric expression") |
| 511 | g.nvArgs = Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.numericValueExpression) |
| 512 | |
| 513 | # geometry types and expressions |
| 514 | g.userDefinedFunction = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 515 | g.userDefinedFunction.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("User defined function") |
| 516 | g.geometryValueExpression = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 517 | g.geometryValueExpression.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("Geometry expression") |
| 518 | g.tapCoordLiteral = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)'(?P<sys>%s)'"%"|".joinscip-python python python-stdlib 3.11 builtins/str#join().(stcscip-python python gavodachs 2.13 `gavo.stc`/__init__:.TAP_SYSTEMSscip-python python gavodachs 2.13 `gavo.stc.tapstc`/TAP_SYSTEMS.) |
| 519 | ).addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().(lambda s,p,t: t["sys"].upper() |
| 520 | ) |
| 521 | g.tapCoordLiteral.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("coordinate system literal (ICRS, GALACTIC,...)") |
| 522 | g.coordSys = (g.tapCoordLiteral |
| 523 | | g.nullLiteral.copyscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Keyword#copy().().addParseActionscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#addParseAction().(lambda s,p,t: "UNKNOWN") |
| 524 | ).setResultsNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setResultsName().("coordSys") |
| 525 | g.coordSys.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("coordinate system literal (ICRS, GALACTIC,...)") |
| 526 | g.coordinates = (g.nvArgs + ',' + g.nvArgs) |
| 527 | g.box = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("BOX")("fName") |
| 528 | - '(' + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.coordSys + ',') |
| 529 | + g.coordinates + ',' |
| 530 | + g.coordinates + ')') |
| 531 | g.point = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("POINT")("fName") |
| 532 | - '(' + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.coordSys - ',') |
| 533 | + g.coordinates + ')') |
| 534 | g.coordValue = ( |
| 535 | g.userDefinedFunction |
| 536 | | g.point |
| 537 | | g.columnReference) |
| 538 | |
| 539 | g.circleSplitCooArgs = (g.coordinates + ',' - g.nvArgs) |
| 540 | g.circlePointCooArgs = ( |
| 541 | Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.coordValue) + ',' |
| 542 | - g.nvArgs) |
| 543 | g.circle = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("CIRCLE")("fName") |
| 544 | - '(' + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.coordSys + ',') |
| 545 | + (g.circleSplitCooArgs | g.circlePointCooArgs) |
| 546 | + ')') |
| 547 | |
| 548 | g.polygonSplitCooArgs = (g.coordinates |
| 549 | + ',' + g.coordinates |
| 550 | + OneOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/OneOrMore#( ',' + g.coordinates )) |
| 551 | g.polygonPointCooArgs = (Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.coordValue) |
| 552 | - ',' - Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.coordValue) |
| 553 | - OneOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/OneOrMore#(',' - Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.coordValue))) |
| 554 | g.polygon = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("POLYGON")("fName") |
| 555 | - '(' + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.coordSys + ',') |
| 556 | + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.polygonSplitCooArgs | g.polygonPointCooArgs) |
| 557 | + ')') |
| 558 | |
| 559 | g.mocArgs = ( |
| 560 | Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.stringValueExpression) |
| 561 | ^ Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().( |
| 562 | g.numericValueExpression) - ',' |
| 563 | - Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.geometryValueExpression)) |
| 564 | g.moc = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("MOC")("fName") |
| 565 | - '(' + g.mocArgs + ')') |
| 566 | |
| 567 | g.region = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("REGION")("fName") |
| 568 | + '(' |
| 569 | + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.stringValueExpression) + ')') |
| 570 | g.geometryExpression = (g.box |
| 571 | | g.point |
| 572 | | g.circle |
| 573 | | g.polygon |
| 574 | | g.region |
| 575 | | g.moc) |
| 576 | g.geometryValue = g.columnReference.copy() |
| 577 | g.centroid = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("CENTROID")("fName") |
| 578 | + '(' + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.geometryValueExpression) + ')') |
| 579 | g.geometryValueExpression << (g.geometryExpression |
| 580 | | g.userDefinedFunction |
| 581 | | g.geometryValue |
| 582 | | g.centroid) |
| 583 | g.geometryValueExpression.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("geometry value expression") |
| 584 | |
| 585 | # geometry functions |
| 586 | g.distanceSplitCooArgs = (g.coordinates + ',' |
| 587 | + g.coordinates) |
| 588 | g.distanceSplitCooArgs.setName("Numeric coordinates") |
| 589 | g.distancePointCooArgs = (Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.coordValue) + ',' |
| 590 | + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.coordValue)) |
| 591 | g.distancePointCooArgs.setName("Geometry argument") |
| 592 | g.distanceFunction = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("DISTANCE")("fName") |
| 593 | - '(' + (g.distanceSplitCooArgs | g.distancePointCooArgs) + ')') |
| 594 | g.pointFunction = (Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)COORD[12]|COORDSYS")("fName") + '(' + |
| 595 | Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.coordValue) + ')') |
| 596 | g.area = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("AREA")("fName") |
| 597 | + '(' + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.geometryValueExpression) + ')') |
| 598 | g.nonPredicateGeometryFunction = ( |
| 599 | g.distanceFunction |
| 600 | | g.pointFunction |
| 601 | | g.area ) |
| 602 | g.predicateGeoFunctionName = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)CONTAINS|INTERSECTS") |
| 603 | g.predicateGeometryFunction = (g.predicateGeoFunctionName("fName") |
| 604 | + '(' + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.geometryValueExpression) |
| 605 | + ',' + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.geometryValueExpression) + ')') |
| 606 | g.numericGeometryFunction = (g.predicateGeometryFunction |
| 607 | | g.nonPredicateGeometryFunction) |
| 608 | |
| 609 | # numeric, system, user defined functions |
| 610 | g.trig1ArgFunctionName = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)ACOS|ASIN|ATAN|COS|COT|SIN|TAN") |
| 611 | # trig1ArgFunction is what causes a parse failure on common numeric |
| 612 | # value expressions. We take the liberty of misnaming it for better |
| 613 | # error messages in most cases. |
| 614 | g.trig1ArgFunctionName.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("numeric expression") |
| 615 | g.trigFunction = ( |
| 616 | g.trig1ArgFunctionName("fName") + '(' |
| 617 | + g.nvArgs + ')' |
| 618 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("ATAN2")("fName") + '(' |
| 619 | + g.nvArgs + ',' |
| 620 | + g.nvArgs + ')') |
| 621 | g.math0ArgFunctionName = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)PI") |
| 622 | g.optIntFunctionName = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)RAND") |
| 623 | g.math1ArgFunctionName = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)ABS|CEILING|DEGREES|EXP|FLOOR|LOG10|" |
| 624 | "LOG|RADIANS|SQUARE|SQRT|BITWISE_NOT") |
| 625 | g.optPrecArgFunctionName = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)ROUND|TRUNCATE") |
| 626 | g.math2ArgFunctionName = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)POWER|MOD|BITWISE_AND|BITWISE_OR" |
| 627 | "|BITWISE_XOR") |
| 628 | g.mathFunction = ( |
| 629 | g.math0ArgFunctionName("fName") + '(' + ')' |
| 630 | | g.optIntFunctionName("fName") + '(' |
| 631 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#( Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.unsignedInteger) ) + ')' |
| 632 | | g.math1ArgFunctionName("fName") + '(' |
| 633 | + g.nvArgs + ')' |
| 634 | | g.optPrecArgFunctionName("fName") + '(' |
| 635 | + g.nvArgs + |
| 636 | Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#( ',' + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.signedInteger) ) + ')' |
| 637 | | g.math2ArgFunctionName("fName") + '(' |
| 638 | + g.nvArgs |
| 639 | + ',' + g.nvArgs + ')') |
| 640 | g.inUnitFunction = ( |
| 641 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("IN_UNIT") |
| 642 | - '(' |
| 643 | - g.numericValueExpression |
| 644 | - ',' |
| 645 | - g.characterStringLiteral |
| 646 | - ')') |
| 647 | g.scalarArray1FunctionName = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#( |
| 648 | "(?i)arr_(min|max|avg|stddev|sum|count)") |
| 649 | g.arrayFunctionArguments = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#('(') - g.nvArgs - ')' |
| 650 | g.arrayFunctionArguments.setName("array function argument") |
| 651 | g.scalarArray1Function = ( |
| 652 | g.scalarArray1FunctionName("fName") |
| 653 | - g.arrayFunctionArguments) |
| 654 | g.scalarArray2FunctionName = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)arr_dot") |
| 655 | g.scalarArray2Function = ( |
| 656 | g.scalarArray2FunctionName("fName") |
| 657 | - '(' - g.nvArgs - ',' - g.nvArgs - ')') |
| 658 | g.scalarArrayFunction = ( |
| 659 | g.scalarArray2Function |
| 660 | | g.scalarArray1Function) |
| 661 | |
| 662 | g.arrayMapFunction = ( |
| 663 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("arr_map")("fName") - '(' |
| 664 | - Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.numericValueExpression) |
| 665 | - ',' - g.nvArgs - ')') |
| 666 | |
| 667 | g.userDefinedFunctionParam = g.valueExpression |
| 668 | g.userDefinedFunctionName = Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)"+userFunctionPrefixscip-python python gavodachs 2.13 `gavo.adql.grammar`/userFunctionPrefix.+"_[A-Za-z_]+") |
| 669 | g.userDefinedFunctionName.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("Name of locally defined function") |
| 670 | g.userDefinedFunction << (g.userDefinedFunctionName("fName") |
| 671 | + '(' |
| 672 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.userDefinedFunctionParam) |
| 673 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#("," + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.userDefinedFunctionParam))) |
| 674 | + ')') |
| 675 | |
| 676 | g.numericValueFunction << (g.trigFunction |
| 677 | | g.mathFunction |
| 678 | | g.inUnitFunction |
| 679 | | g.scalarArrayFunction |
| 680 | | g.arrayMapFunction |
| 681 | | g.userDefinedFunction |
| 682 | | g.numericGeometryFunction) |
| 683 | |
| 684 | g.foldFunction = ( |
| 685 | (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("UPPER") | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("LOWER"))("fName") |
| 686 | - '(' + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.characterValueExpression) + ')' ) |
| 687 | g.stringValueFunction = g.foldFunction |
| 688 | |
| 689 | g.characterPrimary << ( |
| 690 | g.stringValueFunction |
| 691 | | g.generalLiteral |
| 692 | | g.userDefinedFunction |
| 693 | | g.valueExpressionPrimary) |
| 694 | |
| 695 | g.timestampFunction = ( |
| 696 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('TIMESTAMP')("fName") - '(' |
| 697 | + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.stringValueExpression) - ')') |
| 698 | g.dateValueExpression = (g.timestampFunction) |
| 699 | |
| 700 | g.coalesceExpression = ( |
| 701 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('COALESCE') - '(' |
| 702 | + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.valueExpression) |
| 703 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(',' + Argsscip-python python gavodachs 2.13 `gavo.adql.grammar`/Args().(g.valueExpression)) - ')') |
| 704 | |
| 705 | g.searchCondition = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 706 | g.searchCondition.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("Condition") |
| 707 | g.caseResult = g.valueExpression |
| 708 | g.searchedWhenClause = ( |
| 709 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('WHEN') |
| 710 | + g.searchCondition |
| 711 | + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('THEN') |
| 712 | + g.caseResult) |
| 713 | g.simpleWhenClause = ( |
| 714 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('WHEN') |
| 715 | + g.valueExpression |
| 716 | + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('THEN') |
| 717 | + g.caseResult) |
| 718 | g.caseElseClause = CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('ELSE') + g.caseResult |
| 719 | g.searchedCase = ( |
| 720 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('CASE') |
| 721 | + OneOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/OneOrMore#(g.searchedWhenClause) |
| 722 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.caseElseClause) |
| 723 | - CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('END')) |
| 724 | g.simpleCase = ( |
| 725 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('CASE') |
| 726 | + g.valueExpression |
| 727 | + OneOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/OneOrMore#(g.simpleWhenClause) |
| 728 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.caseElseClause) |
| 729 | - CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#('END')) |
| 730 | g.caseExpression = ( |
| 731 | g.coalesceExpression |
| 732 | | g.searchedCase |
| 733 | | g.simpleCase) |
| 734 | |
| 735 | # toplevel value expression |
| 736 | g.valueExpression << ( |
| 737 | LongestMatchscip-python python gavodachs 2.13 `gavo.adql.grammar`/LongestMatch#([ |
| 738 | g.caseExpression, |
| 739 | g.numericValueExpression, |
| 740 | g.stringValueExpression, |
| 741 | g.dateValueExpression, |
| 742 | g.geometryValueExpression])) |
| 743 | g.valueExpression.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("value expression") |
| 744 | g.derivedColumn = g.valueExpression("expr") + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.asClause) |
| 745 | |
| 746 | # parts of select clauses |
| 747 | g.setQuantifier = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#( "DISTINCT" ) |
| 748 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#( "ALL" ))("setQuantifier") |
| 749 | g.setLimit = CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#( "TOP" ) - g.unsignedInteger("setLimit") |
| 750 | g.offsetSpec = CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#( "OFFSET" )- g.unsignedInteger("offset") |
| 751 | g.qualifiedStar = g.qualifier + "." + "*" |
| 752 | g.selectSublist = (g.qualifiedStar | g.derivedColumn |
| 753 | ).setResultsName("fieldSel", listAllMatches=True) |
| 754 | g.selectSublist.setName("select list item") |
| 755 | g.selectList = (Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#("*")("starSel") |
| 756 | | g.selectSublist + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#("," - g.selectSublist) |
| 757 | ) |
| 758 | g.selectList.setName("select list") |
| 759 | |
| 760 | # boolean terms |
| 761 | g.subquery = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 762 | g.subquery.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("Subquery") |
| 763 | g.comparisonPredicate = g.valueExpression + g.compOp + g.valueExpression |
| 764 | g.betweenPredicate = (g.valueExpression |
| 765 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.notKeyword) |
| 766 | + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("BETWEEN") |
| 767 | - g.valueExpression |
| 768 | + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("AND") |
| 769 | - g.valueExpression) |
| 770 | g.inValueList = g.valueExpression + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(',' + g.valueExpression) |
| 771 | g.inPredicateValue = g.subquery | ("(" + g.inValueList + ")") |
| 772 | g.inPredicate = (g.valueExpression + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.notKeyword) |
| 773 | + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("IN") + g.inPredicateValue) |
| 774 | g.existsPredicate = CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("EXISTS") - g.subquery |
| 775 | g.likePredicate = ( |
| 776 | g.characterValueExpression |
| 777 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.notKeyword) |
| 778 | + (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("LIKE") | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("ILIKE")) |
| 779 | + g.characterValueExpression) |
| 780 | g.nullPredicate = (g.columnReference |
| 781 | + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("IS") |
| 782 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.notKeyword) - g.nullLiteral) |
| 783 | g.predicate = (g.comparisonPredicate |
| 784 | | g.betweenPredicate |
| 785 | | g.inPredicate |
| 786 | | g.likePredicate |
| 787 | | g.nullPredicate |
| 788 | | g.existsPredicate) |
| 789 | g.booleanPrimaryOpener = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#('(') # for error messages |
| 790 | g.booleanPrimaryOpener.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("boolean expression") |
| 791 | g.booleanPrimary = ( |
| 792 | g.booleanPrimaryOpener + g.searchCondition + ')' |
| 793 | | g.predicate) |
| 794 | g.booleanPrimary.setName("boolean expression") |
| 795 | g.booleanFactor = Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.notKeyword) + g.booleanPrimary |
| 796 | g.booleanTerm = (g.booleanFactor + |
| 797 | ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("AND") - g.booleanFactor)) |
| 798 | |
| 799 | # WHERE clauses and such |
| 800 | g.searchCondition << (g.booleanTerm |
| 801 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("OR") - g.booleanTerm) |
| 802 | ) |
| 803 | g.searchCondition.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("search condition") |
| 804 | g.whereClause = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("WHERE") |
| 805 | - g.searchCondition)("whereClause") |
| 806 | |
| 807 | # Referencing tables |
| 808 | g.queryExpression = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 809 | g.queryExpression.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("Query expression") |
| 810 | g.correlationSpecification = ( |
| 811 | Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("AS") | g.whitespace) |
| 812 | + g.correlationName("alias")) |
| 813 | g.subqueryOpener = Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#('(') # for error reporting |
| 814 | g.subqueryOpener.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("subquery") |
| 815 | g.subquery << (g.subqueryOpener + g.queryExpression + ')') |
| 816 | g.derivedTable = g.subquery.copyscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#copy().() + g.correlationSpecification |
| 817 | g.tablesample = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("TABLESAMPLE") |
| 818 | - Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#('(') |
| 819 | - g.unsignedNumericLiteral |
| 820 | - Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#(')')) |
| 821 | g.possiblyAliasedTable = ( |
| 822 | (g.uploadTableName | g.tableName) |
| 823 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.correlationSpecification) |
| 824 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.tablesample)("tablesample")) |
| 825 | g.setGeneratingFunction = ( |
| 826 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("generate_series") |
| 827 | - Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#('(') |
| 828 | - g.nvArgs |
| 829 | - ',' |
| 830 | - g.nvArgs |
| 831 | - Literalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Literal#(')') |
| 832 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.correlationSpecification)) |
| 833 | g.joinedTable = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 834 | g.subJoin = '(' + g.joinedTable + ')' |
| 835 | g.joinOperand = ( |
| 836 | g.setGeneratingFunction |
| 837 | | g.possiblyAliasedTable |
| 838 | | g.derivedTable |
| 839 | | g.subJoin).setName("Join Operand") |
| 840 | g.tableReference = ( |
| 841 | g.joinedTable |
| 842 | | g.possiblyAliasedTable |
| 843 | | g.derivedTable) |
| 844 | g.tableReference.setName("table reference") |
| 845 | |
| 846 | # JOINs |
| 847 | g.columnNameList = ( |
| 848 | g.columnName |
| 849 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#( "," + g.columnName) |
| 850 | ) |
| 851 | g.columnNameList.setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("column name list") |
| 852 | g.namedColumnsJoin = ( |
| 853 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("USING") |
| 854 | + '(' + g.columnNameList("columnNames") + ')') |
| 855 | g.joinCondition = CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("ON") - g.searchCondition |
| 856 | g.joinSpecification = g.joinCondition | g.namedColumnsJoin |
| 857 | g.outerJoinType = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("LEFT") |
| 858 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("RIGHT") |
| 859 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("FULL")) |
| 860 | g.joinType = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("INNER") |
| 861 | | (g.outerJoinType + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("OUTER"))) |
| 862 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("CROSS")) # local extension |
| 863 | g.joinOperator = (Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("NATURAL")) |
| 864 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.joinType) |
| 865 | + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("JOIN")) |
| 866 | g.joinedTable << (g.joinOperand |
| 867 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(g.joinOperator |
| 868 | + g.joinOperand |
| 869 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.joinSpecification))).setName("Joined Table") |
| 870 | |
| 871 | # Detritus in table expressions |
| 872 | g.groupByClause = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("GROUP") + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("BY") |
| 873 | + g.valueExpression |
| 874 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(',' + g.valueExpression))("groupby") |
| 875 | g.havingClause = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("HAVING") |
| 876 | + g.searchCondition)("having") |
| 877 | g.orderingSpecification = (Regexscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Regex#("(?i)ASC|DESC")) |
| 878 | g.sortKey = g.valueExpression |
| 879 | g.sortSpecification = g.sortKey + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.orderingSpecification) |
| 880 | g.orderByClause = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("ORDER") |
| 881 | + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("BY") + g.sortSpecification |
| 882 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#( ',' + g.sortSpecification ))("orderBy") |
| 883 | |
| 884 | # FROM fragments and such |
| 885 | g.fromClause = (Suppressscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Suppress#(CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("FROM").setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("FROM")) |
| 886 | + g.tableReference |
| 887 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(Suppressscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Suppress#(',') - g.tableReference))("fromClause") |
| 888 | g.tableExpression = (g.fromClause |
| 889 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.whereClause) |
| 890 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.groupByClause) |
| 891 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.havingClause) |
| 892 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.orderByClause)) |
| 893 | |
| 894 | # Common Table Expressions |
| 895 | g.selectExpression = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#().setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("Select expression") |
| 896 | g.querySetExpression = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 897 | g.querySetTerm = Forwardscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Forward#() |
| 898 | |
| 899 | g.withQuery = (g.regularIdentifier("queryName") |
| 900 | + CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("AS") |
| 901 | + '(' + g.selectExpression + ')') |
| 902 | g.withSpecification = (CaselessLiteralscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessLiteral#("WITH") |
| 903 | + g.withQuery + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(',' + g.withQuery) ) |
| 904 | |
| 905 | # toplevel select clause and set operators |
| 906 | g.selectQuery = (CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("SELECT").setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().("SELECT") |
| 907 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.setQuantifier) |
| 908 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.setLimit) |
| 909 | + g.selectList + g.tableExpression) |
| 910 | |
| 911 | g.optionalAll = Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("ALL")) |
| 912 | g.intersectOperator = ( |
| 913 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("INTERSECT") |
| 914 | + g.optionalAll) |
| 915 | g.additiveSetOperator = (( |
| 916 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("UNION") |
| 917 | | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("EXCEPT") ) |
| 918 | + g.optionalAll) |
| 919 | |
| 920 | # I had to rewrite a few of the following ones to avoid pyparse |
| 921 | # infinite recursions. |
| 922 | g.querySetPrimary = MatchFirstWithSaneErrorscip-python python gavodachs 2.13 `gavo.utils.parsetricks`/MatchFirstWithSaneError#([ |
| 923 | g.selectQuery, |
| 924 | '(' + g.selectExpression + ')']) |
| 925 | g.querySetTerm << ( |
| 926 | g.querySetPrimary |
| 927 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(g.intersectOperator + g.querySetExpression)) |
| 928 | g.querySetExpression << ( |
| 929 | g.querySetTerm |
| 930 | + ZeroOrMorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ZeroOrMore#(g.additiveSetOperator + g.querySetTerm)) |
| 931 | |
| 932 | g.selectExpression << ( |
| 933 | g.querySetExpression |
| 934 | + Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.offsetSpec)) |
| 935 | g.queryExpression << (g.selectExpression | g.joinedTable).setNamescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#setName().( |
| 936 | "Query Expression") |
| 937 | |
| 938 | g.querySpecification = Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.withSpecification) + g.selectExpression |
| 939 | |
| 940 | g.createAs = ( |
| 941 | CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("CREATE") |
| 942 | - CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("TABLE") |
| 943 | - g.uploadTableName |
| 944 | - CaselessKeywordscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/CaselessKeyword#("AS")) |
| 945 | g.statement = ( |
| 946 | Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(g.createAs) |
| 947 | + g.querySpecification + Suppressscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Suppress#(Optionalscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/Optional#(Whitescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/White#()) + StringEndscip-python python gavodachs 2.13 `gavo.imp.pyparsing`/StringEnd#())) |
| 948 | |
| 949 | g.statement.ignorescip-python python gavodachs 2.13 `gavo.imp.pyparsing`/ParserElement#ignore().(g.sqlComment) |
| 950 | return g.getSymbols_scip-python python gavodachs 2.13 `gavo.adql.bindinggrammar`/AutoBindingGrammar#getSymbols_().(), g.statement |
| 951 | |
| 952 | |
| 953 | _grammarCachescip-python python gavodachs 2.13 `gavo.adql.grammar`/_grammarCache. = None |
| 954 | |
| 955 | def enableDebugscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableDebug().(symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableDebug().(syms), debugNamesscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableDebug().(debugNames)=None): # pragma: no cover |
| 956 | if not debugNamesscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableDebug().(debugNames): |
| 957 | debugNamesscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableDebug().(debugNames) = symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableDebug().(syms) |
| 958 | for name in debugNamesscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableDebug().(debugNames): |
| 959 | ob = symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableDebug().(syms)[name] |
| 960 | if not ob.debug: |
| 961 | ob.setDebug(True) |
| 962 | ob.setName(name) |
| 963 | if "sqlComment" in symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableDebug().(syms): |
| 964 | symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableDebug().(syms)["sqlComment"].setDebug(False) |
| 965 | |
| 966 | |
| 967 | def enableTreescip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().(symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().(syms)): # pragma: no cover |
| 968 | def makeActionscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().makeAction().(namescip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().makeAction().(name)): |
| 969 | def actionscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().makeAction().action().(sscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().makeAction().action().(s), posscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().makeAction().action().(pos), toksscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().makeAction().action().(toks)): |
| 970 | return [namescip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().makeAction().(name), toksscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().makeAction().action().(toks)] |
| 971 | return actionscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().makeAction().action(). |
| 972 | for name in symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().(syms): |
| 973 | ob = symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().(syms)[name] |
| 974 | if not ob.debug: |
| 975 | ob.setDebug(True) |
| 976 | ob.setName(name) |
| 977 | ob.addParseAction(makeActionscip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().makeAction().(name)) |
| 978 | |
| 979 | |
| 980 | @functoolsscip-python python python-stdlib 3.11 functools/__init__:.lru_cachescip-python python python-stdlib 3.11 functools/lru_cache().(1) |
| 981 | def getADQLGrammarscip-python python gavodachs 2.13 `gavo.adql.grammar`/getADQLGrammar().(): |
| 982 | """returns a pair of (symbols, root) for an ADQL grammar. |
| 983 | |
| 984 | This probably is mainly useful for testing. At least you should not set |
| 985 | names or parseActions on whatever you are returned unless you are |
| 986 | testing. |
| 987 | """ |
| 988 | return getADQLGrammarCopyscip-python python gavodachs 2.13 `gavo.adql.grammar`/getADQLGrammarCopy().([]) |
| 989 | |
| 990 | |
| 991 | if __name__scip-python python gavodachs 2.13 `gavo.adql.grammar`/=="__main__": # pragma: no cover |
| 992 | def printCsscip-python python gavodachs 2.13 `gavo.adql.grammar`/printCs().(sscip-python python gavodachs 2.13 `gavo.adql.grammar`/printCs().(s), posscip-python python gavodachs 2.13 `gavo.adql.grammar`/printCs().(pos), toksscip-python python gavodachs 2.13 `gavo.adql.grammar`/printCs().(toks)): |
| 993 | printscip-python python python-stdlib 3.11 builtins/print().("---------------Tokens:", toksscip-python python gavodachs 2.13 `gavo.adql.grammar`/printCs().(toks)) |
| 994 | import pprintscip-python python python-stdlib 3.11 pprint/__init__: |
| 995 | symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/syms., grammarscip-python python gavodachs 2.13 `gavo.adql.grammar`/grammar. = getADQLGrammarscip-python python gavodachs 2.13 `gavo.adql.grammar`/getADQLGrammar().() |
| 996 | enableTreescip-python python gavodachs 2.13 `gavo.adql.grammar`/enableTree().(symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/syms.) |
| 997 | resscip-python python gavodachs 2.13 `gavo.adql.grammar`/res. = symsscip-python python gavodachs 2.13 `gavo.adql.grammar`/syms.["statement"].parseString( |
| 998 | """select 4.5@{km} from misc |
| 999 | """ |
| 1000 | , parseAll=True) |
| 1001 | pprintscip-python python python-stdlib 3.11 pprint/__init__:.pprintscip-python python python-stdlib 3.11 pprint/pprint().(resscip-python python gavodachs 2.13 `gavo.adql.grammar`/res..asList(), streamscip-python python python-stdlib 3.11 pprint/pprint().(stream)=sysscip-python python python-stdlib 3.11 sys/__init__:.stderrscip-python python python-stdlib 3.11 sys/stderr.stderr.) |