Skip to content

Expose libpq client lexer #284

@mmoncure

Description

@mmoncure

Currently, the provided parser aborts processing on any error. This is problematic for anything that would like to resume on processing, for example, lsp type implementations that would want to parse larger files and not be limited to stopping on first error.

The libpq lexer would do this and guarantee that statements would be 1:1 as to how they are seen in psql, and would additionally allow for other psql commands like backslash commands \if, \endif etc to be at least removed or possibly even handled the same way the server would handle them, which would lower the downstream parsing burden and improve compatibility with the server parsing outcomes.

Hacking around a bit, I was able to work out a simple program that exposed psqlscan.l and related functions and do some basic lexing that could sit in front of an lsp implementation. To do this though, I had to rip out various things and hand compile, the postgres build system is complex and I was not able to get it to work out of standard make. I'm thinking that this the right project to utilize to solve that particular problem, basically, expose the statement lexer and return a list of high level primitives (statement, backslash command etc) along with character start/end in the strem, and return them. This could be then fed back into the parsing API or utilized in some other deeper parsing implementation.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions