1use strict;
2use warnings;
3
4use Test::More;
5
6eval "use YAML::PP; 1" or
7    plan skip_all => 'YAML::PP required';
8
9plan tests => 1;
10
11my $grammar_text = <<'...';
12contact:
13    name_section
14    phone_section
15    address_section
16
17name_section:
18    / 'Name' <COLON> <BLANK>+ /
19    name
20    EOL
21
22name: /(<WORD>+)<BLANK>(<WORD>+)/
23
24phone_section: /Phone<COLON><BLANK>+/ <phone_number> <EOL>
25phone_number: term
26
27address_section:
28    /Address<COLON><EOL>/
29    street_line
30    city_line
31    country_line?
32
33street_line: indent street EOL
34street: /<NS><ANY>*/
35city_line: indent city EOL
36city: term
37country_line: indent country EOL
38country: term
39
40term: /(
41    <NS>            # NS is "non-space"
42    <ANY>*
43)/
44
45indent: /<BLANK>{2}/
46...
47
48my $input = <<'...';
49Name: Ingy Net
50Phone: 919-876-5432
51Address:
52  1234 Main St
53  Niceville
54  OK
55...
56
57my $want = <<'...';
58...
59
60use Pegex::Grammar;
61use Pegex::Receiver;
62use Pegex::Compiler;
63my $grammar = Pegex::Grammar->new(
64    tree => Pegex::Compiler->new->compile($grammar_text)->tree,
65);
66my $parser = Pegex::Parser->new(
67    grammar => $grammar,
68    receiver => Pegex::Receiver->new,
69    debug => 1,
70);
71my $ast1 = $parser->parse($input);
72
73pass 'parsed'; exit;
74
75my $got = YAML::PP
76    ->new(schema => ['Perl'])
77    ->dump_string($ast1);
78
79is $got, $want, 'It works';
80