On Fri Dec 12 04:52:12 2008, baest wrote:
> When using rules at least with <ws> overwritten, the rule also captures 
> whitespace. Please see attached file for example.


The problem is with trying to invoke the rule using "$str ~~ NG::TOP" --
that's not a valid syntax for invoking a rule in a grammar.

Using "$str ~~ /<NG::TOP>/" instead gets the correct match -- see
attached example.

Marking ticket as resolved, thanks!

Pm
$ cat NG.pl
grammar NG {
    rule TOP { ^ <line>+ $ };

    #whitespace rules is borrowed from pipp
    # Whitespace and comments
    token ws_char           { \h | \v }

    # end of line comment like Unix shell and C++
    token singlelinecomment { [ '#' || '//' ] \N* }

    # C-like multiline comment
    token multilinecomment  { '/*' .*?  '*/' }

    token ws_all {
          <.ws_char>
        | <.singlelinecomment>
        | <.multilinecomment>
    }

    token ws { <.ws_all>* }

    rule line {
        'default' \w+
    }
};

my $str = 'default testtesttest
// this is a comment shouldn\'t be outputted';

$str ~~ /<NG::TOP>/;

die("No match") unless ~$/;

say $<NG::TOP><line>[0];

$ ./parrot perl6.pbc NG.pl
default testtesttest
// this is a comment shouldn't be outputted

Reply via email to