Becaue I have a really redundant config-file format.. I invented a custom script-format for writing loops, for example:
[Config Object]
{Loop 3
Setting[i] = Value[i]
}
OtherSetting=X
Which will result in:
[Config Object]
Setting1 = Value1
Setting2 = Value2
Setting3 = Value3
OtherSetting = X
My first idea was to use regular expressions, like this one:
!{(.*?)}!is
That worked really well until i tried to use it with nested loops - you surely know this "oh cr... moments"
Because the following:
1: [Config Object]
2: *{*Loop 3
3: Section[i]
4: {Loop 3
5: Setting[i] = Value[i]
6: *}*
7: }
8: OtherSetting=X
Will lead the regex to cover the range between line 2 and line 6 (market them with *s)
And actually I really have no Idea how to solve this because the regex is logically doing right.
The ? Lazy-Operator is needed because without it I would have the same problem in the another direction and would not be able to write two following loops.
Little bit research made me clear that regex is not the right direction here, but I couldn't find any PHP-Solutions. So how may I performantly parse my "loop"-script in PHP getting for example an array with the loops and replacing the commands within the braces with the calculated results?