 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Mon May 17, 2010 10:59 pm
Pattern in dbvar doesn't match.. any help on it? |
I'm triggering off a database variable using the following trigger pattern:
#TRIGGER {{%%dbkeys(@Faerie_Tales_II_DB}}
One of the keys in the variable is the following:
A transformed prince hops(?) around here.
My guess is it's not matching due to the (?) portion, but I can't figure out a way to make it work. I've tried %quote, %quoteregex, %string and nothing works, so I'm hoping someone knows how I can force it to match. Thanks!
Charneus |
|
|
 |
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
Posted: Mon May 17, 2010 11:03 pm |
Perhaps make a function that takes a string and converts it to pattern format. Something like #trigger {@ToPattern(%%dbkeys(@Faerie_Tales_II_DB))}
IE: 'A transformed prince hops(?) around here.' would become 'A transformed prince hops~(?~) around here.' |
|
|
 |
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon May 17, 2010 11:13 pm |
Try using %stripq()? When (*) doesn't contain a pipe symbol, CMud will surround the element with quotes to ensure that the () are treated as literal characters rather than as a nested stringlist.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Tue May 18, 2010 12:40 am |
Neither of the above worked for me, sadly. In fact, it broke the pattern altogether (i.e, nothing would match in the database variable).
I wonder if it might even be a bug. :\
Charneus |
|
|
 |
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Tue May 18, 2010 4:46 pm |
The %%function() syntax is broken for zscript triggers.
If you use them within a regex trigger it works fine.
But then of course you have to retype your database.
Edit: The %%function is working after all.
I tried this to test.
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="test" copy="yes">
<value>#show {cat}
</value>
</alias>
<var name="animal" type="StringList" copy="yes">cat|dog</var>
<trigger name="regex" priority="20" regex="true" copy="yes">
<pattern>%%item(@animals,1)</pattern>
<value>#print {Matched regex.}</value>
</trigger>
<trigger name="zscript" priority="20" copy="yes">
<pattern>%%item(@animals,1)</pattern>
<value>#print {Matched zscript.}</value>
</trigger>
</cmud> |
So I'm still looking into it. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Last edited by Arminas on Tue May 18, 2010 5:24 pm; edited 1 time in total |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue May 18, 2010 5:22 pm |
Quote: |
The %%function() syntax is broken for zscript triggers. |
Umm, no it's not, I use it all the time. It *is* broken in the new trigger pattern wizard so you can't use the wizard to create triggers with functions.
Using a user function like GeneralStonewall suggested with @ToPattern has not been tested and likely doesn't work.
To solve the original posters problem, you will likely need to create a second database variable that has "clean" patterns in it. Use the %replace function to replace "(" with "~(" and then add that to the new database variable and then use the new database variable in your trigger. |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Tue May 18, 2010 5:39 pm |
Zugg:
Tried doing that, and still no dice. I have tried even replacing ? with ~?, and it doesn't work.
I know in a regular trigger pattern, it works, but I really don't want to have to create individual triggers for anything that has () in it, though I suppose if I really have to, I will.
Charneus |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue May 18, 2010 6:01 pm |
Try turning off the "Allow wildcards within {} trigger patterns" in the Scripting tab of the Preferences. I know this is a global option so it might interfere with other triggers were you want this option. In the future I might make this option a per-trigger option. But see if that at least fixes the problem.
|
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Tue May 18, 2010 6:18 pm |
Negative on the disallowing wildcards too, with and without escaping the ()...
And yeah, you're right - it would break a few other scripts if that had worked. :P I wouldn't mind it being a per-trigger option, as long as you could add that to the #TRIGGER command options, too.
Charneus |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue May 18, 2010 11:11 pm |
Hmm, that's odd. Something else is wrong then. Can you post a simple snippet of code with a db variable to demonstrate the problem? When I'm working on adding the changes to hash tables and using the JSON SuperObject code I'll be working on the section of code that handles matching lists within triggers and with a good test case I should be able to make sure this works properly in the next version.
|
|
|
 |
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed May 19, 2010 12:29 am |
What order of operation did you use when trying the different functions, Charneus? Unless there's a more fundamental bug, my guess is:
%quote() fails on account of the double-quotes surrounding the element, to literalize the parentheses contained therein. Since the line sent to you doesn't contain double-quotes, it won't match even if ~( and ~) are present.
%stripq() fails on account of the parentheses no longer being literalized, causing the trigger to look for a pattern-capture of ? or what the ? wildcard matches. This would fail to match because the trigger is now no longer looking for parentheses. Ozzy recently-ish discussed a problem with %1...%99 variables in nested stringlists on Aardwolf's tech channel, so you might try talking him up on this.
%stripq(%quote()) fails on account of the quoting getting pre-expanded back out of the string before the trigger parser gets it (essentially creating the same problem as %stripq()).
%quote(%stripq()) in theory should work, having forced the removal of any CMud-added "" and also forcing the insertion of ~ preceding each parenthetical symbol. |
|
_________________ EDIT: I didn't like my old signature |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed May 19, 2010 3:47 am |
Well, color me embarrassed on this one for making an assumption. Apparently the script I did use works... at least, it does in #TRIGGER form...
However, in regex form, it does not work, which is what I actually have the trigger set as. I know it's correct regex because everything else fires. *sigh* My mistake was thinking that if it didn't work in #REGEX, it wouldn't work in #TRIGGER. Here's my testing scripts:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<var name="TestDB" type="Record" copy="yes">This is another(?) key.=Test3|This is one key.=Test2|This is (another) key.=Test1|This is yet one more key.=Test5</var>
<trigger priority="40" regex="true" copy="yes">
<pattern>(?:(@TestDB))</pattern>
<value>#SAY {%db(@TestDB, %1)}</value>
</trigger>
</cmud> |
#SAY {This is one key.} and #SAY {This is yet one more key.} both fire correctly. The others do not. If you change the trigger back to zscript (#TRIGGER {({@TestDB})} works, can change it to #TRIGGER {({%%dbkeys(@TestDB))}), all five keys trigger. So, maybe it's a problem with the regex engine, then? The reason I have it as a regex is because I'm also matching additional information in the original trigger (checks whether something is there or not). Again, the original trigger works for everything except keys with parentheses in it.
Sorry for making assumptions... :\
Charneus |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed May 19, 2010 4:48 pm |
Remember that in RegEx the escape character is \ instead of ~. So stuff like %quote will not work (because it puts ~ instead of \ in front of the parens).
In general, this is exactly why people should be using zScript triggers and *not* regex triggers. Only use Regex triggers if there is a specific NEED to use them. When using zScript patterns, CMUD can do more processing of your pattern. For example, with zScript CMUD can reorder the elements in your list from longest to shortest so that it will work properly. With RegEx your pattern just gets passed to the regex engine without additional processing like this. |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed May 19, 2010 4:54 pm |
Right. There is a specific need for it. The script I posted was just the problem part. The trigger itself is a bit more complex. However, because %quote didn't work, isn't that the reason you created %quoteregex? That doesn't work, either.
Charneus |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed May 19, 2010 4:59 pm |
Not sure what you mean. I just tried this:
Code: |
<trigger priority="40" regex="true" copy="yes">
<pattern>(?:(%%quoteregex(%dbkeys(@TestDB))))</pattern>
<value>#SAY {%db(@TestDB, %1)}</value>
</trigger> |
and it worked fine here. |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed May 19, 2010 5:05 pm |
That's what I was missing! Doh! I was using %%quoteregex(@TestDB) instead of %%quoteregex(%dbkeys(@TestDB))...
Tested it in the original trigger, and it works now. Thanks! Silly me. :\
Charneus |
|
|
 |
|
|