[DGD] parse_string() implementation of regex (was: Memory usage)

Felix A. Croes felix at dworkin.nl
Fri Mar 14 21:38:20 CET 2003


Tavis Elliott <tavise at nwlink.com> wrote:

>[...]
> Here's my first attempt, which doesn't seem to do what I want:
>
>   grammar = "pattern = /"+ pattern +"/ " +
>     "other = /./ "+
>     "match : pattern";
>
> Using a pattern of 'foo' on a string of 'foo' matches fine, but using a 
> pattern of 'foo' on any other string (such as 'afoo') returns nil.
>
> It seemed that the token 'pattern' would match whatever the pattern is, and 
> the token 'other' would match everything else.  This would mean the token 
> parsing wouldn't ever fail, since 'other' would match the whole string if 
> 'pattern' didn't match anything.  If no 'pattern' token was found, then 
> parse_string() would return nil.
>
> I feel I'm missing something major.

What you are missing is that you have to match the entire input string,
when it just contains the proper substring.  As a regular expression
rule, this would be more like: "/.*" + pattern + ".*/".

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



More information about the DGD mailing list