File: re_capture_return.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 (31 lines) | stat: -rwxr-xr-x 568 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;

use Test::More 'no_plan';
use Parse::RecDescent;

my $parser = Parse::RecDescent->new(<<'EOG');

{
  my %ret;
}

CONFIG : KV_PAIR(s) { return \%ret }

KV_PAIR : WORD /\s*=\s*/ MAYBE_QUOTED_WORD { $ret{$item[1]} = $item[3] }

MAYBE_QUOTED_WORD:  WORD
                   | /'([^']+)'/  { $return = $1 }
                   | /"([^"]+)"/  { $return = $1 }

WORD : /\w+/

EOG

ok($parser, 'Created parser');

my $str = q|a=1 b="2" c ="33" d= '12'|;

my $result = $parser->CONFIG($str);

is_deeply($result, { a => 1, b => 2, c => 33, d => 12 } );