[go: up one dir, main page]

Page MenuHomePhabricator

jqueryMsg doesn't support complex first parameter for #FORMAL
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Have mw.jqueryMsg available in the console (it usually is available)
  • In the browser console, input: mw.messages.set( 'mytest', '{{#FORMAL:{{GENDER:|Informal}} hello|{{GENDER:|Formal}} hello}}' );
  • Input: mw.msg( 'mytest' );

What happens?:

  • The message is not parsed as expected: {{#FORMAL:{{GENDER:|Informal}} hello|{{GENDER:|Formal}} hello}}

What should have happened instead?:

  • The message should have been parsed to Informal hello (or Formal hello if you use a language code like de-formal)

I discovered this not long after my patch adding FORMAL support to jqueryMsg was merged, after adding {{#FORMAL:}} to some JavaScript-only messages in Translatewiki.

In order to make myself clear, here's the terminology I'll use:
{{#FORMAL:firstparam|secondparam}}
In my testing, I've found that firstparam can not contain complex syntax. Other (jqueryMsg-supported) parser functions are fine in isolation, but not when combined with other text. So if firstparam is {{GENDER:|He|She|They}}, it works, but if it is {{GENDER:|He|She}} is, it doesn't work. secondparam can be whatever thing is supported, the problem is only when the complex text is in the first parameter (following the colon).

The code that chooses how to parse stuff in jqueryMsg is unfortunately quite complex (at least to me), with functions like nOrMore(), sequence() and choice() used to pick which function it should try to parse with. I've tried a lot of different things locally, but haven't been able to make heads or tails of it, so I'm hoping someone else has a clue.

Event Timeline

@matmarex @Fomafix Adding you as subscribers because you've both contributed to jqueryMsg in the past, so I'm hoping you might have more of a clue than me about how to fix this. :-)

FYI, jqueryMsg is basically a handwritten recursive descent parser. The example given in the Wikipedia article is perhaps a bit too complex to be educational, but knowing this keyword you can probably look up some other examples, and I hope this helps explain why all the functions exist and call each other like that. And the higher-order functions you mention are technically parser combinators (the example in this article is unfortunately even less educational).

Anyway, I figured out why this case is not working. Funny thing is, I touched that code about 10 years ago in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/113112, and the commit message there makes it clear that I didn't understand it back then ;)

Change #1088667 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/core@master] mw.jqueryMsg: Allow complex expressions in parser functions' first param

https://gerrit.wikimedia.org/r/1088667

Change #1088668 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/core@master] mw.jqueryMsg: Simplify special cases for parser functions' first param

https://gerrit.wikimedia.org/r/1088668

Change #1088667 merged by jenkins-bot:

[mediawiki/core@master] mw.jqueryMsg: Allow complex expressions in parser functions' first param

https://gerrit.wikimedia.org/r/1088667

Change #1088668 merged by jenkins-bot:

[mediawiki/core@master] mw.jqueryMsg: Simplify special cases for parser functions' first param

https://gerrit.wikimedia.org/r/1088668

Thank you very much for fixing that, @matmarex, and for the pointers for how to learn more. Greatly appreciated!

Change #1090478 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/core@REL1_43] mw.jqueryMsg: Allow complex expressions in parser functions' first param

https://gerrit.wikimedia.org/r/1090478

Change #1090479 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/core@REL1_43] mw.jqueryMsg: Simplify special cases for parser functions' first param

https://gerrit.wikimedia.org/r/1090479

Change #1090478 merged by jenkins-bot:

[mediawiki/core@REL1_43] mw.jqueryMsg: Allow complex expressions in parser functions' first param

https://gerrit.wikimedia.org/r/1090478

Change #1090479 merged by jenkins-bot:

[mediawiki/core@REL1_43] mw.jqueryMsg: Simplify special cases for parser functions' first param

https://gerrit.wikimedia.org/r/1090479

matmarex claimed this task.
matmarex removed a project: Patch-For-Review.