Bug 411867 - [New Syntax] Highlighting for Solidity (Ethereum)
Summary: [New Syntax] Highlighting for Solidity (Ethereum)
Status: RESOLVED FIXED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-12 16:11 UTC by Robert Kaiser
Modified: 2020-02-12 11:13 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.68.0


Attachments
First take on Solidity highlighting rules (11.58 KB, text/xml)
2019-09-12 16:11 UTC, Robert Kaiser
Details
Updated Solidity highlighting rules (11.73 KB, text/xml)
2020-01-11 20:59 UTC, Robert Kaiser
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Kaiser 2019-09-12 16:11:58 UTC
Created attachment 122631 [details]
First take on Solidity highlighting rules

Kate has no syntax highlighting for Ethereum's Solidity language yet, but it would be really nice to have for people who work with Smart Contracts on that popular blockchain.

Language docs are at https://solidity.readthedocs.io/en/latest/index.html

I have a very preliminary XML I just created in the last few hours (attached), it may not be optimal but it seems to work decent with the Solidity files I tried so far.
There may be things missing (though I read through all the docs to try and catch all keywords, units, and built-ins at least) or things not detected in the right way, but this should be a start.

I'll keep trying and testing that XML in my ~/.local/share/org.kde.syntax-highlighting/syntax/ directories and I'm happy for any suggestions, improvements and help in maybe getting this into Kate proper.
Comment 1 Nibaldo G. 2019-09-20 07:09:16 UTC
I don't know this language, however I have tested with the GitHub sample files (https://github.com/ethereum/solidity/) and it looks good. If you want, you can send it to the repository to include it. In that case, it's necessary that you also add a test file in "autotests/input/".

This is the KSyntaxHighlighting repository: https://phabricator.kde.org/source/syntax-highlighting/
The XML files are located in "data/syntax/".

Here is the documentation for publishing patches: https://community.kde.org/Infrastructure/Phabricator

If you think the highlighting file can be improved, you can publish patches in the future, modifying it without problems.

In case you don't have time to do all that, you can upload the test file here and I will publish the highlighter file.

Some recommendations:
* On line 284, add `<IncludeRules context="##Doxygen" />` to also highlight comments with documentation.
* If possible, use the MIT license in the .xml file.
Comment 2 Nibaldo G. 2019-09-20 07:14:31 UTC
Also, the keywords "reserved" are highlighted with "Error", I don't know if it's intentional, but I think it's good
Comment 3 Robert Kaiser 2019-09-22 10:32:26 UTC
(In reply to Nibaldo G. from comment #2)
> Also, the keywords "reserved" are highlighted with "Error", I don't know if
> it's intentional, but I think it's good

That is intentional as it's an error if you use them in your code right now. Of course, the highlighting will need to be updated if/when any words may move from that list to language keywords in future versions.

I will look into your comment #1 as soon as I get to it, hopefully in the next few weeks, thanks for the pointers!
Comment 4 Robert Kaiser 2020-01-11 20:59:45 UTC
Created attachment 125043 [details]
Updated Solidity highlighting rules

OK, I have worked with those rules for a while and they perform very well for me, so I updated the file and attached it here.

I tried to do a patch but stumbled fast because I can't get my home directory "polluted" by a kde subdirectory, I'd need to have the build in a different directory/disk if I would build - and I also doN't want my default .bashrc filled up with any project I contribute a single patch to (as much as I like KDE). But I don't want to complain here, rather get to a productive result.

So, it would be preferred if someone other than me can drive this into the repository, but I'm happy to provide anything needed.

What should be in the test file? Should it touch all syntax cases or just an example?
Comment 5 Christoph Cullmann 2020-01-11 22:33:18 UTC
Thanks for working on this.

Yes, we can take care on commiting this file.

As for the test: ideally, a MIT licensed example file that touches as much of the syntax as possible would be nice, to see if we regress some when.
Comment 6 Christoph Cullmann 2020-02-01 20:29:27 UTC
Hi, have you some small test file?
Comment 7 Nibaldo G. 2020-02-11 08:35:19 UTC
I can add a test file
Comment 8 Nibaldo G. 2020-02-11 08:38:28 UTC
https://phabricator.kde.org/D27313
Comment 9 Robert Kaiser 2020-02-11 18:57:53 UTC
Thanks, I wanted to get back to it, but it's always a time issue. ;-)

That file from the docs probably does not use the majority of the language features but it should be a decent test for the most common things being used.

Thanks for picking this up!
Comment 10 Christoph Cullmann 2020-02-11 19:02:51 UTC
Git commit fd345c7338fb88f668b7341faaca0ab1913a6894 by Christoph Cullmann, on behalf of Nibaldo González.
Committed on 11/02/2020 at 19:03.
Pushed by cullmann into branch 'master'.

Add syntax highlighting for Solidity

Summary:

The XML file was created by Robert Kaiser and attached in: https://bugs.kde.org/show_bug.cgi?id=411867

I took the test file from the Solidity documentation: https://solidity.readthedocs.io/en/latest/solidity-by-example.html

Reviewers: #framework_syntax_highlighting, dhaumann, cullmann

Reviewed By: #framework_syntax_highlighting, cullmann

Subscribers: kwrite-devel, kde-frameworks-devel

Tags: #kate, #frameworks

Differential Revision: https://phabricator.kde.org/D27313

A  +153  -0    autotests/folding/test.sol.fold
A  +160  -0    autotests/html/test.sol.html
A  +153  -0    autotests/input/test.sol
A  +153  -0    autotests/reference/test.sol.ref
A  +357  -0    data/syntax/solidity.xml

https://commits.kde.org/syntax-highlighting/fd345c7338fb88f668b7341faaca0ab1913a6894