From 2cebdc6ca3e80afade4c04e309975459d1ad88dd Mon Sep 17 00:00:00 2001
From: Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz>
Date: Sun, 14 Aug 2022 21:30:37 +0200
Subject: [PATCH] ConfigParser: Lines and Tokens

---
 ConfigParser.cs | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/ConfigParser.cs b/ConfigParser.cs
index 7a49b3b..65f453a 100644
--- a/ConfigParser.cs
+++ b/ConfigParser.cs
@@ -311,8 +311,35 @@ abstract class ConfigValue
 	{
 		return new ConfigParser(AsString(), Root.FileName, Line);
 	}
+	public ConfigValue[] Lines()
+	{
+		int lineOfset = 0;
+		return AsString().Split("\n").Select(x => new ConfigValueSegment(this, x, lineOfset++)).Where(x => x.Value?.Trim() != "").ToArray();
+	}
+	public ConfigValue[] Tokens()
+	{
+		return (
+				from l in Lines()
+				from v in l.AsString().Split(new char[]{' ', '\t'})
+				where v.Trim() != ""
+				select new ConfigValueSegment(l, v)
+		).ToArray();
+	}
 	public static implicit operator string(ConfigValue v) => v.AsString();
 }
+class ConfigValueSegment: ConfigValue
+{
+	ConfigValue parent;
+	internal ConfigValueSegment(ConfigValue _parent, string _Value, int lineOfset=0): base(_parent.Root)
+	{
+		parent = _parent;
+		Line = parent.Line + lineOfset;
+		Value = _Value;
+	}
+	override public string FullName{
+		get => parent.FullName;
+	}
+}
 class ConfigOption: ConfigValue
 {
 	public ConfigSection Section {get; init;}
-- 
GitLab