On Wednesday, December 25, Alt Mcarter wrote: 
> But I'm wondering, is there a way to write token var in such a way that it
> matches <[a..z]>+ EXCEPT when it is a keyword (print, for, to, next, etc.)?

You could use a negative code assertion --

  #!/usr/bin/env raku

  my @keywords = <print for to next>;

  grammar G {
    rule TOP {
     <var>
    }
    rule var {
      <id>
      <!{ $<id> eq @keywords.any }>
    }
    token id {
      <[a..z]>+
    }
  }

  use Test;

  ok G.parse('fine');
  ok G.parse('finetoo');
  nok G.parse('print');
  nok G.parse('for');
  nok G.parse('to');
  nok G.parse('next');
  ok G.parse('forth');

(you can also use before/after assertions -- 
see 
<https://stackoverflow.com/questions/42538548/perl6-negating-multiple-words-and-permutations-of-their-chars-inside-a-regex>)

Brian

Reply via email to