Skip to content

Commit

Permalink
TSQL: allow leading GO (#2997)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Guyot <pguyot@upclear.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
  • Loading branch information
3 people committed Apr 4, 2022
1 parent 939113e commit ae7b629
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/sqlfluff/dialects/dialect_tsql.py
Expand Up @@ -2572,16 +2572,19 @@ class FileSegment(BaseFileSegment):

# NB: We don't need a match_grammar here because we're
# going straight into instantiating it directly usually.
parse_grammar = Delimited(
Ref("BatchSegment"),
delimiter=AnyNumberOf(
Sequence(
Ref("DelimiterGrammar", optional=True), Ref("BatchDelimiterGrammar")
parse_grammar = Sequence(
AnyNumberOf(Ref("BatchDelimiterGrammar")),
Delimited(
Ref("BatchSegment"),
delimiter=AnyNumberOf(
Sequence(
Ref("DelimiterGrammar", optional=True), Ref("BatchDelimiterGrammar")
),
min_times=1,
),
min_times=1,
allow_gaps=True,
allow_trailing=True,
),
allow_gaps=True,
allow_trailing=True,
)


Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/dialects/tsql/go_delimiters.sql
@@ -1,3 +1,5 @@
-- It's possible to have a file starting with GO
GO
-- It's possible to have multiple GO between batches.
SELECT foo FROM bar GO GO
SELECT foo FROM bar GO
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/dialects/tsql/go_delimiters.yml
Expand Up @@ -3,8 +3,10 @@
# 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: 48ee8f3f556e82816f06c2f0155e2eb39630f07d23a9a0a7cf961d58d58df5eb
_hash: bd36bce2e40fe28989cdc56078defe2ddae2d528b37e5b717984c9a6e64041af
file:
- go_statement:
keyword: GO
- batch:
statement:
select_statement:
Expand Down

0 comments on commit ae7b629

Please sign in to comment.