Last active
February 6, 2018 21:15
-
-
Save tbrowder/db2a3a80d09e5fddaf755ecc42178953 to your computer and use it in GitHub Desktop.
grammar test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cat file: lib/Presenters.pm6 | |
unit module Presenters; | |
use Grammar::Tracer; | |
grammar Presenters::PGrammar { | |
token TOP { | |
[ | |
| <entry> | |
| <blank> | |
]+ | |
} | |
token entry { <key> <sep> <value> } | |
token key { \h* \w+ } | |
token sep { \h* ':' \h* } | |
token value { \N+ } | |
token blank { \h* \n } | |
} | |
# cat file: ./test-presenters.data | |
id: laue-d | |
name: Lauer, Denny | |
id: horn-a | |
name: Hornstein, Anne | |
id: bran-e | |
name: Branch, Eddie | |
# cat file: ./grammar-test-fail.p6 | |
#!/usr/bin/env perl6 | |
use lib <./lib>; | |
use Presenters; | |
my $pfil = "test-presenters.data"; | |
my $mp = Presenters::PGrammar.parse(slurp $pfil); | |
say "WARNING: Presenters grammar failed to match." if !$mp; | |
say $mp; | |
# executing | |
./grammar-test-fail.p6 | |
TOP | |
Cannot invoke this object (REPR: Null; VMNull) | |
in block at /usr/local/rakudo.d/share/perl6/site/sources/C0DCFF5AEFDF38901A375AE53AF39C4F12B3F6FC (Grammar::Tracer) line 43 | |
in regex TOP at /usr/local/people/tbrowde/mydata/tbrowde-home-bzr/mydomains/domains/primary-web-servers/web-sites/computertechnwf.org/public/lib/Presenters.pm6 (Presenters) line 6 | |
in block at /usr/local/rakudo.d/share/perl6/site/sources/C0DCFF5AEFDF38901A375AE53AF39C4F12B3F6FC (Grammar::Tracer) line 49 | |
in block <unit> at ./grammar-test-fail.p6 line 7 | |
# after removing "use Grammar::Tracer" the code runs to completion: | |
# executing | |
./grammar-test-fail.p6 | |
「id: laue-d | |
name: Lauer, Denny | |
id: horn-a | |
name: Hornstein, Anne | |
id: bran-e | |
name: Branch, Eddie | |
」 | |
entry => 「id: laue-d」 | |
key => 「id」 | |
sep => 「: 」 | |
value => 「laue-d」 | |
blank => 「 | |
」 | |
entry => 「name: Lauer, Denny」 | |
key => 「name」 | |
sep => 「: 」 | |
value => 「Lauer, Denny」 | |
blank => 「 | |
」 | |
entry => 「id: horn-a」 | |
key => 「id」 | |
sep => 「: 」 | |
value => 「horn-a」 | |
blank => 「 | |
」 | |
entry => 「name: Hornstein, Anne」 | |
key => 「name」 | |
sep => 「: 」 | |
value => 「Hornstein, Anne」 | |
blank => 「 | |
」 | |
entry => 「id: bran-e」 | |
key => 「id」 | |
sep => 「: 」 | |
value => 「bran-e」 | |
blank => 「 | |
」 | |
entry => 「name: Branch, Eddie」 | |
key => 「name」 | |
sep => 「: 」 | |
value => 「Branch, Eddie」 | |
blank => 「 | |
」 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment