[DGD] Question about parse_string

Jay Shaffstall jshaffst at netwalk.com
Mon Jul 1 22:41:00 CEST 2002


> >       whitespace = /[\b\n\r\t ]+/
> >       command: 'touch' 'pole'
> >       command: 'touch' 'the' 'pole'
> >
> > As you can see, an extremely basic grammar to make sure I understood 
> what I
> > was doing.  Apparently I don't, though.  Any string that doesn't match the
> > production rules generates the bad token error, when I would have simply
> > expected parse_string to return nil.
>
>The thing to do is to add a "garbage" token rule to the grammar that
>catches anything...

Odd...that was one of the things I tried before mailing the list.  Here's 
my test code with that bit added:

         if (parse_string ("whitespace = /[\b\n\r\t ]+/ garbage = /.+/ 
command: 'touch' 'pole' command: 'touch' 'the' 'pole'", "touch pole"))
                 this_user ()->message ("Parsed!\n");
         else
                 this_user ()->message ("Did not parse.\n");

When this runs, parse_string always returns nil, even though it seems to me 
that the string "touch pole" should match the grammar.

Is my grammar in some other way defective?

Jay


_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list