File: skip.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,255 bytes parent folder | download | duplicates (3)
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 strict;
use warnings;
use Parse::RecDescent;
use Test::More tests => 8;

my $grammar = <<'END_OF_GRAMMAR';
    foo:             item(s) eotext { $return = $item[1] }
    foo_with_skip:   <skip: qr/(?mxs: \s+ |\# .*?$)*/>
                     item(s) eotext { $return = $item[1] }
    item:            name value { [ @item[1,2] ] }
    name:            'whatever' | 'another'
    value:           /\S+/
    eotext:          /\s*\z/
END_OF_GRAMMAR

my $text = <<'END_OF_TEXT';
whatever value

# some spaces, newlines and a comment too!

another value

END_OF_TEXT

# Test setting the initial skip via the <skip:> global directive
RunTests(q{
<skip:'(?mxs: \s+ |\# .*?$)*'>
});

# Test setting the initial skip via $Parse::RecDescent::skip global
local $Parse::RecDescent::skip = qr/(?mxs: \s+ |\# .*?$)*/;
RunTests();

sub RunTests {
    my $prefix = shift || '';

    my $parser = Parse::RecDescent->new($prefix . $grammar);
    ok($parser, 'got a parser');

    my $inskip = $parser->foo_with_skip($text);
    ok($inskip, 'foo_with_skip()');

  {
      my $outskip = $parser->foo($text);
      ok($outskip, 'foo() with regex $P::RD::skip');
  }

  {
      my $outskip = $parser->foo($text);
      ok($outskip, 'foo() with string $P::RD::skip');
  }
}