Files
Print_server/Inspectron.Epson.Templates/Language/Nodes/ForeachNode.cs
2026-01-21 15:56:37 +01:00

22 lines
724 B
C#

namespace Inspectron.Epson.Templates.Language.Nodes;
public record ForeachNode(
string ItemVariable,
string CollectionPath,
List<ITemplateNode> Body,
SourcePosition Position) : ITemplateNode
{
public IReadOnlyList<ITemplateNode> Children => Body;
public static (string ItemVariable, string CollectionPath) ParseForeach(string value)
{
// Expected format: "item in collection" or "item in collection.path"
var parts = value.Split(" in ", 2, StringSplitOptions.TrimEntries);
if (parts.Length != 2)
{
throw new FormatException($"Invalid foreach syntax: '{value}'. Expected 'item in collection'.");
}
return (parts[0], parts[1]);
}
}