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

Node for parenthesized expressions #274

Closed
HiPhish opened this issue Aug 14, 2024 · 3 comments
Closed

Node for parenthesized expressions #274

HiPhish opened this issue Aug 14, 2024 · 3 comments

Comments

@HiPhish
Copy link

HiPhish commented Aug 14, 2024

Hello,

maintainer of HiPhish/rainbow-delimiters.nvim here; I have a problem matching and properly highlighting parenthesized expressions. The problem is that all the parentheses of an expression are on the same level as their siblings. Consider the following query:

SELECT ((((1))));

It's a weird query, but at least in SQLite it is valid. The tree looks like this:

  (select
    (keyword_select)
    (select_expression
      (term
        value: "("
        value: "("
        value: "("
        value: "("
        value: (literal)
        value: ")"
        value: ")"
        value: ")"
        value: ")")))

All the parentheses are on the same level, it is impossible to build up a tree of "containers" to determine the proper nesting. I propose a sort of parenthesized_expression node (or whatever name you consider more appropriate). With that node the term would have only one value:

  (select
    (keyword_select)
    (select_expression
      (term
    	value: (parenthesized_expression
    	  "("
    	  (parenthesized_expression
    	    "("
    	    (parenthesized_expression
    	      "("
    	      (parenthesized_expression
    	        "("
                (literal)
    	        ")")
    	      ")")
    	    ")")
    	  ")"))))

Let's take another example:

SELECT 1 + (2);

The original tree:

  (select
    (keyword_select)
    (select_expression
      (term
        value: (binary_expression
          left: (literal)
          operator: "+"
          right: "("
          right: (literal)
          right: ")"))))

How many right nodes can a binary expression reasonably have? Here is what it would look like with parenthesized_expression:

(select
  (keyword_select)
  (select_expression
    (term
      value: (binary_expression
        left: (literal)
        operator: "+"
        right: (parenthesized_expression
          "("
          (literal)
          ")")))))
@matthias-Q
Copy link
Collaborator

I agree. I think our AST is sometimes way to "flat". I will take a look later today.

@matthias-Q
Copy link
Collaborator

Closed by #275

Please tell me if that change is sufficient.

@HiPhish
Copy link
Author

HiPhish commented Aug 30, 2024

Looks great, thank you!

Screenshot_20240831_002856

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