Author Topic: Possible regexp bug?  (Read 932 times)

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 859
  • Dreaming of a red Xmas
    • The Gibberlings Three
Possible regexp bug?
« on: May 04, 2022, 03:36:31 PM »
This came up in the G3 Discord, as part of morpheus562's work on the Skills and Abilities mod.

Essentially, he wants to patch Narlen Darkwalk's dialogue in BGEE to allow monks and bars to take part in the previously thief-only quests. Narlen has two top-level states with these triggers:

Code: [Select]
Global("TalkedToNarlen","GLOBAL",0)
!InParty([0.0.0.THIEF_ALL])

and

Code: [Select]
Global("TalkedToNarlen","GLOBAL",0)
He wants to alter only the first trigger and not the second, so we tried this d code:

Code: [Select]
REPLACE_TRIGGER_TEXT NARLEN ~Global("TalkedToNarlen","GLOBAL",0)[ %TAB%%LNL%%MNL%%WNL%]*!~ ~Global("TalkedToNarlen","GLOBAL",0) !InParty([0.0.0.BARD_ALL]) !~
No matter what we tried, we couldn't get it to positively match the ! at the end. We tried several tricks to try and get it to work, but it only seems to match if you use a . there. Trying this in a COPY_EXISTING > DECOMPILE_AND_PATCH > REPLACE_TEXTUALLY has the same result which makes me suspect there's something going on in the regexp parser.
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline Argent77

  • Planewalker
  • *****
  • Posts: 187
Re: Possible regexp bug?
« Reply #1 on: May 04, 2022, 04:09:52 PM »
It looks like exclamation marks are not allowed in regular expressions. You can work around it by using variable substitution.

Add this line to your .tp2 file:
Code: [Select]
OUTER_SPRINT NEGATE ~!~
and add EVAL to the COMPILE action.

Use this .d command to replace the state trigger:
Code: [Select]
REPLACE_TRIGGER_TEXT NARLEN ~Global("TalkedToNarlen","GLOBAL",0)[ %TAB%%WNL%]*%NEGATE%~ ~Global("TalkedToNarlen","GLOBAL",0) !InParty([0.0.0.BARD_ALL]) !~

Edit: Btw, LNL and MNL instances are redundant in regexp character sets, since both codes are already included by WNL. I mention it because I have seen it numerous times in WeiDU code examples.
« Last Edit: May 04, 2022, 04:14:15 PM by Argent77 »

morpheus562

  • Guest
Re: Possible regexp bug?
« Reply #2 on: May 04, 2022, 04:35:17 PM »
That code provides the following error:

[tb#_compile_eval_buffer/skills-and-abilities/dlg/narlenb.d] LEXER ERROR at line 21 column 1-0
Near Text: !
        invalid character [!]
ERROR: parsing [tb#_compile_eval_buffer/skills-and-abilities/dlg/narlenb.d]: Parsing.Parse_error
ERROR: compiling [skills-and-abilities/dlg/narlenb.d]!
Stopping installation because of error.
Stopping installation because of error.
Stopping installation because of error.

Offline Argent77

  • Planewalker
  • *****
  • Posts: 187
Re: Possible regexp bug?
« Reply #3 on: May 04, 2022, 05:21:48 PM »
The code above worked fine in a quick test mod. Maybe there is something else in your code that interferes with script execution?

morpheus562

  • Guest
Re: Possible regexp bug?
« Reply #4 on: May 04, 2022, 06:22:42 PM »
Code: [Select]
OUTER_SPRINT monegate ~!~
Code: [Select]
///////////////////////////////////////////////////////////////////////////
// Narlen Darkwalk - BGEE Thieves Guild                             //
///////////////////////////////////////////////////////////////////////////
ACTION_IF GAME_IS ~bgee eet~ BEGIN
  COMPILE EVAL ~skills-and-abilities/dlg/narlenb.d~
END

Code: [Select]
REPLACE_TRIGGER_TEXT NARLEN ~Global("TalkedToNarlen","GLOBAL",0)[ %TAB%%WNL%]*%monegate%~ ~Global("TalkedToNarlen","GLOBAL",0) !InParty([0.0.0.BARD_ALL]) !~
I think I have everything exactly as you stated.

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 859
  • Dreaming of a red Xmas
    • The Gibberlings Three
Re: Possible regexp bug?
« Reply #5 on: May 04, 2022, 07:14:47 PM »
Variable substitution is one of the things we tried that also didn't work.

edit: should also add, ! is absolutely allowed in regexps--it's used without issue throughout BG2FP in both script (via R_T) and d code patches.
« Last Edit: May 04, 2022, 07:17:03 PM by CamDawg »
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 859
  • Dreaming of a red Xmas
    • The Gibberlings Three
Re: Possible regexp bug?
« Reply #6 on: May 04, 2022, 07:23:49 PM »
And the solution is decidedly less sexy--compiling with an explicit EVALUATE_BUFFER was needed. I thought AUTO_EVAL_STRINGS was sufficient.
« Last Edit: May 04, 2022, 07:28:48 PM by CamDawg »
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

morpheus562

  • Guest
Re: Possible regexp bug?
« Reply #7 on: May 04, 2022, 07:41:27 PM »
However, WeiDU is evaluating %WNL% even if it is commented out. That was causing my error above because I commented out lines of unused code while I was troubleshooting.

morpheus562

  • Guest
Re: Possible regexp bug?
« Reply #8 on: May 04, 2022, 07:43:16 PM »
I have no way to edit my prior message, but big props to Bubb for determining the issue with WeiDU evaluating %WNL% even if it is commented out.

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 859
  • Dreaming of a red Xmas
    • The Gibberlings Three
Re: Possible regexp bug?
« Reply #9 on: May 04, 2022, 07:46:08 PM »
However, WeiDU is evaluating %WNL% even if it is commented out. That was causing my error above because I commented out lines of unused code while I was troubleshooting.

Working example:

Code: [Select]
<<<<<<<<./narlen.d
//REPLACE_TRIGGER_TEXT NARLEN ~Global("TalkedToNarlen","GLOBAL",0)\([ %TAB%%WNL%]+!\)~ ~Global("TalkedToNarlen","GLOBAL",0) !InParty([0.0.0.BARD_ALL]) \1~
REPLACE_TRIGGER_TEXT NARLEN ~Global("TalkedToNarlen","GLOBAL",0)\([ %TAB%%WNL%]+!\)~ ~Global("TalkedToNarlen","GLOBAL",0) !InParty([0.0.0.BARD_ALL]) \1~
>>>>>>>>
COMPILE ~./narlen.d~ EVALUATE_BUFFER
Removing the commented code, or wrapping it in /* */ instead works fine.
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline Wisp

  • Moderator
  • Planewalker
  • *****
  • Posts: 1176
Re: Possible regexp bug?
« Reply #10 on: May 07, 2022, 06:14:20 PM »
Variable substitution does not heed comments, no. /* */ works because it ends up containing the expanded new lines, whereas // only comments out the string before %WNL%; whatever comes after ends up on a different line.

Offline DavidW

  • Planewalker
  • *****
  • Posts: 316
Re: Possible regexp bug?
« Reply #11 on: May 08, 2022, 03:13:19 PM »
And presumably it shouldn't. In variable-substitution contexts a file is just text. (I substitute comments in and out in various bits of my code.)

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: