WeiDUorg / weidu

WeiDU is a program used to develop, distribute and install modifications for games based on the Infinity Engine.
http://www.weidu.org
GNU General Public License v2.0
90 stars 20 forks source link

REFACTOR_TRIGGER: infinite matching #97

Closed FredrikLindgren closed 6 years ago

FredrikLindgren commented 7 years ago

Inserting a matched-group reference into ORed triggers leads into an infinite loop. The code uses spacer in the substituting text to prevent additional matches against the new text that is inserted by the refactoring. Matched-group references slip through this mechanism because they are not, and cannot yet be, literal matches.

In fix_or, after fix_or_internal has returned, find returns true because the matched-group reference has now been replaced by the group it referenced. subst is called in a depth-first recursion that never ends.

If the matched-group reference in the TP2 is replaced by the equivalent literal text, find instead returns false because the substituting text contains spacer.

<<<<<<<< .../test.baf
IF
  See(Player1)
  OR(2)
    RandomNum(10,1)
    RandomNum(10,2)
  See(Player2)
THEN
  RESPONSE #100
    NoAction()
END
>>>>>>>>

COPY - ~.../test.baf~ ~.../subst.baf~
  REFACTOR_TRIGGER EVALUATE_REGEXP ~\(RandomNum(10,2)\)~ ~\1~
  READ_ASCII 0 buff (BUFFER_LENGTH)

PRINT ~%buff%~
FredrikLindgren commented 6 years ago

The brute solution of adding spacer to everything and removing it from everything seems to work.