Skip to content

fix(parser): support simple/series/const UDF param qualifiers and T[] postfix-array decls#22

Merged
luisleo526 merged 1 commit into
mainfrom
fix/udf-param-qualifiers-and-postfix-array-decls
Jun 28, 2026
Merged

fix(parser): support simple/series/const UDF param qualifiers and T[] postfix-array decls#22
luisleo526 merged 1 commit into
mainfrom
fix/udf-param-qualifiers-and-postfix-array-decls

Conversation

@luisleo526

Copy link
Copy Markdown
Contributor

Problem

Two parser defects surface when transpiling real-world published PineScript v6 strategies (found while backtesting scraped TradingView strategies through the engine):

  1. UDF parameter type qualifiers dropped. Only series was special-cased in _parse_func_def, so simple/const fell through. ma(float s, int l, simple string m) => parsed as 4 params (s, l, simple, m), and the generated C++ failed to compile:

    error: no matching function for call to 'ma_cs0(double&, int&, std::string&)'
    note: candidate: 'double ma_cs0(double, int, std::string, double)'
    
  2. Postfix-array declarations silently dropped. var float[] qp = array.from(...) / float[] x = ... produced no VarDecl at all — _parse_type_hint_string left the trailing [] unconsumed, the name failed to parse, and statement-level error recovery discarded the whole line. Downstream every reference became Unknown variable 'qp'. (Untyped var qp = array.from(...) worked, masking it.)

Fix

  • Consume any leading series / simple / const qualifier before the (optional) type in UDF params. Also fixes UDT-typed series/simple params.
  • Parse the T[] postfix as array<T> in _parse_type_hint_string, and recognize the bare T[] name = form in the statement dispatcher.

Tests

5 regression tests in tests/test_parser.py (param qualifiers single-param; postfix-array var/bare register a VarDecl; end-to-end transpile). Full suite green (pre-existing test_matrix_*_compiles env failures unaffected).

Regression verification (transpiler + engine)

  • Isolation diff: re-transpiled all 258 corpus probes with this change vs. with it stashed → byte-identical generated.cpp for every probe (0 drift).
  • Full local build + run: built runtime + 246 strategy .so, ran the sweep → ok=246 fail=0, verify_corpus --all = 245 excellent / 1 anomaly (unchanged canonical baseline); regenerated engine_trades.csv byte-identical to committed.

🤖 Generated with Claude Code

… 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>
@luisleo526 luisleo526 merged commit 8e0839b into main Jun 28, 2026
9 checks passed
@luisleo526 luisleo526 deleted the fix/udf-param-qualifiers-and-postfix-array-decls branch June 28, 2026 08:17
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.

1 participant