Skip to content

Support ${placeholder} syntax in tokenizer#2239

Open
cetra3 wants to merge 1 commit intoapache:mainfrom
pydantic:support-dollar-brace-placeholder-syntax
Open

Support ${placeholder} syntax in tokenizer#2239
cetra3 wants to merge 1 commit intoapache:mainfrom
pydantic:support-dollar-brace-placeholder-syntax

Conversation

@cetra3
Copy link

@cetra3 cetra3 commented Feb 25, 2026

Add support for dollar-brace placeholders (${name}, ${1}, etc.) in the tokenizer, storing the full ${...} string in the existing Token::Placeholder / Value::Placeholder variants with zero breaking changes. Unterminated ${name produces a clear error.

Add support for dollar-brace placeholders (`${name}`, `${1}`, etc.)
in the tokenizer, storing the full `${...}` string in the existing
`Token::Placeholder` / `Value::Placeholder` variants with zero
breaking changes. Unterminated `${name` produces a clear error.
@adriangb
Copy link

@iffyio could we bother your to take a look at this PR please? Thanks!

chars.next();

// Handle ${placeholder} syntax
if matches!(chars.peek(), Some('{')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering how this works with the self.dialect.supports_dollar_placeholder() dialects, is it possible that e.g. ${abc}$ is part of a dollar string or other potentially conflicting syntax?

Copy link
Author

@cetra3 cetra3 Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could possibly add this as another flag to dialect if that makes sense? I just thought it would be yet another flag, and if we could include it in this flag, but you're right it means that it will parse some dialects as valid even if it's not for that dialect

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if the syntax potentially conflicts we might need to ensure that it doesn't, because in this case its rather that ${abc}$ in the example will be parsed incorrectly as something that it is not (a placeholder vs a string)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is some existing behaviour, whereby $placeholder will work currently with postgres and other dialects even though supports_dollar_placeholder() is false — it falls through to the placeholder fallback when the next character after the identifier isn't $.

The ${placeholder} branch is consistent with that existing behavior, and there's no conflict with dollar-quoted strings since { is not a valid tag character

dollar-quoted string tags only allow alphanumeric characters and underscores (e.g., $tag_1$...$tag_1$), so ${abc}$ could never be interpreted as a dollar-quoted string.


chars.next();

// Handle ${placeholder} syntax
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we include a reference to the dialect that defines this syntax maybe here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tough one, as it's not defined by a specific dialect but used in some of our other integrations around parametrised queries. Namely we're using this with perses

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.

3 participants