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

Erwin Harte harte at xs4all.nl
Fri Mar 14 20:43:25 CET 2003


On Fri, Mar 14, 2003 at 11:35:33AM -0800, Tavis Elliott 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.

Well, with most regexp packages you can do things like this (I'll
write how I'd do it in perl):

    if ($str =~ /^(\S+):((\d+)\s+)?Foo\s+([a-z])$/) {
        print "$1; $2; $3; $4\n";
    }

Match the pattern and be able to use the (sub)matches.  How would you
do that one? :)

[...]
> no one has implemented this yet ... Everyone who is smarter than me, and 
> who has done so, must be shy.  :)

Or too busy with other `more important' things in life. ;-)

Erwin.
-- 
Erwin Harte <harte at xs4all.nl>
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list