[212] in Coldmud discussion meeting
Re: match_template() needs help with consistancy
daemon@ATHENA.MIT.EDU (Thu Apr 28 00:29:21 1994
)
To: the Lyncx <BRANDON@cc.usu.edu>
Cc: coldstuff@MIT.EDU
In-Reply-To: Your message of Wed, 27 Apr 94 21:17:18 -0600.
<01HBOMJG87W4BETA4J@cc.usu.edu>
Date: Thu, 28 Apr 94 00:26:34 EDT
From: Greg Hudson <ghudson@MIT.EDU>
> match_template("f * d *", "f zz d foo") => ["f", "zz", "d", "foo"]
> match_template("f * d *", "f \"zz\" d foo") => ["f", "zz", "d", "foo"]
> match_template("f * d *", "f \"zz\" cc d foo") => 0
> match_template("f * d *", "f zz d \"fo\"o") => ["f", "zz", "d", "\"fo\"o"]
From the documentation on match_template:
A simple wildcard is represented by an asterix (`*'). A
simple wildcard matches any number of words in string. If the
wildcard is followed by a word-pattern in template, then it
can also match a quoted wildcard match.
A quoted wildcard match is just like a C-- string literal: it
begins and ends with a double quote (`"'), and can include a
literal double quote or backslash by preceding the character
with abackslash (`\'). If the simple wildcard is followed by
a word-pattern, and the words in string that the wildcard
would match begin with a double quote, then the match must be
a quoted wildcard match or the match fails, even if the match
would have succeeded if the words were not treated as a quoted
wildcard match.
My justification:
* If the user wants to match a wildcard with something that includes
text that would match the next word pattern, the user should simply
quote the entire argument as a C string literal, and leave it at that.
* The user generally doesn't want any processing to get in the way
when it's not necessary; therefore, no processing at all is done on
the last argument.
As far as I know, these rules are completely consistent with MOO's
verb-dobj-preposition-iobj parsing rules, assuming the pattern is of
the form "foo * bar *".
> As I feel it should work (for consistancy reasons):
> match_template("f * d *", "f zz d foo") => ["f", "zz", "d", "foo"]
> match_template("f * d *", "f \"zz\" d foo") => ["f", "zz", "d", "foo"]
> match_template("f * d *", "f \"zz\" cc d foo") => ["f", "zz", "cc", "d", "foo"]
> match_template("f * d *", "f zz d \"fo\"o") => ["f", "zz", "d", "fo", "o"]
According to these rules, a wildcard can (apparently) result in more
than one field. This requires in-db checking every time you match a
template containing a wildcard, and worse, it is ambiguous: consider:
match_template("f * a|b *",
"f \"b\" a \"a\"") => ["f", "b", "a", "a"]
match_template("f * a|b *",
"f b \"a\" a") => ["f", "b", "a", "a"]
The later results sound like genuine bugs; perhaps someone should fix
them.
--GBH