Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix table alias location tracking #158

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/syntax/base.ne
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ data_type_date
# === Table ref (ex: [db.]mytable [as X] )

# [AS x] or just [x]
ident_aliased -> (%kw_as ident {% last %}) | ident {% unwrap %}
ident_aliased -> (%kw_as ident {% last %}) | ident {% last %}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestions on this? my only reasoning for using last here is because, unlike unwrap, it handles tracking under the hood.


table_ref -> qualified_name {% unwrap %}

Expand Down
46 changes: 45 additions & 1 deletion src/syntax/select.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'mocha';
import 'chai';
import { checkSelect, checkInvalid, columns, ref, star, tbl, name, qname, checkStatement, int, binary } from './spec-utils';
import { checkSelect, checkSelectLoc, checkInvalid, columns, ref, star, tbl, name, qname, checkStatement, int, binary } from './spec-utils';
import { JoinType, SelectStatement } from './ast';

describe('Select statements', () => {
Expand Down Expand Up @@ -1060,4 +1060,48 @@ describe('Select statements', () => {
type: 'skip locked',
}
});

checkSelectLoc('select * from test as t', {
_location: { start: 0, end: 23 },
type: 'select',
from: [{
_location: { start: 14, end: 23 },
type: 'table',
name: {
_location: { start: 14, end: 23 },
name: 'test',
alias: 't',
}
}],
columns: [{
_location: { start: 7, end: 8 },
expr: {
_location: { start: 7, end: 8 },
type: 'ref',
name: '*',
}
}]
});
Comment on lines +1064 to +1084
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test passes on master and on this branch


checkSelectLoc('select * from test t', {
_location: { start: 0, end: 20 },
type: 'select',
from: [{
_location: { start: 14, end: 20 },
type: 'table',
name: {
_location: { start: 14, end: 20 },
name: 'test',
alias: 't',
},
}],
columns: [{
_location: { start: 7, end: 8 },
expr: {
_location: { start: 7, end: 8 },
type: 'ref',
name: '*',
},
}]
});
Comment on lines +1086 to +1106
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails on master. The end positions there are 18 instead of 20, because the t part is omitted.

});
6 changes: 5 additions & 1 deletion src/syntax/spec-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function checkSelect(value: string | string[], expected: SelectStatement)
checkTree(value, expected, (p, m) => m.statement(p));
}

export function checkSelectLoc(value: string | string[], expected: SelectStatement) {
checkTree(value, expected, (p, m) => m.statement(p), undefined, true);
}

export function checkCreateSequence(value: string | string[], expected: CreateSequenceStatement) {
checkTree(value, expected, (p, m) => m.statement(p));
}
Expand Down Expand Up @@ -330,4 +334,4 @@ export function tbl(nm: string): FromTable {
}
export function numeric(value: number): ExprNumeric {
return { type: 'numeric', value };
}
}