syntax-highlighting: parameters for included highlighting rules

Milian Wolff mail at milianw.de
Thu Jul 18 10:12:06 BST 2019


Hey all,

has anyone ever thought about a way to make the declarative XML syntax 
highlighting rules configurable somehow? Case in point:

in QML, this is valid:

property string foo: (true ? "line 1
                              line 2" : "line 1
                                        line 2")

While in QML this is not:

var foo = (true ? "line 1
                   line 2" : "line 1
                             line 2")

I.e. QML supports multi-line string literals. JavaScript on the other hand 
does not support this. We handle this for top-level strings in the QML 
highlighter, but do not catch the strings nested within a Conditional block, 
Object or any other deeper levels of the syntax tree.

I don't see any easy way to solve this. One idea I have (no clue if this is 
even possible) would be something like:

qml.xml:
```
<IncludeRules context="Normal##JavaScript">
    <SetEntity name="StringLineEndContext" value="#stay" />
</IncludeRules>
```

javascript.xml:
```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd"
[
  ...
  <!ENTITY StringLineEndContext value="#pop" />
]>
...
<context attribute="String" lineEndContext="&StringLineEndContext;" 
name="String">
...
```

Sadly, it doesn't seem to be trivially possible to overwrite entities through 
QXmlStreamReader, but the QXmlStreamEntityResolver would allow resolving 
undeclared entities. So maybe we'd need to add some prefix to where we use the 
entity and then either use the entity from a parent include's SetEntity value, 
or fall back to the current file's non-prefixed identify value...

Other ideas or suggestions?

Cheers
-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kwrite-devel/attachments/20190718/1dd8acc6/attachment.sig>


More information about the KWrite-Devel mailing list