[DGD] Question about parse_string

Felix A. Croes felix at dworkin.nl
Mon Jul 1 22:09:23 CEST 2002


Jay Shaffstall <jshaffst at netwalk.com> wrote:

>[...]
> Here's the grammar:
>
> 	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 that is not matched by the preceding rules or by strings:

    whitespace = /[\b\n\r\t ]+/
    garbage = /.+/

This token does not have to appear in the rules below.  The grammar as
a whole will now reject any incorrect input without causing an error.

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



More information about the DGD mailing list