templates support
This commit is contained in:
21
Inspectron.Epson.Templates/Language/Nodes/ForeachNode.cs
Normal file
21
Inspectron.Epson.Templates/Language/Nodes/ForeachNode.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user