From 8dc6849c9e00afa45733ed9e0ef902b2728d183d Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Mon, 21 Sep 2026 13:41:14 +0200 Subject: [PATCH 1/3] Avoid parsing // as comment when inside string --- tree-sitter-ggsql/grammar.js | 2 +- tree-sitter-ggsql/test/corpus/basic.txt | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tree-sitter-ggsql/grammar.js b/tree-sitter-ggsql/grammar.js index 66c301ed..bdb404ec 100644 --- a/tree-sitter-ggsql/grammar.js +++ b/tree-sitter-ggsql/grammar.js @@ -1115,7 +1115,7 @@ module.exports = grammar({ ) )), - string: $ => seq("'", repeat(choice(/[^'\\]/, /\\./)), "'"), + string: $ => token(seq("'", repeat(choice(/[^'\\]/, /\\./)), "'")), boolean: $ => choice('true', 'false'), diff --git a/tree-sitter-ggsql/test/corpus/basic.txt b/tree-sitter-ggsql/test/corpus/basic.txt index 881519ac..bb173b7c 100644 --- a/tree-sitter-ggsql/test/corpus/basic.txt +++ b/tree-sitter-ggsql/test/corpus/basic.txt @@ -4536,3 +4536,27 @@ DRAW point SETTING bounds => [null, 1, Inf, -Inf], limit => inf (bare_identifier))) value: (parameter_value (infinity)))))))) + +================================================================================ +Label string containing URL with comment-like sequences +================================================================================ + +VISUALISE +DRAW point +LABEL caption => 'Data source: -- see appendix' + +-------------------------------------------------------------------------------- + +(query + (visualise_statement + (visualise_keyword) + (viz_clause + (draw_clause + (geom_type))) + (viz_clause + (label_clause + (label_assignment + (label_type + (identifier + (bare_identifier))) + (string)))))) From c8c68bc1a395d64d27663333ccc68a4b95c9bcc2 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Mon, 21 Sep 2026 13:43:52 +0200 Subject: [PATCH 2/3] Add changelig --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 756a7070..0d70d803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## [Unreleased] +### Fixed + +- Fixed a parser bug that interpreted comment characters inside string literals + as initializing a comment (#555). + ## 0.5.2 - 2026-09-11 ### Changed From cbe563397b8a5c43f4cbddfb95eecf4c4b5034b5 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Mon, 21 Sep 2026 15:38:55 +0200 Subject: [PATCH 3/3] Add comment tests --- tree-sitter-ggsql/test/corpus/basic.txt | 128 ++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/tree-sitter-ggsql/test/corpus/basic.txt b/tree-sitter-ggsql/test/corpus/basic.txt index bb173b7c..493f5f1e 100644 --- a/tree-sitter-ggsql/test/corpus/basic.txt +++ b/tree-sitter-ggsql/test/corpus/basic.txt @@ -4560,3 +4560,131 @@ LABEL caption => 'Data source: -- (identifier (bare_identifier))) (string)))))) + +================================================================================ +Line comment (double slash) between clauses +================================================================================ + +// A leading comment +VISUALISE x, y // trailing comment on the same line +DRAW point +// comment before a clause +LABEL title => 'My Plot' // and one at the end + +-------------------------------------------------------------------------------- + +(query + (comment) + (visualise_statement + (visualise_keyword) + (global_mapping + (mapping_list + (mapping_element + (implicit_mapping + (identifier + (bare_identifier)))) + (mapping_element + (implicit_mapping + (identifier + (bare_identifier)))))) + (comment) + (viz_clause + (draw_clause + (geom_type))) + (comment) + (viz_clause + (label_clause + (label_assignment + (label_type + (identifier + (bare_identifier))) + (string))))) + (comment)) + +================================================================================ +SQL line comment (double dash) +================================================================================ + +VISUALISE x -- pick the x column +DRAW point + +-------------------------------------------------------------------------------- + +(query + (visualise_statement + (visualise_keyword) + (global_mapping + (mapping_list + (mapping_element + (implicit_mapping + (identifier + (bare_identifier)))))) + (comment) + (viz_clause + (draw_clause + (geom_type))))) + +================================================================================ +Block comment spanning lines +================================================================================ + +VISUALISE /* inline block */ x, y +DRAW point +/* a multi-line + block comment */ +LABEL title => 'My Plot' + +-------------------------------------------------------------------------------- + +(query + (visualise_statement + (visualise_keyword) + (comment) + (global_mapping + (mapping_list + (mapping_element + (implicit_mapping + (identifier + (bare_identifier)))) + (mapping_element + (implicit_mapping + (identifier + (bare_identifier)))))) + (viz_clause + (draw_clause + (geom_type))) + (comment) + (viz_clause + (label_clause + (label_assignment + (label_type + (identifier + (bare_identifier))) + (string)))))) + +================================================================================ +Comments alongside strings that contain comment-like text +================================================================================ + +-- leading comment +VISUALISE +DRAW point +LABEL caption => 'see https://example.com -- details' // trailing comment + +-------------------------------------------------------------------------------- + +(query + (comment) + (visualise_statement + (visualise_keyword) + (viz_clause + (draw_clause + (geom_type))) + (viz_clause + (label_clause + (label_assignment + (label_type + (identifier + (bare_identifier))) + (string))))) + (comment))