[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Bug reports
. . -> [Subject]  %<> 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] Refresh page


Posted by Kahenraz   (75 posts)  [Biography] 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&lt;thing&gt;.+)|You prod (?P&lt;thing&gt;.+))$"
   regexp="y"
   send_to="12"
  >
  <send>
    print("Thing -- " .. "%&lt;thing&gt;")
  </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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] 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
[Go to top] top

Posted by Kahenraz   (75 posts)  [Biography] 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&lt;thing&gt;.+) with (?P&lt;with&gt;.+)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>print("Thing: %&lt;thing&gt;")
print("With: %&lt;with&gt;")
</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
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] 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
[Go to top] 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.


11,450 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]