#!/usr/bin/env perl # make_grammar.pl use strict; use warnings; use Parse::RecDescent qw( ); my $grammar = <<'__END_OF_GRAMMAR__'; { use strict; use warnings; } parse : list /\Z/ { $item[1] } list : '(' term(s) ')' { $item[2] } term : /[a-z]+/ | list __END_OF_GRAMMAR__ Parse::RecDescent->PreCompile($grammar, 'NestedListParser') or die("Bad Grammar\n"); #### use NestedListParser qw( ); sub load { my $self = shift; my $qfn = shift; open(my $fh, '<', $qfn) or croak("Couldn't open file \"$qfn\": $!"); my $file; { local $/; $file = <$fh>; } my $parser = NestedListParser->new(); $self->{list} = $parser->parse($file) or die("Bad data\n"); }