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

backslash is not defined in PostgresLexer #2310

Open
Andrew15-5 opened this issue Dec 29, 2022 · 5 comments
Open

backslash is not defined in PostgresLexer #2310

Andrew15-5 opened this issue Dec 29, 2022 · 5 comments

Comments

@Andrew15-5
Copy link

I stumbled on this problem multiple times. I need to lex an SQL script for PostgreSQL, specifically for creating and connecting to DB and creating tables in it. Everything works fine, but I don't know why such command as \connect is not defined. With minted package for TeX-family typesetting systems, the output of PDF file shows that the backslash in \connect command is not defined (or probably the command itself):

image

Other PostgreSQL lexers work even worse (some other commands are also not defined). After running python3 -I _postgres_builtins.py nothing has changed. Is this a bug or unimplemented syntax?

@Andrew15-5
Copy link
Author

Andrew15-5 commented Dec 29, 2022

I made a quick fix (without syntax highlighting):

sed -i 's/\((r"\[\)\(;:()\\\[\\\]{},.]", Punctuation)\)/\1\\\\\2/' "/home/$USER/.local/lib/$(realpath "$(command -v python3)" | xargs basename)/site-packages/pygments/lexers/sql.py"

But it doesn't really answer my question.

@Anteru
Copy link
Collaborator

Anteru commented Jan 2, 2023

Are you using PostgresConsoleLexer to highlight your code? I can't reproduce the issue using:

grafik

@Andrew15-5
Copy link
Author

In the title, I said that I use PostgresLexer (postgres). Other lexers such as PostgresConsoleLexer (psql) work differently. PostgresConsoleLexer just doesn't highlight anything after first line (I don't want that).

@Andrew15-5 Andrew15-5 changed the title backslash is not defined in PostgresLexer backslash is not defined in PostgresLexer Jan 2, 2023
@Anteru
Copy link
Collaborator

Anteru commented Jan 2, 2023

The console lexer is specified as the one that understands \command, so that's the one to use in your case. I noticed that without a prompt, it stops highlighting, but with a valid prompt (as you'd get from psql output) it works just fine:
grafik

The commands are part of the psql tool, not standard SQL, so it really only makes sense to have them in the PostgresConsoleLexer. Can you feed it "proper" psql output (including the prompt)? Otherwise you're asking for yet another flavor here ...

@Andrew15-5
Copy link
Author

As you can see in the screenshot, I use lexer to add syntax highlighting to a PostgreSQL script file. It includes standard SQL commands and psql specific, since this script is fed to psql command (through CLI). So, no, "proper" psql is not gonna cut it for me. I hope that I can modify PostgresConsoleLexer instead and be done with it. I'll post my "fix" here later. Thank you for explaining why PostgresConsoleLexer wasn't working.

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