Skip to content

Commit

Permalink
Improve at_sign lexer.
Browse files Browse the repository at this point in the history
$ sign is now supported, and a `.` cannot be at the start/end of a variable name.
  • Loading branch information
qgallet committed Jul 9, 2022
1 parent 54e7fb6 commit b88321e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/sqlfluff/dialects/dialect_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,13 @@ class IntervalExpressionSegment(BaseSegment):
Ref("DatatypeSegment"),
),
LocalVariableNameSegment=RegexParser(
r"`?[a-zA-Z0-9_]*`?",
r"`?[a-zA-Z0-9_$]*`?",
CodeSegment,
name="declared_variable",
type="variable",
),
SessionVariableNameSegment=RegexParser(
r"[@][a-zA-Z0-9_]*",
r"[@][a-zA-Z0-9_$]*",
CodeSegment,
name="declared_variable",
type="variable",
Expand All @@ -717,7 +717,7 @@ class IntervalExpressionSegment(BaseSegment):
[
RegexLexer(
"at_sign",
r"@@?[a-zA-Z0-9_.]*",
r"@@?[a-zA-Z0-9_$]*(\.[a-zA-Z0-9_$]+)?",
CodeSegment,
),
],
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/dialects/mysql/set_session_variable.sql
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
set @abc = 1;
set @abc = 1;
set @my_var = 1;
set @my$currency = 1;
set @sha256enabled = 1;
30 changes: 27 additions & 3 deletions test/fixtures/dialects/mysql/set_session_variable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,37 @@
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: 91d7a5a3d6a5986cf93fd70ccbc2cc4f148a27c126ab479bc3d44f68690d4af3
_hash: 9e4ffffc861f4647dfc51be1591f5df5931d712fe5083c39fde3ce9942d8ad60
file:
statement:
- statement:
set_statement:
- keyword: set
- variable: '@abc'
- comparison_operator:
raw_comparison_operator: '='
- variable: '1'
statement_terminator: ;
- statement_terminator: ;
- statement:
set_statement:
- keyword: set
- variable: '@my_var'
- comparison_operator:
raw_comparison_operator: '='
- variable: '1'
- statement_terminator: ;
- statement:
set_statement:
- keyword: set
- variable: '@my$currency'
- comparison_operator:
raw_comparison_operator: '='
- variable: '1'
- statement_terminator: ;
- statement:
set_statement:
- keyword: set
- variable: '@sha256enabled'
- comparison_operator:
raw_comparison_operator: '='
- variable: '1'
- statement_terminator: ;

0 comments on commit b88321e

Please sign in to comment.