Skip to content

Commit e382659

Browse files
committed
Fix crash when .. syntax encountered in Transact-SQL
Fixes #700
1 parent 9c22894 commit e382659

File tree

7 files changed

+17
-3
lines changed

7 files changed

+17
-3
lines changed

src/formatter/ExpressionFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export default class ExpressionFormatter {
179179

180180
private formatPropertyAccess(node: PropertyAccessNode) {
181181
this.formatNode(node.object);
182-
this.layout.add(WS.NO_SPACE, '.');
182+
this.layout.add(WS.NO_SPACE, node.operator);
183183
this.formatNode(node.property);
184184
}
185185

src/lexer/Tokenizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export default class Tokenizer {
184184
]),
185185
},
186186
{ type: TokenType.ASTERISK, regex: /[*]/uy },
187-
{ type: TokenType.DOT, regex: /[.]/uy },
187+
{ type: TokenType.DOT, regex: /[.]+/uy },
188188
]);
189189
}
190190

src/lexer/token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export enum TokenType {
2828
OPERATOR = 'OPERATOR',
2929
COMMA = 'COMMA',
3030
ASTERISK = 'ASTERISK', // *
31-
DOT = 'DOT', // .
31+
DOT = 'DOT', // . (or .. in Transact-SQL)
3232
OPEN_PAREN = 'OPEN_PAREN',
3333
CLOSE_PAREN = 'CLOSE_PAREN',
3434
LINE_COMMENT = 'LINE_COMMENT',

src/parser/ast.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export interface LiteralNode extends BaseNode {
128128
export interface PropertyAccessNode extends BaseNode {
129129
type: NodeType.property_access;
130130
object: AstNode;
131+
operator: string;
131132
property: IdentifierNode | ArraySubscriptNode | AllColumnsAsteriskNode;
132133
}
133134

src/parser/grammar.ne

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ property_access -> atomic_expression _ %DOT _ (identifier | array_subscript | al
265265
return {
266266
type: NodeType.property_access,
267267
object: addComments(object, { trailing: _1 }),
268+
operator: dot.text,
268269
property: addComments(property, { leading: _2 }),
269270
};
270271
}

test/transactsql.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ describe('TransactSqlFormatter', () => {
101101
`);
102102
});
103103

104+
it('formats .. shorthand for database.schema.table', () => {
105+
expect(format('SELECT x FROM db..tbl')).toBe(dedent`
106+
SELECT
107+
x
108+
FROM
109+
db..tbl
110+
`);
111+
});
112+
104113
it('formats ALTER TABLE ... ALTER COLUMN', () => {
105114
expect(format(`ALTER TABLE t ALTER COLUMN foo INT NOT NULL DEFAULT 5;`)).toBe(dedent`
106115
ALTER TABLE t

test/unit/__snapshots__/Parser.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ Array [
293293
"text": "ident",
294294
"type": "identifier",
295295
},
296+
"operator": ".",
296297
"property": Object {
297298
"type": "all_columns_asterisk",
298299
},
@@ -642,13 +643,15 @@ Array [
642643
"text": "foo",
643644
"type": "identifier",
644645
},
646+
"operator": ".",
645647
"property": Object {
646648
"quoted": false,
647649
"text": "bar",
648650
"type": "identifier",
649651
},
650652
"type": "property_access",
651653
},
654+
"operator": ".",
652655
"property": Object {
653656
"quoted": false,
654657
"text": "baz",

0 commit comments

Comments
 (0)