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

Add SiblingTokens back to the parser #54

Open
psteinroe opened this issue Dec 6, 2023 · 0 comments
Open

Add SiblingTokens back to the parser #54

psteinroe opened this issue Dec 6, 2023 · 0 comments

Comments

@psteinroe
Copy link
Collaborator

Sibling tokens are tokens that should end up at the same depth in the CST, such as ( and ). Right now, that is not the case. Take for example the following statement:

ALTER TABLE products ALTER COLUMN price TYPE numeric(10,2);

The brackets of numeric are not on the same level:

AlterTableStmt@0..59
        Alter@0..5 "ALTER"
        Whitespace@5..6 " "
        Table@6..11 "TABLE"
        Whitespace@11..12 " "
        RangeVar@12..20
          Ident@12..20 "products"
        Whitespace@20..21 " "
        AlterTableCmd@21..57
          Alter@21..26 "ALTER"
          Whitespace@26..27 " "
          Column@27..33 "COLUMN"
          Whitespace@33..34 " "
          Ident@34..39 "price"
          Whitespace@39..40 " "
          TypeP@40..44 "TYPE"
          Whitespace@44..45 " "
          ColumnDef@45..57
            TypeName@45..57
              Numeric@45..52 "numeric"
              Ascii40@52..53 "("  <-- this is deeper than
              AConst@53..55
                Iconst@53..55 "10"
              Ascii44@55..56 ","
              AConst@56..57
                Iconst@56..57 "2"
        Ascii41@57..58 ")" <-- this
        Ascii59@58..59 ";"

To fix this, we have to keep track the depth at which tokens are "opened". If the closing token is encountered, we apply it at the same depth as its sibling.

A SiblingToken struct already exists from past implementations. It should be reused.

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

1 participant