added generic parser
author"Tomas Zeman <tzeman@volny.cz>"
Fri, 06 Nov 2009 13:59:00 +0100
changeset 9 837e0e828d06
parent 8 7d6516dd0b3e
child 10 91148603fd70
added generic parser
parser
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/parser	Fri Nov 06 13:59:00 2009 +0100
@@ -0,0 +1,43 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Parse::RecDescent;
+use Data::Dumper;
+
+my $grammar_file = shift;
+unless (defined $grammar_file) {
+	print "Usage: $0 grammar_file\n";
+	exit 1;
+}
+
+unless (-f $grammar_file) {
+	die "Grammar file $grammar_file does not exit";
+}
+
+my $grammar = '';
+{
+	open G, $grammar_file;
+	local $/;
+	$grammar = <G>;
+	close G;
+}
+
+# Enable warnings within the Parse::RecDescent module.
+$::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error
+$::RD_WARN   = 1; # Enable warnings. This will warn on unused rules &c.
+$::RD_HINT   = 1; # Give out hints to help fix problems.
+
+my $parser = Parse::RecDescent->new($grammar);
+
+my $content = '';
+{
+	local $/;
+	$content = <>;
+}
+
+$::res = {};
+my $p_res = $parser->file($content);
+
+#print Dumper $p_res;
+
+print Dumper $::res;