Partial matching in a simple Raku program

  Kiến thức lập trình

I’ve created a simple program based on the Raku parsefile example provided here. The contents of my Raku file are:

grammar Names {
  token TOP  { [<name><.ws>]+ }
  token name { <:alpha>+ }
}                                                                               
                                                                                
say Names.parsefile('names.txt');

The contents of names.txt is below:

Andrea
John

Running this minimal program indicates a successful parse has been achieved:

「Andrea
John
」
 name => 「Andrea」
 name => 「John」

If I now add something which will not be parsed by the name token (i.e. 99999999):

Andrea
99999999
John

…running the program then outputs only Nil. Is there a way to modify the program so that I could still find that “Andrea” and “John” have been parsed by the name token successfully?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT