Repeating ProcessText

Hi folks!

Today's random thought about the core code.
There are a few situations where it looks to me like the text processor has issues due to processing commands top-down. For example, if you put another text processor command inside the condition for an {if block, it won't work. The {if is changed to @@@open@@@if before it processes the parts within the if block. And then after it's done the inner bit, it wouldn't attempt the if again. It only turns the @@@open@@@ back right before outputting the text. I can't see many situations where this would be useful, but I think it could be a hidden gotcha for anyone who expects it to work.

So off the top of my head, here's a simple change:

  <function name="ProcessText" type="string" parameters="text">
    data = NewDictionary()
    dictionary add (data, "fulltext", text)
    originaltext = text
    text = ProcessTextSection(text, data)
    text = Replace(Replace(text, "@@@open@@@", "{"), "@@@close@@@", "}")
    if (GetBoolean (game, "slowtextprocessor")) {
      while (not text = originaltext and IsRegexMatch("\{.+?\}", text)) {
        originaltext = text
        text = ProcessTextSection(text, data)
        text = Replace(Replace(text, "@@@open@@@", "{"), "@@@close@@@", "}")
      }
    }
    return (text)
  </function>

Basically, as long as the output from the text processor still contains { and } pairs (either because a transclusion or eval added them, or because a statement failed) the text processor runs again on the new string.

If a statement failed to evaluate the first time, but now succeeds because of changes made inside it, this will work fine. If a statement fails for reasons not related to other text processor commands inside it, it will still fail and the text processor will run one more time to check, until all sections that can be processed have been.

I've made it check for a boolean, game.slowtextprocessor, because this will be slow, and should only be enabled if necessary.

I know this is random, it just popped into my head when I woke up this morning.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums