Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Bug reports
➜ %<> assignment with mode modifier (?J) erroneously point to the last group
%<> assignment with mode modifier (?J) erroneously point to the last group
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Kahenraz
(75 posts) Bio
|
Date
| Sat 14 Apr 2018 08:16 AM (UTC) |
Message
| This is regarding PCRE regular expression matching and has to do with an incorrect result being assigned to the matching %<> that is passed along to a script; Lua in my case.
Regex:
(?J)^(You poke (?P<thing>.+)|You prod (?P<thing>.+))$
Trigger:
<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="(?J)^(You poke (?P<thing>.+)|You prod (?P<thing>.+))$"
regexp="y"
send_to="12"
>
<send>
print("Thing -- " .. "%<thing>")
</send>
</trigger>
</triggers>
Test:
You poke a rock
You prod a rock
Result:
You poke a rock
Thing --
You prod a rock
Thing -- a rock
The expected result is for "thing" to be "a rock" for both poking and prodding.
The problem is that the value assigned to %<thing> is always the last group which may not have a value for the named group as it wasn't a match. This can be demonstrated by swapping the order of the logical expression:
(?J)^(You prod (?P<thing>.+)|You poke (?P<thing>.+))$
I can confirm that the PCRE library which MUSH uses does handle this expression correctly:
Regex = "(?J)^(You poke (?P<thing>.+)|You prod (?P<thing>.+))$"
Regex = rex.new(Regex)
_, _, Table = Regex:match("You poke a rock")
print(Table[2])
print(Table[3])
print()
Regex = "(?J)^(You prod (?P<thing>.+)|You poke (?P<thing>.+))$"
Regex = rex.new(Regex)
_, _, Table = Regex:match("You poke a rock")
print(Table[2])
print(Table[3])
Result:
a rock
false
false
a rock
This is most likely due to an error in handling the result from the match when Mush assigns values to its special %<> variables. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 15 Apr 2018 06:02 AM (UTC) |
Message
| I am somewhat astounded at this, because this feature was added in version 4.06 on 26 Apr 2007 and would have been tested to make sure it works. There was a bugfix on 7 May 2007 related to using the same name in multiple places. This would necessarily have required testing to ensure it worked properly.
I can only assume that in one of the upgrades to the PCRE code in the last 11 years they changed the way the duplicate named groups works, a change that wasn't noticed by anyone, including me.
I have pushed a change to the code which seems to fix it, although I am not 100% confident. Perhaps you can test it and let me know.
Get the pre-release version and see what happens.
http://www.gammon.com.au/forum/?id=13903 |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Kahenraz
(75 posts) Bio
|
Date
| Reply #2 on Mon 16 Apr 2018 12:33 AM (UTC) Amended on Mon 16 Apr 2018 12:34 AM (UTC) by Kahenraz
|
Message
| I think this broke something. Testing with release #f99ffb2.
Regex:
^You poke at (?P<thing>.+) with (?P<with>.+)$
Script:
print("Thing: %<thing>")
print("With: %<with>")
Copy/Paste:
<triggers>
<trigger
enabled="y"
group="-- TEST"
match="^You poke at (?P<thing>.+) with (?P<with>.+)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>print("Thing: %<thing>")
print("With: %<with>")
</send>
</trigger>
</triggers>
Test:
You poke at a rock with a stick
Expected output:
Thing: a rock
With: a stick
Actual output:
Thing: a stick
With: a stick
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Mon 16 Apr 2018 05:23 AM (UTC) |
Message
| Try the latest pre-release now. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,378 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top