[LQP Meta] Add formatted and non-formatted literal tokens - #228
Merged
Conversation
nystrom
marked this pull request as ready for review
March 9, 2026 17:11
staworko
approved these changes
Mar 16, 2026
| end | ||
|
|
||
| @testitem "Custom formatter - int32" setup=[PrettySetup] begin | ||
| struct Int32Formatter <: ConstantFormatter end |
Contributor
There was a problem hiding this comment.
That's a nice solution. 🎉
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In the Julia pretty-printer, we want to obscure some constants (e.g., by hashing them so they don't appear in logs) but not all. For instance, literal values inside formula fragments should go through a
ConstantFormatterhook, while values in config relations and attributes should be printed as-is.This PR introduces formatted literal tokens (
FORMATTED_INT,FORMATTED_STRING, etc.) into the grammar as aliases of their unformatted counterparts (INT,STRING, etc.):format_*_formattedbuiltins, which in the Julia SDK go through theConstantFormatterhook on thePrettyPrinter(allowing RAICode to hash/obscure values). In Go and Python, the formatted variants behave identically to the base formatters.valuenonterminal (used in formulaterm) now uses formatted tokens. A newraw_valuenonterminal uses plain tokens and is used inconfig_key_value,attribute, andspecialized_valuewhere constants should not be obscured.date/datetimeare similarly split into formatted andraw_*variants.Changes
grammar.y: Add%token_aliasdeclarations, splitvalue/raw_valueanddate/datetime/raw_date/raw_datetime, remove theconstantnonterminal (was just an alias forvalue)grammar.py,yacc_parser.py: Support%token_aliasin grammar representation and parserpretty_gen.py: Table-driven terminal formatting with formatted variant entriescodegen_templates.py,target_builtins.py: Registerformat_*_formattedbuiltins for all three target languagespretty_printer.jl.template: Addformat_int32/format_float32to theConstantFormatterprotocol; formatted builtins dispatch throughpp.constant_formatter, unformatted builtins useDEFAULT_CONSTANT_FORMATTERdirectly