my $level = 1;
my $from=pos($$input);
my $to;
while($$input =~ /\G(.*?
(?:
\#[^\n]*\n # Perl like comments
| \/\*.*?\*\/ # C like comments
| \/\/[^\n]*\n # C++ like comments
| (?<!\\)'.*?(?<!\\)' # Single-quoted strings
| (?<!\\)".*?(?<!\\)" # Double-quoted strings
| ([{}]|$) # Our match or EOF
)
)/xsgc)
{
if (defined $2)
{
if ($2 eq '}')
{
$level--;
unless($level)
{
$to = pos($$input) - 1;
last;
}
}
elsif ($2 eq '{')
{
$level++;
}
else
{
$to = length $$input;
print(2,"Unmatched { opened line $old_lineno",-1);
last;
}
}
}
$code = substr($$input,$from,$to-$from);
$lineno+= $code=~tr/\n//;
return('BRACED_CODE',[ $code, $old_lineno ]);
};
NAME
yagg::TerminalParser - An internal class for the yagg parser.