Skip to content

make metacmd tokenization and quoted-string parsing match psql#565

Open
BapTruongSinh wants to merge 1 commit intoxo:mainfrom
BapTruongSinh:blueblueblue/feat/make-metacmd-tokenization-and-quoted-str
Open

make metacmd tokenization and quoted-string parsing match psql#565
BapTruongSinh wants to merge 1 commit intoxo:mainfrom
BapTruongSinh:blueblueblue/feat/make-metacmd-tokenization-and-quoted-str

Conversation

@BapTruongSinh
Copy link
Copy Markdown

This is the core parser change. The metacmd scanner/parser needs to stop treating quoted text and ' :' substitutions as mostly literal text and instead parse them with psql-compatible rules. The issue examples show three failures that all point here: ':{?name}' is not recognized at all, single-quoted strings used by ' \set' are not decoded with psql escape rules, and backtick bodies are not being tokenized with the same interpolation-aware logic as normal metacmd arguments. This file should be updated so the lexer/parser can distinguish plain tokens, single-quoted strings, double-quoted strings, backtick command bodies, and variable references with enough context to apply the correct expansion rules later.

Affected files: parse.go

This is the core parser change. The metacmd scanner/parser needs to stop treating quoted text and `:` substitutions as mostly literal text and instead parse them with psql-compatible rules. The issue examples show three failures that all point here: `:{?name}` is not recognized at all, single-quoted strings used by `\set` are not decoded with psql escape rules, and backtick bodies are not being tokenized with the same interpolation-aware logic as normal metacmd arguments. This file should be updated so the lexer/parser can distinguish plain tokens, single-quoted strings, double-quoted strings, backtick command bodies, and variable references with enough context to apply the correct expansion rules later.

Affected files: parse.go

Signed-off-by: Ngô Quang Sinh <omaken567@gmail.com>
@kenshaw
Copy link
Copy Markdown
Member

kenshaw commented Mar 30, 2026

@BapTruongSinh I actually was aware of the issue with the variables, and have a half-implementation that I didn't have time to complete from over a year ago. I'll review and merge this if it's clean. Appreciate the contribution, thanks.

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

Successfully merging this pull request may close these issues.

2 participants