DerekStride / tree-sitter-sql

SQL grammar for tree-sitter
http://derek.stride.host/tree-sitter-sql/
MIT License
159 stars 54 forks source link

Add backslashed single quotes to grammar #262

Open kislikjeka98 opened 4 months ago

kislikjeka98 commented 4 months ago

It breaks if use single quoted string with backslash escaped single quote, for example 'Author\'s name'. But mysql and postgres accept it https://dev.mysql.com/doc/refman/8.4/en/string-literals.html https://www.postgresql.org/docs/current/sql-syntax-lexical.html

I think it can be fixed by changing single_quote grammar to this

{
    "_single_quote_string": {
        "type": "SEQ",
        "members": [
            {
                "type": "PATTERN",
                "value": "([uU]&)?'(''|[^'\\]|\\.)*'"
            },
            {
                "type": "REPEAT",
                "content": {
                    "type": "PATTERN",
                    "value": "'(''|[^'\\]|\\.)*'"
                }
            }
        ]
    }
}
matthias-Q commented 4 months ago

This change is not enough, unfortunately. I have tested it and it breaks some tests (COPY FROM STDIN, because there a backslash can be set as an escape char)

kislikjeka98 commented 4 months ago

In my mind COMMENT used more frequiently than copy statements with EXCAPE '\' But i will think what to with this case

matthias-Q commented 4 months ago

Correct, but the parser work in all cases. I would really not like to remove functionality.

I did not had the time to look deeper into that issue.