File: skip_dynamic.t

package info (click to toggle)
libparse-recdescent-perl 1.967015%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 764 kB
  • sloc: perl: 6,797; makefile: 13; ansic: 9
file content (40 lines) | stat: -rwxr-xr-x 939 bytes parent folder | download | duplicates (4)
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
#! /usr/bin/perl -w
use strict;
use warnings;
use Parse::RecDescent;
use Test::More tests => 3;

my $grammar = <<'END_OF_GRAMMAR';
    foo_with_dynamic_skip:
                     <skip: $::skip_pattern>
                     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

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

{
   local $::skip_pattern = qr/XXXXX/;
   my $outskip = $parser->foo_with_dynamic_skip($text);
   ok(!defined $outskip, 'foo()');
}

{
   no warnings 'once';
   local $::skip_pattern = qr/(?mxs: \s+ |\# .*?$)*/;
   my $outskip = $parser->foo_with_dynamic_skip($text);
   ok($outskip, 'foo() with string $::skip');
}