[DGD] Question about parse_string

Jay Shaffstall jshaffst at netwalk.com
Mon Jul 1 19:14:19 CEST 2002


I'm new to creating grammars, so this may be something silly on my 
part.  My understanding was that if parse_string could not parse the string 
using the grammar, it would return nil.  I have a very simple grammar I'm 
using as a test case, to make sure I understand the basics, and when the 
string is able to be parsed, parse_string returns non-nil, as 
expected.  But when the string is not able to be parsed, I get an error 
thrown: Bad token at offset 0.

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.

Is there a way to get parse_string to not generate the bad token error, and 
simply return nil if the string cannot be parsed?  I'm assuming some 
modification of the grammar is in order, but I can't figure out what from 
looking at other sample grammars I've seen.

Any advice would be greatly appreciated.

Thanks,
Jay

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



More information about the DGD mailing list