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 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..493f5f1e 100644 --- a/tree-sitter-ggsql/test/corpus/basic.txt +++ b/tree-sitter-ggsql/test/corpus/basic.txt @@ -4536,3 +4536,155 @@ 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)))))) + +================================================================================ +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))