| author | "Tomas Zeman <tzeman@volny.cz>" |
| Fri, 27 Nov 2009 23:12:41 +0100 | |
| changeset 17 | d39ff14a8964 |
| parent 9 | 837e0e828d06 |
| child 18 | 8d541766cd1f |
| permissions | -rw-r--r-- |
| 9 | 1 |
#!/usr/bin/perl -w |
2 |
||
3 |
use strict; |
|
4 |
use Parse::RecDescent; |
|
5 |
use Data::Dumper; |
|
|
17
d39ff14a8964
parser: store result via Storable if requested
"Tomas Zeman <tzeman@volny.cz>"
parents:
9
diff
changeset
|
6 |
use Storable; |
| 9 | 7 |
|
8 |
my $grammar_file = shift; |
|
|
17
d39ff14a8964
parser: store result via Storable if requested
"Tomas Zeman <tzeman@volny.cz>"
parents:
9
diff
changeset
|
9 |
my $storable = shift; # optional |
| 9 | 10 |
unless (defined $grammar_file) {
|
11 |
print "Usage: $0 grammar_file\n"; |
|
12 |
exit 1; |
|
13 |
} |
|
14 |
||
15 |
unless (-f $grammar_file) {
|
|
16 |
die "Grammar file $grammar_file does not exit"; |
|
17 |
} |
|
18 |
||
19 |
my $grammar = ''; |
|
20 |
{
|
|
21 |
open G, $grammar_file; |
|
22 |
local $/; |
|
23 |
$grammar = <G>; |
|
24 |
close G; |
|
25 |
} |
|
26 |
||
27 |
# Enable warnings within the Parse::RecDescent module. |
|
28 |
$::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error |
|
29 |
$::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c. |
|
30 |
$::RD_HINT = 1; # Give out hints to help fix problems. |
|
31 |
||
32 |
my $parser = Parse::RecDescent->new($grammar); |
|
33 |
||
34 |
my $content = ''; |
|
35 |
{
|
|
36 |
local $/; |
|
37 |
$content = <>; |
|
38 |
} |
|
39 |
||
40 |
$::res = {};
|
|
41 |
my $p_res = $parser->file($content); |
|
|
17
d39ff14a8964
parser: store result via Storable if requested
"Tomas Zeman <tzeman@volny.cz>"
parents:
9
diff
changeset
|
42 |
store($::res, $storable) if (defined $storable && length($storable) > 0); |
| 9 | 43 |
print Dumper $::res; |