Skip to content

Commit

Permalink
fix: fix DuckDB LOAD syntax support
Browse files Browse the repository at this point in the history
Related to #882

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/quarylabs/sqruff/issues/882?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
benfdking committed Nov 24, 2024
1 parent f059720 commit a003be0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
27 changes: 25 additions & 2 deletions crates/lib-dialects/src/duckdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ use sqruff_lib_core::parser::parsers::StringParser;
use sqruff_lib_core::parser::segments::meta::MetaSegment;
use sqruff_lib_core::vec_of_erased;

use crate::{ansi, postgres};

pub fn dialect() -> Dialect {
raw_dialect().config(|dialect| dialect.expand())
}

pub fn raw_dialect() -> Dialect {
let ansi_dialect = super::ansi::raw_dialect();
let postgres_dialect = super::postgres::dialect();
let ansi_dialect = ansi::raw_dialect();
let postgres_dialect = postgres::dialect();
let mut duckdb_dialect = postgres_dialect;
duckdb_dialect.name = DialectKind::Duckdb;

Expand Down Expand Up @@ -60,6 +62,15 @@ pub fn raw_dialect() -> Dialect {
)
.into(),
),
(
"LoadStatementSegment".into(),
Sequence::new(vec_of_erased![
Ref::keyword("LOAD"),
Ref::new("SingleIdentifierGrammar"),
])
.to_matchable()
.into(),
),
]);

duckdb_dialect.insert_lexer_matchers(
Expand Down Expand Up @@ -177,5 +188,17 @@ pub fn raw_dialect() -> Dialect {
.to_matchable(),
);

duckdb_dialect.replace_grammar(
"StatementSegment",
postgres::statement_segment().copy(
Some(vec_of_erased![Ref::new("LoadStatementSegment")]),
None,
None,
None,
vec![],
false,
),
);

duckdb_dialect
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LOAD spatial;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
file:
- statement:
- keyword: LOAD
- naked_identifier: spatial
- statement_terminator: ;

0 comments on commit a003be0

Please sign in to comment.