File: leftop_cap.t

package info (click to toggle)
libparse-recdescent-perl 1.967013%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 772 kB
  • ctags: 780
  • sloc: perl: 6,796; sh: 54; makefile: 13; ansic: 9
file content (52 lines) | stat: -rwxr-xr-x 1,922 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use Parse::RecDescent;

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

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

    nolcappos: start <leftop: id /\+|-/   id> end
	        { # force @itempos to be included
              &::make_itempos_text(\@item, \@itempos); }
    lcappos: start <leftop: id /(\+|-)/   id> end
	        { &::make_itempos_text(\@item, \@itempos); }
    norcappos: start <rightop: id /\+|-/   id> end
	        { &::make_itempos_text(\@item, \@itempos); }
    rcappos: start <rightop: id /(\+|-)/   id> end
	        { &::make_itempos_text(\@item, \@itempos); }

    start: /start/i
    end: /end/i

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

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

use Test::More tests=>8;
require 't/util.pl';

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

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

my $postext = "START a +
 bb -
ccccccccc +
  d
END";
my $message = '';
my $expected = '
START      offset.from=  0 offset.to=  4 line.from=  1 line.to=  1 column.from=  1 column.to=  5
_REF_      offset.from=  6 offset.to= 30 line.from=  1 line.to=  4 column.from=  7 column.to=  3
END        offset.from= 32 offset.to= 34 line.from=  5 line.to=  5 column.from=  1 column.to=  3
';
is $parser->nolcappos($postext), $expected => "Position capturing leftop$message";
is $parser->lcappos($postext),   $expected => "Position noncapturing leftop$message";
is $parser->norcappos($postext), $expected => "Position capturing rightop$message";
is $parser->rcappos($postext),   $expected => "Position noncapturing rightop$message";