develooper Front page | perl.perl6.users | Postings from September 2018

Grammar doesn't seem to match any token

Thread Next
From:
Mark Carter
Date:
September 23, 2018 23:07
Subject:
Grammar doesn't seem to match any token
Message ID:
b8d31174-0957-3a24-b293-7f697d3c1072@gmail.com
My grammar doesn't seem to match the 'other' rule. What's wrong with it?

grammar Weave {
         token TOP {  <el> * }
         rule el {  <lt> | <tilde> | <other>  }
         rule lt { '<'  }
         rule tilde { '~' \S+ }
         rule other { .  }
}

class Weaver {
         has Str $.outstr;

         method TOP   ($/) { make $<el> ; put("top called") ; put($<el>) }
         method el    ($/) { put($/) }
         method tilde ($/) { say 'tilde called' }
         method lt    ($/) { make '&lt;' ; put('&lt'); $!outstr ~= 'X' }
         method other ($/) { $!outstr ~= '.'; say 'other called'; 
put('.'); }

}

$input = '~i <<<YZ';
my $w = Weaver.new();
Weave.parse($input, :actions($w));
say $w.outstr; # outputs XXX

It never once says 'other called'. It seems to be matching the '<' signs 
OK, and I think the '~' is OK, too. It's just any other token that it's 
not matching.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About