Hi Marc,
This looks like a Perl 5 complementary character match:  [^:]*

But it means something quite different in Perl6. From S05
<http://perlcabal.org/syn/S05.html>

Bracket rationalization
<http://perlcabal.org/syn/S05.html#Bracket_rationalization>  [ ... ] is no
longer a character class. It now delimits a non-capturing group.

Changed metacharacters
<http://perlcabal.org/syn/S05.html#Changed_metacharacters>^ and $ now
always match the start/end of a string

Backtracking control
<http://perlcabal.org/syn/S05.html#Backtracking_control>To force the
preceding atom to do no backtracking, use a single :

In summary, this pattern is repeatably matching an empty start-of-string.

A Perl 6 equivalent is:

    token gecos { <- [':']>* }

This matches a complementary character class; all but ':'.

Also, the <home> and <shell> rules aren't fully matching their test input
at the moment.

Cheers,
- David


On Sat, Jul 12, 2014 at 10:07 AM, Marc Chantreux <m...@unistra.fr> wrote:

> hello,
>
> using perl6 version 2014.04 built on MoarVM version 2014.04
>
> i'm trying to write a grammar to parse the result of a `getent passwd`
> but when i test the gecos (which could be empty), i fall into a loop.
>
> the pb appears whenever i try to match something that can be empty using
> the * quantifier.
>
> I guess i miss a simple point there but i can't figure out what. Any
> help (or feedback on any other part of the code) would be appreciated.
>
> regards
>
> use v6;
> use Test;
>
> grammar PAccountDB {
>     token TOP { ^ <account>*  $ }
>     token account {
>         <login>
>         ':' <passwd>
>         ':' <uid>
>         ':' <gid>
>         ':' <gecos>
>         ':' <home>
>         ':' <shell>
>         \n
>     }
>     token login  { <[a..z]>+ }
>     token passwd { 'x' }
>     token numid  { \d+ }
>     token uid    { <.numid> }
>     token gid    { <.numid> }
>     token gecos  { [^:]* }
>     token path   { '/' <-[\x00'/']>+ }
>     token home   { <.path> }
>     token shell  { <.path> }
> }
>
> for
> ( uid   => '445'
> , gid   => '445'
> , shell => '/bin/false'
> , home  => '/home/mc'
> # , gecos => 'server account,,,'
> , login => 'root' ) {
>         my ( $rule, $candidate ) = .kv;
>         ok ?PAccountDB.subparse( $candidate, :rule($rule) )
>         , "subrule $rule matches $candidate";
> }
>
>
> --
> Marc Chantreux
> Université de Strasbourg, Direction Informatique
> 14 Rue René Descartes,
> 67084  STRASBOURG CEDEX
> ☎: 03.68.85.57.40
> http://unistra.fr
> "Don't believe everything you read on the Internet"
>     -- Abraham Lincoln
>

Reply via email to