|
Revision 21646, 1.6 kB
(checked in by lwall, 4 months ago)
|
|
[STD] renamed main package to STD
fixed package name conflicts
fixed tests that used function call syntax for quotes
various other bugs
now parses all but one of the t/spec tests (needs macros)
|
-
Property svn:mime-type set to
text/plain; charset=UTF-8
-
Property svn:eol-style set to
native
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/usr/local/bin/perl |
|---|
| 2 | # A script to make running STD.pmc easier, |
|---|
| 3 | # by providing it input, and isolating it's Match yaml output. |
|---|
| 4 | use strict; |
|---|
| 5 | use warnings; |
|---|
| 6 | |
|---|
| 7 | sub print_usage_and_exit { |
|---|
| 8 | print STDERR <<"END"; exit(2); |
|---|
| 9 | $0 [-fo] GRAMMAR_RULE [ INPUT_FILE | -e INPUT ] |
|---|
| 10 | |
|---|
| 11 | Examples: |
|---|
| 12 | $0 noun -e 42 |
|---|
| 13 | END |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | my $fo = ''; |
|---|
| 17 | $fo = shift if $ARGV[0] eq '-fo'; |
|---|
| 18 | |
|---|
| 19 | sub main { |
|---|
| 20 | print_usage_and_exit if @ARGV < 2 || $ARGV[0] eq '--help'; |
|---|
| 21 | my $rule = shift(@ARGV); |
|---|
| 22 | print_usage_and_exit if $rule !~ /^\w+$/; |
|---|
| 23 | my $input; |
|---|
| 24 | if($ARGV[0] eq '-e') { |
|---|
| 25 | shift(@ARGV); |
|---|
| 26 | print_usage_and_exit if not @ARGV; |
|---|
| 27 | $input = shift(@ARGV); |
|---|
| 28 | #$input = 'qq{'.quotemeta($input).'}'; |
|---|
| 29 | } |
|---|
| 30 | else { |
|---|
| 31 | my $fn = shift(@ARGV); |
|---|
| 32 | print_usage_and_exit if !-f $fn; |
|---|
| 33 | $input = "`cat $fn`"; |
|---|
| 34 | } |
|---|
| 35 | if(-e 'STD.pm' and -e 'gimme5') { # We're in the right place. |
|---|
| 36 | # pretend we're 'make' |
|---|
| 37 | if(!-e 'STD.pmc' or |
|---|
| 38 | -M 'STD.pmc' > -M 'STD.pm' or |
|---|
| 39 | -M 'STD.pmc' > -M 'gimme5') { |
|---|
| 40 | system("$^X gimme5 $fo STD.pm >STD.pmc"); |
|---|
| 41 | system("rm -rf lex"); |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | #my $cmd = qq/perl -w -I . -MSTD5 -e 'print STD::Dump(STD->new(orig=>$input)->${rule}(["$rule"]));'/; |
|---|
| 45 | #warn "# ",$cmd,"\n"; |
|---|
| 46 | #system "$cmd 2>try5.err"; |
|---|
| 47 | unshift(@INC,'.'); |
|---|
| 48 | require "STD.pmc"; |
|---|
| 49 | my $err = "try5.err"; |
|---|
| 50 | my $perl = STD->new($input); |
|---|
| 51 | if(!$perl->can($rule)) { die "\nERROR: Unknown rule: $rule\n"; } |
|---|
| 52 | open(STDERR,">$err") or die; |
|---|
| 53 | my $result = eval { $perl->${rule}(); }; |
|---|
| 54 | if($result) { |
|---|
| 55 | print $result->dump(); |
|---|
| 56 | # print STD::Dump($result); |
|---|
| 57 | } else { |
|---|
| 58 | print "Parse failed. See $err.\n"; |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | main; |
|---|
| 62 | |
|---|
| 63 | __END__ |
|---|