Skip to content

Commit b28003d

Browse files
authored
Fix dollar sign should be a valid part of the identifier (#147)
1 parent a0842a7 commit b28003d

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

parser/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ func IsIdentStart(c byte) bool {
1313
}
1414

1515
func IsIdentPart(c byte) bool {
16-
return '0' <= c && c <= '9' || 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_'
16+
return '0' <= c && c <= '9' || 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_' || c == '$'
1717
}

parser/lexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (l *Lexer) consumeIdent(_ Pos) error {
188188

189189
i := 0
190190
if quoteType == Unquoted {
191-
if l.peekN(i) == '$' {
191+
if l.peekOk(i) && l.peekN(i) == '$' {
192192
i++
193193
}
194194
for l.peekOk(i) && IsIdentPart(l.peekN(i)) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
-- Origin SQL:
22
SELECT 'abc' as "value2";
33

4+
SELECT $abc, a$$bc, abc$$;
5+
6+
47
-- Format SQL:
58
SELECT 'abc' AS "value2";
9+
SELECT $abc, a$$bc, abc$$;

parser/testdata/query/output/select_column_alias_string.sql.golden.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,59 @@
3636
"UnionAll": null,
3737
"UnionDistinct": null,
3838
"Except": null
39+
},
40+
{
41+
"SelectPos": 27,
42+
"StatementEnd": 52,
43+
"With": null,
44+
"Top": null,
45+
"SelectItems": [
46+
{
47+
"Expr": {
48+
"Name": "$abc",
49+
"QuoteType": 1,
50+
"NamePos": 34,
51+
"NameEnd": 38
52+
},
53+
"Modifiers": [],
54+
"Alias": null
55+
},
56+
{
57+
"Expr": {
58+
"Name": "a$$bc",
59+
"QuoteType": 1,
60+
"NamePos": 40,
61+
"NameEnd": 45
62+
},
63+
"Modifiers": [],
64+
"Alias": null
65+
},
66+
{
67+
"Expr": {
68+
"Name": "abc$$",
69+
"QuoteType": 1,
70+
"NamePos": 47,
71+
"NameEnd": 52
72+
},
73+
"Modifiers": [],
74+
"Alias": null
75+
}
76+
],
77+
"From": null,
78+
"ArrayJoin": null,
79+
"Window": null,
80+
"Prewhere": null,
81+
"Where": null,
82+
"GroupBy": null,
83+
"WithTotal": false,
84+
"Having": null,
85+
"OrderBy": null,
86+
"LimitBy": null,
87+
"Limit": null,
88+
"Settings": null,
89+
"Format": null,
90+
"UnionAll": null,
91+
"UnionDistinct": null,
92+
"Except": null
3993
}
4094
]
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
SELECT 'abc' as "value2";
1+
SELECT 'abc' as "value2";
2+
3+
SELECT $abc, a$$bc, abc$$;

0 commit comments

Comments
 (0)