| 1 |
""" |
| 2 |
Parsing, annotating, and morphing queries in the Astronomical Data |
| 3 |
Query Language. |
| 4 |
""" |
| 5 |
|
| 6 |
#c Copyright 2008-2025, the GAVO project <[email protected]> |
| 7 |
#c |
| 8 |
#c This program is free software, covered by the GNU GPL. See the |
| 9 |
#c COPYING file in the source distribution. |
| 10 |
|
| 11 |
|
| 12 |
# Not checked by pyflakes: API file with gratuitous imports |
| 13 |
|
| 14 |
from gavo.adql.annotations import annotate, optimize |
| 15 |
|
| 16 |
from gavo.adql.common import * |
| 17 |
|
| 18 |
from gavo.adql.nodes import flatten, registerNode, getTreeBuildingGrammar |
| 19 |
|
| 20 |
from gavo.adql.grammar import ( |
| 21 |
getADQLGrammar as getRawGrammar, |
| 22 |
ALL_RESERVED_WORDS, |
| 23 |
ParseException, ParseSyntaxException) |
| 24 |
|
| 25 |
from gavo.adql.morphpg import ( |
| 26 |
morphPG) |
| 27 |
|
| 28 |
from gavo.adql.fieldinfo import getSubsumingType, FieldInfo |
| 29 |
|
| 30 |
from gavo.adql.ufunctions import userFunction |
| 31 |
|
| 32 |
|
| 33 |
def getSymbols(): |
| 34 |
return getTreeBuildingGrammar()[0] |
| 35 |
|
| 36 |
def getGrammar(): |
| 37 |
return getTreeBuildingGrammar()[1] |
| 38 |
|
| 39 |
|
| 40 |
def parseToTree(adqlStatement): |
| 41 |
"""returns a "naked" parse tree for adqlStatement. |
| 42 |
|
| 43 |
It contains no annotations, so you'll usually not want to use this. |
| 44 |
""" |
| 45 |
return utils.pyparseString(getGrammar(), adqlStatement)[0] |
| 46 |
|
| 47 |
|
| 48 |
def parseAnnotating(adqlStatement, fieldInfoGetter): |
| 49 |
"""returns a tuple of context, parsedTree for parsing and annotating |
| 50 |
adqlStatement. |
| 51 |
|
| 52 |
The builtin morphs are performed on the tree. |
| 53 |
""" |
| 54 |
parsedTree = parseToTree(adqlStatement) |
| 55 |
ctx = annotate(parsedTree, fieldInfoGetter) |
| 56 |
optimize(parsedTree) |
| 57 |
return ctx, parsedTree |