Вот ваши тесты, выложенные для runTests:
tests = """\
SELECT emp.ename as e FROM scott.employee as emp
SELECT ename as e, fname as f FROM scott.employee as emp
#Here I combine both conventions i.e' rc2+rc1)
SELECT emp.eid, fname,lname FROM scott.employee as emp
#Here I combine both conventions i.e' rc1+rc2)
SELECT ename, lname, emp.eid FROM scott.employee as emp
"""
Используя парсер из select_parser.py, выходные данные runTests выглядят так:
SELECT emp.ename as e FROM scott.employee as emp
['SELECT', [['emp.ename', 'AS', 'e']], 'FROM', ['scott', '.', 'employee'], 'AS', 'emp']
- columns: [['emp.ename', 'AS', 'e']]
[0]:
['emp.ename', 'AS', 'e']
- from: [['scott', '.', 'employee']]
[0]:
['scott', '.', 'employee']
- database: ['scott']
- table: [['employee']]
[0]:
['employee']
- table_alias: [['emp']]
[0]:
['emp']
SELECT ename as e, fname as f FROM scott.employee as emp
['SELECT', [['ename', 'AS', 'e'], ['fname', 'AS', 'f']], 'FROM', ['scott', '.', 'employee'], 'AS', 'emp']
- columns: [['ename', 'AS', 'e'], ['fname', 'AS', 'f']]
[0]:
['ename', 'AS', 'e']
[1]:
['fname', 'AS', 'f']
- from: [['scott', '.', 'employee']]
[0]:
['scott', '.', 'employee']
- database: ['scott']
- table: [['employee']]
[0]:
['employee']
- table_alias: [['emp']]
[0]:
['emp']
#Here I combine both conventions i.e' rc2+rc1)
SELECT emp.eid, fname,lname FROM scott.employee as emp
['SELECT', [['emp.eid'], ['fname'], ['lname']], 'FROM', ['scott', '.', 'employee'], 'AS', 'emp']
- columns: [['emp.eid'], ['fname'], ['lname']]
[0]:
['emp.eid']
[1]:
['fname']
[2]:
['lname']
- from: [['scott', '.', 'employee']]
[0]:
['scott', '.', 'employee']
- database: ['scott']
- table: [['employee']]
[0]:
['employee']
- table_alias: [['emp']]
[0]:
['emp']
#Here I combine both conventions i.e' rc1+rc2)
SELECT ename, lname, emp.eid FROM scott.employee as emp
['SELECT', [['ename'], ['lname'], ['emp.eid']], 'FROM', ['scott', '.', 'employee'], 'AS', 'emp']
- columns: [['ename'], ['lname'], ['emp.eid']]
[0]:
['ename']
[1]:
['lname']
[2]:
['emp.eid']
- from: [['scott', '.', 'employee']]
[0]:
['scott', '.', 'employee']
- database: ['scott']
- table: [['employee']]
[0]:
['employee']
- table_alias: [['emp']]
[0]:
['emp']
Это не должно быть два разныхВ выражениях pyparsing вы должны быть способны написать только одно, которое захватывает необязательное имя ведущей таблицы, и дать ему соответствующее имя результата.Затем сделайте имя столбца группой, чтобы из каждого можно было извлечь имя и таблицу.