~ubuntu-branches/ubuntu/jaunty/horae/jaunty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/local/bin/perl -sw
2
 
 
3
 
# THE OL' "EMPTY SUBCLASS IN THE DEMO" TRICK.
4
 
 
5
 
use Parse::RecDescent;
6
 
 
7
 
sub Parse::RecDescent::f
8
 
{
9
 
        print "Parse::RecDescent::f\n";
10
 
}
11
 
 
12
 
@DerParser::ISA = qw { Parse::RecDescent };
13
 
 
14
 
$grammar =
15
 
q{
16
 
        typedef : /type/ ident /has/ <commit> field(s) 'end type'
17
 
                        { $return = $item[2]; }
18
 
                | /type/ ident ( /is/ | /are/ ) ident
19
 
                        { $return = $item[2]; }
20
 
                | <error>
21
 
 
22
 
        field   : /field/ ident /is/ ident 
23
 
 
24
 
        ident   : /[A-Za-z]\w*/
25
 
                        { f(); $return = $item[1]; }
26
 
 };
27
 
 
28
 
$parse = new DerParser ( $grammar ) || die "\n";
29
 
 
30
 
$str = "
31
 
type student has
32
 
        field name is text
33
 
        field age
34
 
end type
35
 
";
36
 
 
37
 
print "> ", $parse->typedef($str) || "<failed (as expected)>", "\n";
38
 
 
39
 
 
40
 
$str = " type student has end type ";
41
 
 
42
 
print "> ", $parse->typedef($str) || "<failed (as expected)>", "\n";
43
 
 
44
 
 
45
 
$str = " type studentRec is student ";
46
 
 
47
 
print "> ", $parse->typedef($str) || "<failed (unexpectedly!)>", "\n";