fix(parser): support simple/series/const UDF param qualifiers and T[] postfix-array decls#22
Merged
luisleo526 merged 1 commit intoJun 28, 2026
Conversation
… postfix-array decls
Two parser defects surfaced while transpiling real-world published v6 strategies:
1. UDF parameter type qualifiers were not consumed. `simple string maType`
(and `const`) were mis-parsed: only `series` was special-cased, so
`f(..., simple string m)` split into two params (`simple`, `m`) and the
generated C++ failed to compile (no matching function). Now any leading
`series`/`simple`/`const` qualifier is consumed before the type — this also
fixes UDT-typed series/simple params.
2. Postfix-array declarations (`float[] x = ...`, `var int[] xs = ...`) were
silently dropped. `_parse_type_hint_string` didn't consume the trailing
`[]`, so the following name failed to parse and the whole declaration was
discarded by error recovery, leaving the variable undeclared downstream
("Unknown variable"). The `[]` postfix now lowers to `array<T>`, and the
statement dispatcher recognizes the bare `T[] name =` form.
Adds 5 regression tests.
Verified no corpus regression: re-transpiling all 258 corpus probes with vs
without this change yields byte-identical generated.cpp (0 drift); a full local
engine build + run of the 246-probe sweep reproduces the canonical
245-excellent / 1-anomaly parity.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
Two parser defects surface when transpiling real-world published PineScript v6 strategies (found while backtesting scraped TradingView strategies through the engine):
UDF parameter type qualifiers dropped. Only
serieswas special-cased in_parse_func_def, sosimple/constfell through.ma(float s, int l, simple string m) =>parsed as 4 params (s,l,simple,m), and the generated C++ failed to compile:Postfix-array declarations silently dropped.
var float[] qp = array.from(...)/float[] x = ...produced noVarDeclat all —_parse_type_hint_stringleft the trailing[]unconsumed, the name failed to parse, and statement-level error recovery discarded the whole line. Downstream every reference becameUnknown variable 'qp'. (Untypedvar qp = array.from(...)worked, masking it.)Fix
series/simple/constqualifier before the (optional) type in UDF params. Also fixes UDT-typedseries/simpleparams.T[]postfix asarray<T>in_parse_type_hint_string, and recognize the bareT[] name =form in the statement dispatcher.Tests
5 regression tests in
tests/test_parser.py(param qualifiers single-param; postfix-arrayvar/bare register aVarDecl; end-to-end transpile). Full suite green (pre-existingtest_matrix_*_compilesenv failures unaffected).Regression verification (transpiler + engine)
generated.cppfor every probe (0 drift)..so, ran the sweep →ok=246 fail=0,verify_corpus --all= 245 excellent / 1 anomaly (unchanged canonical baseline); regeneratedengine_trades.csvbyte-identical to committed.🤖 Generated with Claude Code