~ubuntu-branches/ubuntu/vivid/horae/vivid

« back to all changes in this revision

Viewing changes to 0CPAN/Parse-RecDescent-1.94/demo/demo_matchrule.pl

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2006-12-26 11:54:29 UTC
  • Revision ID: james.westby@ubuntu.com-20061226115429-kjuhf6h9w6bohlwj
Tags: upstream-063
ImportĀ upstreamĀ versionĀ 063

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/local/bin/perl -sw
 
2
 
 
3
use vars qw($animal);
 
4
use Parse::RecDescent;
 
5
 
 
6
$grammar = q {
 
7
                    object:      thing[article=>'a'](s)
 
8
                          |      thing[article=>'the'](s)
 
9
 
 
10
                    thing:       <matchrule:$arg{article}>
 
11
                                 <matchrule:${\scalar reverse $::animal}>
 
12
 
 
13
                    a:          'a'
 
14
                    the:        'the'
 
15
 
 
16
                    cat:        'cat' { print "meow\n"; $::animal = 'god' }
 
17
                    dog:        'dog' { print "woof\n" }
 
18
             };
 
19
 
 
20
unless( $parser = new Parse::RecDescent( $grammar ))
 
21
{
 
22
    die "bad grammar; bailing\n";
 
23
}
 
24
 
 
25
$/ = "";
 
26
while (defined ($input = <DATA>))
 
27
{
 
28
        $::animal = reverse 'cat';
 
29
 
 
30
        print STDERR "parsing...\n";
 
31
        unless( defined $parser->object( $input ))
 
32
        {
 
33
            die "error in input; bailing\n";
 
34
        }
 
35
        print STDERR "...parsed\n";
 
36
}
 
37
 
 
38
__DATA__
 
39
a cat
 
40
a cat
 
41
a cat
 
42
a dog
 
43
 
 
44
the cat
 
45
the dog
 
46
the dog
 
47
the dog
 
48
the dog
 
49
a dog