Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Expose tag from dollar quoted strings #281

Open
dbaynard opened this issue Oct 22, 2024 · 3 comments
Open

Feature request: Expose tag from dollar quoted strings #281

dbaynard opened this issue Oct 22, 2024 · 3 comments

Comments

@dbaynard
Copy link

I use this grammar with neovim and I would like to take advantage of the language injection functionality. One elegant way to do this is to parse the language indicated in a dollar quoted string tag.

select $${"some":"json"}$$::jsonb;
select $json${"some":"json"}$json$::jsonb;

(It seems linguist, via https://github.com/textmate/sql.tmbundle, gets the highlighting here correct — I'm not sure how, though.)

At the moment, the whole text (including the tags) gets returned as a (literal). I would like to return an expression like (quoted_string tag: (literal) value: (literal)).

It looks like this requires a change to scanner.c for this, though, and it would also have knock on effects downstream (although these would be small and manageable).

Would such a change be welcome?

@DerekStride
Copy link
Owner

This seems like a good change to me, feel free to take this as guidance not the exact behaviour but I would expect a test like this (tag should probably be (identifier) and value can be literal):

================================================================================
dollar quoted string with tag
================================================================================

SELECT select $json${"some":"json"}$json$::jsonb;

--------------------------------------------------------------------------------

(program
  (statement
    (select
      (keyword_select)
      (select_expression
        (term
          value: (cast
            (literal
              (quoted_string tag: (identifier) value: (literal))
            (keyword_jsonb))))))

@dbaynard
Copy link
Author

Ah, that preserves the currrent behaviour with any matching on literal so it is backwards compatible?

This is the current parse for that example.
(program
  (statement
    (select
      (keyword_select)
      (select_expression
        (term
          value: (cast
            (literal)
            (keyword_jsonb)))))))

Thanks for the quick response. I can't commit to an implementation timeline. That said, I would like to do it this week, while looking at my monochrome embedded json acts as a reminder.

The use of quoted_string (rather than dollar_quoted_string) would apply to unwrapping quotes on other quote forms — I don't propose doing that now. Postgresql refers to 'string constants' and 'dollar-quoted string constants so it could also just be string.

@DerekStride
Copy link
Owner

The use of quoted_string (rather than dollar_quoted_string) would apply to unwrapping quotes on other quote forms — I don't propose doing that now. Postgresql refers to 'string constants' and 'dollar-quoted string constants so it could also just be string.

Either of those make sense to me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants