in reply to Parsing and editing a configuration file

The main problem for me is that the

> configuration file lacks a formal syntax specification

IMHO it's too dangerous to be simply done with a fancy regex.

You need validation to catch wrong assumptions and errors in the input.

For instance it's unclear

I'd personally go for maintainability over speed then.

Like writing an iterator which returns each "VIEW" as a nested data structure.

Like this you can find and report errors and create a tidied version.

Actually it's not too difficult to define your own grammar as a DSL of subs

my $iterator = block start => qr/^VIEW \s+ (?<name>\w+)/x , stop => qr/^END_VIEW/ , hash => sub { entry "RECORD"; group "FIELD", array => sub { entries "FIELD" }; entry "INTERVAL"; } ;

group() would be a special case of block() with

start => qr/^ \s* FIELD \s+ \( \s* $/x , stop => qr/^ \s* \) \s* $/x,

Inside those DSL subs I'd use an nextline() iterator, which does single readlines and handles empty lines and comments and returns undef if the stop condition of the upper level is met.

And you might consider using a q_entry() sub for automatic unquoting of "quoted" entries. hence you are free to dynamically adapt to unknown conditions.

NB This is untested code, I started to implement it but don't wanna spend my free Sunday on it, sorry ;-)

HTH! :)

Update

if you wanna go this way, I'll share more insights.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^2: Parsing and editing a configuration file
by shmem (Chancellor) on Jun 23, 2019 at 17:40 UTC
    my free Sunday

    That sounds really bad and doesn't forebode well. If an inherent property of a substantive is stripped from it for attachment as adjective, the property is prone to change or to go away.

    May your Sundays stay free.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'