Skip to content

Instantly share code, notes, and snippets.

@cognominal
Last active March 25, 2021 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cognominal/5846277 to your computer and use it in GitHub Desktop.
Save cognominal/5846277 to your computer and use it in GitHub Desktop.
strange behavior of a grammar test in the Perl 6 shell. [see the comments. The problem is not what I originally described]The first two results are expected but not the third and the fourth that should match as well.Expected results : the b rules matches except at the second iteration. Because of the procedural alternation with the rule bdesigne…
> for '', 'a', 'aa', 'aaa' -> $t { say $! unless try say ( grammar { token TOP { <a> || <b> } ; token a { '[' ~ ']' a }; token b { "[$t]" } }).parse: "[$t]" }
「[]」
b => 「[]」
「[a]」
a => 「[a]」
Unable to parse expression in a; couldn't find final ']'
in any FAILGOAL at src/stage2/QRegex.nqp:1037
in method parse at src/gen/CORE.setting:10695
in method reify at src/gen/CORE.setting:6010
in method reify at src/gen/CORE.setting:5905
in method gimme at src/gen/CORE.setting:6333
Unable to parse expression in a; couldn't find final ']'
in any FAILGOAL at src/stage2/QRegex.nqp:1037
in method parse at src/gen/CORE.setting:10695
in method reify at src/gen/CORE.setting:6010
in method reify at src/gen/CORE.setting:5905
in method gimme at src/gen/CORE.setting:6333
>
grammar A {
token TOP { <a> || <b> } ;
token a { '[' ~ ']' a };
token b { { say $*t.perl } "[$*t]" }
};
for '', 'a', 'aa', 'aaa' {
say "+$_";
try {
say "-$_";
my $*t = "[$_]";
$/ = A.parse: $*t;
say $/.perl;
}
}
@xlat
Copy link

xlat commented Jun 23, 2013

I think the first result must be rejected if 'the ~ construct adds a "fail the match" component'

@cognominal
Copy link
Author

Indeed I missed the pmichaud comment about "fail the match" for the ~ construct when it fails. I can't give the link beause irc log is down.

@cognominal
Copy link
Author

I don't see anything about "fail the whole match" for the tilda operator in S05

@xlat
Copy link

xlat commented Jun 23, 2013

the ~ construct adds a "fail the match" component source: http://colabti.org/irclogger/irclogger_log/perl6?date=2013-06-23#l1118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment