Repository navigation
fix: lint SQL macro bodies as compiled and pass SQL macro expansions to Python macros intact - #1236
Merged
Merged
Conversation
…to Python macros intact Linting a SQL macro file read a parameter followed by words and a parenthesis, such as `@value IS NULL OR TRIM(@value) = ''`, as an unprefixed macro call (L005), and a body opening with two parentheses reached the native parser as a statement it rejected (rules-unevaluated). - One rule decides an unprefixed call everywhere: `@name(` with the parenthesis right after the name. The Python macro call scanner, the SQL macro lexer, parameter references and the bare-call check share it, so `@name IS NULL OR f(x)` in model SQL is no longer P014 either. `@const`, `@enum` and `@param` stay declarations with or without a space before their parenthesis. - Lint replaces a SQL macro body's parameters by sentinels with the compiler's own parameter scan, lints an expression body as the `SELECT` the compiler parses it as, and a CTE-list body with its ceremonial `SELECT 1` and its CTEs counted as used by the caller. Findings in the generated frame are dropped. - A SQL macro expansion passed to a Python macro is spliced as a string literal with `"` written as `\x22`, which the call scanner and the argument parser read the same way, so quotes, backslashes, line breaks and comments reach the macro unchanged. - An expansion ending in a line comment gets a line break only when text would follow it on the same line, so the caller's text stays code and calls already last on their line compile unchanged. - A macro call the scan cannot read is a MacroArgumentError naming the call, file, line and column instead of a location-less P001. - Rules on a caller skip comments a SQL macro expansion generated; the macro file is where they are judged, and compiled SQL keeps them. Comments from Python macro output are judged as before.
kvlonge
enabled auto-merge (squash)
October 23, 2026 13:09
…mment blanking adds no peak memory
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.
Why
With Rules on, SQL macro files that compile failed to lint: a parameter followed by words and
((@value IS NULL OR TRIM(@value) = '') was read as an unprefixed call (L005), and a body opening with((was parsed as a statement the native parser rejects (rules-unevaluated). A SQL macro call passed to a Python macro failed when its expansion held", with no location; a body ending in a--comment swallowed the caller's text; and SQBRSQL033 judged comments from macro expansions in the caller.Changes
@name(with no gap, used by the Python call scanner, the SQL macro lexer, parameter references and the bare-call check.@name IS NULL OR f(x)in model SQL is no longer P014;@const/@enum/@paramstay declarations with or without a space before(.SELECT <body>and CTE-list bodies with a ceremonialSELECT 1, and drops findings in that generated frame."as\x22, so the scanner and argument parser agree.Verification
'''', backslashes, newlines, dict and list values, comments), lint frames and comments.make test,make check-ci,make compiler-differential(no golden changes). One Python-oracle golden updated for seven located scan errors.