WML Syntax Highlighting for Kate/KWrite

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Can-ned_Food
Posts: 217
Joined: December 17th, 2015, 10:27 pm

Re: WML Syntax Highlighting for Kate/KWrite (edition 0.43)

Post by Can-ned_Food »

R-r-r-resurrection!

I am making a few necessary changes to my own copy and thought that I'd let you all know so that you could throw in any of your own improvements or complaints.

Here are the two biggest things which I am changing:
  • preprocessor_block_end_statements will now be recognized with a set of additionalDeliminator that allows it to better represent how the preprocessor actually parses.
  • the brackets in animation notation of image paths are now not seen as wml elements; they have their own formatting to highlight them.
Although the version in Kate.git is now the only copy which seems to be maintained — or even online, — I am posting this notice here rather than on the KDE boards for intuitive reasons.
User avatar
Iris
Site Administrator
Posts: 6797
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: WML Syntax Highlighting for Kate/KWrite (edition 0.43)

Post by Iris »

Can-ned_Food wrote: March 15th, 2018, 11:38 pmAlthough the version in Kate.git is now the only copy which seems to be maintained — or even online, — I am posting this notice here rather than on the KDE boards for intuitive reasons.
https://github.com/shikadiqueen/kate-wml-syntax

If you could take the time to make a pull request against my repository I can work on getting the changes merged upstream later. I'm still using Kate and this syntax highlighter for WML every time I manage to find the motivation to do WML, so I'm quite interested in any updates for it. I also have a couple of 1.14-specific additions I want to work on over the next few days.
(By the way, the syntax schemas are now maintained as part of the ktexteditor library, not Kate.)
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
Can-ned_Food
Posts: 217
Joined: December 17th, 2015, 10:27 pm

Re: WML Syntax Highlighting for Kate/KWrite (edition 0.45)

Post by Can-ned_Food »

I should've thought to look there. Okay, I'll do a pull sometime soon. I haven't finished it yet.
shadowm wrote: March 16th, 2018, 4:09 am (By the way, the syntax schemas are now maintained as part of the ktexteditor library, not Kate.)
Those repos on https://cgit.kde.org/ must be old ones, then.
User avatar
Iris
Site Administrator
Posts: 6797
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: WML Syntax Highlighting for Kate/KWrite

Post by Iris »

They're not old per se, it's just that Kate/KWrite underwent a major reorganization as part of the KF5 port.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
User avatar
Iris
Site Administrator
Posts: 6797
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: WML Syntax Highlighting for Kate/KWrite

Post by Iris »

Two things:
  • I previously mentioned that the syntax highlighting files had been moved to the KDE ktexteditor library. Well, I was wrong. They are now in the syntax-highlighting library instead. Not sure if there were ever in ktexteditor in the first place, but then again it does look like they’ve moved things around more than once.
  • I added basic support for #arg/#endarg and #deprecated
Still waiting to see Can-ned’s changes, in particular those concerning preprocessor blocks. I’m also supposed to integrate a few other changes that have been independently made upstream in the meantime.

I’d also like to take this opportunity to mention that if you can figure out a way to fix the issue with # metadirectives: (# po:, # wmllint:, etc.) requiring that pesky space sandwiched between the leading # and the keyword itself to be actually recognized, that’d be grand.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
User avatar
nnibags
Posts: 6
Joined: December 31st, 2018, 9:00 am
Location: Chile

Re: WML Syntax Highlighting for Kate/KWrite

Post by nnibags »

Hi!
A bug has been reported in the WML highlighter of Kate (KSyntaxHighlighting framework): https://bugs.kde.org/show_bug.cgi?id=402720

I have proposed a patch that fixes it and, in addition, I modified the code so that only tags with valid names are highlighted (since the highlighter considers all content between "[" and "]" as a tag.).
Proposed patch: https://phabricator.kde.org/D17891

I'm not an expert in that language, I just relied on the documentation (wiki.wesnoth.org) and the highlighter for Visual Studio Code (Bitron.wml). I hope you can check the changes and verify that everything is OK (all the details are in the previous link).
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: WML Syntax Highlighting for Kate/KWrite

Post by josteph »

User avatar
nnibags
Posts: 6
Joined: December 31st, 2018, 9:00 am
Location: Chile

Re: WML Syntax Highlighting for Kate/KWrite

Post by nnibags »

With a valid tag, I mean a regular expression (alphanumeric characters and underscores), not the exact names the tags can have.
I described the tags as:
\[\+?\w*\]
\[/\s*\w*\s*]

It could also be more general:: \[[^\[\]\s]*\]
The idea is to avoid writing "[", the highlighter considers all the following code as the tag name.
EDIT: for example: https://github.com/wesnoth/wesnoth/blob ... ng.cfg#L37
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: WML Syntax Highlighting for Kate/KWrite

Post by beetlenaut »

Kate also highlights array indices like this: stored_unit[1].moves. Could it be prevented by requiring a non-alphanumeric character before the opening bracket? (This is new within a few months. It used to highlight indices normally.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
nnibags
Posts: 6
Joined: December 31st, 2018, 9:00 am
Location: Chile

Re: WML Syntax Highlighting for Kate/KWrite

Post by nnibags »

I included it! I didn't highlight tags if there is an alphanumeric character, underscore or "]" before. Because seen that a tag is highlighted in things like: https://github.com/wesnoth/wesnoth/blob ... ng.cfg#L59

The regex that I included is: (\w+|\])\[(?!/)
In this case, the matched code is highlighted as normal text.
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: WML Syntax Highlighting for Kate/KWrite

Post by josteph »

The case of ][ is tricky, since that sequence can occur both in tags ([allow_undo][/allow_undo], [not][true][/true][/not], both used in mainline) and in inline WFL/lua (x[foo][bar] is valid lua). Your example is WFL, but it's hard to get right since it's a macro that expands to a formula, not to WML as macros usually do.
User avatar
nnibags
Posts: 6
Joined: December 31st, 2018, 9:00 am
Location: Chile

Re: WML Syntax Highlighting for Kate/KWrite

Post by nnibags »

I thought about that case! The rules for highlighting tags have priority, therefore, the nested tags will be highlighted correctly. The case ][ only be considered if ] doesn't belong to the closing of a tag. In addition, [/some] (case [/) will always be highlighted as a tag.
  • text[hello] -> [hello] isn't considered a tag, since there are alphanumeric characters before.
  • text[/hello] -> [/hello] is highlighted as a tag, since there is [/.
  • text[foo][bar][hello] -> In this case, tags aren't highlighted, since there are alphanumeric characters before [foo]. Since [foo] isn't tag, enter the case ][ and neither [bar] and [hello] are highlighted.
  • [foo][bar][hello]text[/hello][/bar][/foo] -> Here, all the tags are highlighted! [foo], [bar] & [hello] don't have alphanumeric characters before, so they are highlighted as tags. [/hello][/bar][/foo] are also highlighted as tags.

This is a consequence of the regex: (\w+|\])\[(?!/)

Also, for simplicity, I can consider array indices only if there are integers between [ & ] (and alphanumeric characters before [); for example: "array[2]", but not "foo[text]" (regex: \w+\[(?=\d+\])) ...or simply, eliminate the case ][
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: WML Syntax Highlighting for Kate/KWrite

Post by beetlenaut »

nnibags wrote: January 2nd, 2019, 7:42 pm I can consider array indices only if there are integers ... for example: "array[2]", but not "foo[text]"
No, that won't work. Another common case is "foo[$index]". However, I think all the other cases would start with "$" or white space ("foo[ 100 ]").
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: WML Syntax Highlighting for Kate/KWrite

Post by josteph »

In theory someone could do foo[{MACRO}].
User avatar
nnibags
Posts: 6
Joined: December 31st, 2018, 9:00 am
Location: Chile

Re: WML Syntax Highlighting for Kate/KWrite

Post by nnibags »

If you want to check the changes, here I leave a link with the modified highlighter: https://drive.google.com/file/d/1pmqc-_ ... sp=sharing

To install it, copy the wml.xml file to $HOME/.local/share/org.kde.syntax-highlighting/syntax/ (for local user) or /usr/share/org.kde.syntax-highlighting/syntax/ (for all users).

On Friday I'll do the commit (so the patch will be included in KDE Frameworks 5.54).
Post Reply