File: leftop_cap.t

package info (click to toggle)
libparse-recdescent-perl 1.965001%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 672 kB
  • ctags: 766
  • sloc: perl: 6,448; sh: 48; makefile: 10; ansic: 9
file content (22 lines) | stat: -rw-r--r-- 676 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use Parse::RecDescent;

my $grammar = q {
    nolcap : <leftop: id /\+|-/   id>
    lcap   : <leftop: id /(\+|-)/ id>

    norcap : <rightop: id /\+|-/   id>
    rcap   : <rightop: id /(\+|-)/ id>

    id : /[a-zA-Z][a-zA-Z_0-9\.]*/
};

my $parser = new Parse::RecDescent($grammar) or die "Bad Grammar";

use Test::More tests=>4;

my $text = "a + b - c + d";

is_deeply $parser->nolcap($text), [qw<a b c d>]       => 'Capturing leftop';
is_deeply $parser->lcap($text),   [qw<a + b - c + d>] => 'Noncapturing leftop';
is_deeply $parser->norcap($text), [qw<a b c d>]       => 'Capturing rightop';
is_deeply $parser->rcap($text),   [qw<a + b - c + d>] => 'Noncapturing rightop';