Pipe Parameter is now a Tuple

This commit is contained in:
Michael Schimmel
2026-01-05 00:13:51 +01:00
parent 242ec9a56e
commit 264314cd93
15 changed files with 322 additions and 1244 deletions
+7 -45
View File
@@ -532,59 +532,21 @@ begin
begin
if SameText(head.Token.Text, 'pipe') then
begin
// (pipe [stream1 [:Key1 :Key2] stream2 [:Key3]] (fn ...))
// (pipe [[stream1 [:Key1 :Key2]] [stream2 [:Key3]]] (fn ...))
if Length(tailNodes) <> 2 then
Error('Syntax Error: ''pipe'' requires [inputs] vector and (fn) transformation.');
if tailNodes[0].Kind <> akTuple then
Error('Syntax Error: ''pipe'' first argument must be a vector [...].');
// Access tuple elements safely
var inputsTuple := tailNodes[0].AsTuple;
if (inputsTuple.Count mod 2) <> 0 then
Error('Syntax Error: Pipe inputs must be pairs of Identifier and Selector Vector (e.g. [btc [:Close]]).');
// NOTE: We do NOT validate inner tuples or keywords here anymore.
// It is just a Tuple of Tuples structurally.
// The TypeChecker will ensure valid structure (Series + Keywords).
var pipeInputs := TList<IPipeInputNode>.Create;
try
var k := 0;
while k < inputsTuple.Count do
begin
var streamNode := inputsTuple.Items[k];
if streamNode.Kind <> akIdentifier then
Error('Syntax Error: Pipe input stream must be an identifier.');
if tailNodes[1].Kind <> akLambdaExpression then
Error('Syntax Error: Pipe transformation must be a lambda (fn).');
var selNode := inputsTuple.Items[k + 1];
var streamId := streamNode.AsIdentifier;
var selKeywords: TArray<IKeywordNode>;
if selNode.Kind <> akTuple then
Error('Syntax Error: Pipe selector must be a vector of keywords (e.g. [:Close :High]).');
var selTuple := selNode.AsTuple;
if selTuple.Count = 0 then
Error('Syntax Error: Selector list cannot be empty.');
SetLength(selKeywords, selTuple.Count);
for var m := 0 to selTuple.Count - 1 do
begin
if selTuple.Items[m].Kind <> akKeyword then
Error('Syntax Error: Selector vector must contain only keywords.');
selKeywords[m] := selTuple.Items[m].AsKeyword;
end;
var selectorList := TAst.PipeSelectorList(selKeywords, selNode.Identity.Location);
pipeInputs.Add(TAst.PipeInput(streamId, selectorList, streamId.Identity.Location));
Inc(k, 2);
end;
if tailNodes[1].Kind <> akLambdaExpression then
Error('Syntax Error: Pipe transformation must be a lambda (fn).');
Result := TAst.Pipe(pipeInputs.ToArray, tailNodes[1].AsLambdaExpression, startLoc);
finally
pipeInputs.Free;
end;
Result := TAst.Pipe(tailNodes[0].AsTuple, tailNodes[1].AsLambdaExpression, startLoc);
end
else if SameText(head.Token.Text, 'fn') then
begin