I tried to implement a Marpa::R2 solution:
#!/usr/bin/perl use warnings; use strict; use Marpa::R2; use Data::Dumper; my $input = do { local $/; <DATA> }; my $grammar = << '__GRAMMAR__'; lexeme default = latm => 1 :start ::= List :default ::= action => ::first List ::= Hash+ action => list Hash ::= String '{' Pairs '}' action => hash Pairs ::= Pair+ action => list Pair ::= String Value ';' action => pair | Hash Value ::= Simple | Bracketed Bracketed ::= '[' String ']' action => second Simple ::= String String ~ [-a-zA-Z_0-9]+ whitespace ~ [\s] + :discard ~ whitespace __GRAMMAR__ sub hash { +{ $_[1] => $_[3] } } sub pair { +{ $_[1] => $_[2] } } sub second { [ @_[ 2 .. $#_-1 ] ] } sub list { shift; \@_ } my $parser = 'Marpa::R2::Scanless::G'->new({ source => \$grammar }); print Dumper $parser->parse(\$input, 'main', { trace_terminals => 1 }) +; __DATA__ bob { ed { larry { ...

Does the output satisfy you?

[ { 'bob' => [ { 'ed' => [ { 'larry' => [ { 'rule5' => [ { ' +option' => [ + { + 'disable-server-response-inspection' => 'no' + } + ] }, { ' +tag' => [ + 'some_tag' + ] }, { ' +from' => [ + 'prod-L3' + ] }, { ' +to' => [ + 'corp-L3' + ] }, { ' +source' => [ + 'any' + ] }, { ' +destination' => [ + 'any' + ] }, { ' +source-user' => [ + 'any' + ] }, { ' +category' => [ + 'any' + ] }, { ' +application' => [ + 'any' + ] }, { ' +service' => [ + 'any' + ] }, { ' +hip-profiles' => [ + 'any' + ] }, { ' +log-start' => 'no' }, { ' +log-end' => 'yes' }, { ' +negate-source' => 'no' }, { ' +negate-destination' => 'no' }, { ' +action' => 'allow' }, { ' +log-setting' => 'orion_log' } ] }, { 'rule6' => [ { ' +option' => [ + { + 'disable-server-response-inspection' => 'no' + } + ] }, { ' +tag' => [ + 'some_tag' + ] }, { ' +from' => [ + 'prod-L3' + ] }, { ' +to' => [ + 'corp-L3' + ] }, { ' +source' => [ + 'any' + ] }, { ' +destination' => [ + 'any' + ] }, { ' +source-user' => [ + 'any' + ] }, { ' +category' => [ + 'any' + ] }, { ' +application' => [ + 'any' + ] }, { ' +service' => [ + 'any' + ] }, { ' +hip-profiles' => [ + 'any' + ] }, { ' +log-start' => 'no' }, { ' +log-end' => 'yes' }, { ' +negate-source' => 'no' }, { ' +negate-destination' => 'no' }, { ' +action' => 'allow' }, { ' +log-setting' => 'orion_log' } ] } ] } ] } ] } ]
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

In reply to Re: Parsing a config file with braces and nested braces by choroba
in thread Parsing a config file with braces and nested braces by IamtheGorf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.