Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 37 lines (22 sloc) 0.824 kb
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
#! nqp

# test protoregexes in grammars

plan(7);

grammar ABC {

    token TOP { <symbols> .* }

    proto token symbols { <...> }

    token symbols:sym<abc> { <sym> }
    token symbols:sym<a> { <sym> }
    token symbols:sym<bang> { $<sym>=['!'] }
    token symbols:sym<===> { <sym> }
}


my $/ := ABC.parse('abcdef');
ok( ?$/ , 'successfully matched grammar' );
ok( $/ eq 'abcdef', 'successful string match' );
ok( $<symbols> eq 'abc', 'successful protoregex match');
ok( $<symbols><sym> eq 'abc', 'correct proto candidate match' );

$/ := ABC.parse('adef');
ok( ?$/ , 'successfully matched grammar' );

$/ := ABC.parse('xxx');
ok( !$/ , 'successfully failed protoregex match' );

$/ := ABC.parse('xxx', :rule<symbols>);
ok( !$/ , 'successfully failed protoregex match' );



Something went wrong with that request. Please try again.