Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Solidity (lexer and examples) #760

Merged
merged 31 commits into from
Apr 5, 2020

Conversation

veox
Copy link
Contributor

@veox veox commented Aug 22, 2017

Adds a lexer for the Solidity language. It's based on Rouge's C lexer.

The longer example in sample is from my Pygments lexer package. The shorter one in demos was written specifically for Rouge.

Compared to the linked Pygments lexer, the one here has more less up-to-date keywords, but and doesn't have a distinct assembly state (yet). This is not a big issue: the low-level assembly keywords (e.g. let) are listed (in self.reserved).

Here's the demo file on Lightshow, for comparison with a yet another highlighter (using davidhq/SublimeEthereum grammar file).

I've squashed the development history into one commit; do tell if this is undesirable.


Solidity is a high(?)-level language for the Ethereum Virtual Machine (EVM), a blockchain-based "decentralised computer".

More info: solc compiler, its docs; ethereum.org landing page

This fixes #987.

@veox veox changed the title spec/lexers/sampes/demos: add Solidity lexer (squashed branch). Add Solidity (lexer and examples) Aug 22, 2017
@veox
Copy link
Contributor Author

veox commented Aug 22, 2017

To be transparent: Solidity's not in github's linguist (yet), and looks like it won't be for the foreseeable future.

My hopes with adding it here is that GitLab will eventually pick it up with a Rouge update; and the Solidity community will finally get a little-effort way of having highlighted code online.

spec/lexers/solidity_spec.rb Outdated Show resolved Hide resolved
lib/rouge/lexers/solidity.rb Outdated Show resolved Hide resolved
@Arachnid
Copy link

Any chance of this getting merged? It'd be really handy.

@veganstraightedge
Copy link

What's the over/under that this'll get merged in, @jneen? I'd love to be able to use Rouge and stay in Ruby Land instead of farming out to Pygments.

PS. Thanks for making Rouge! ❤️

@pklinger
Copy link

pklinger commented Mar 21, 2019

Is there any chance this will ever get merged or what is holding this back @jneen @dblessing ?

@FabioBonfiglio
Copy link

Would love to see this merged too...
🙏

@axic
Copy link

axic commented Dec 8, 2019

To be transparent: Solidity's not in github's linguist (yet), and looks like it won't be for the foreseeable future.

Actually linguist merged the PR on 12th Jan 2018: github-linguist/linguist#3973

@axic
Copy link

axic commented Mar 23, 2020

@jneen @dblessing @pyrmont @gfx can you give some advice what would be needed to get his PR considered for merging?

It definitely needs to be updated for latest syntax.

@pyrmont
Copy link
Contributor

pyrmont commented Mar 24, 2020

@axic I'm sorry this has been outstanding for such a long time. I have a couple of comments to make but is @veox still monitoring this? (I wouldn't blame you if you weren't, @veox.) Just wondering whether it makes more sense for someone else to submit a new PR that they can be responsible for or not.

@pyrmont pyrmont self-assigned this Mar 24, 2020
@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Mar 24, 2020
@chriseth
Copy link

@pyrmont thanks for your quick response! I'll add some comments where this needs to be updated to the latest version of the language if you don't mind. If veox is not working on this anymore, we can open a new PR any time.

@veox
Copy link
Contributor Author

veox commented Mar 25, 2020

I'll get to this tomorrow, a bit too late today.

(The Pygments highlighter has been updated to Solidity v0.6.0 syntax, so this should be relatively easy.)

@axic
Copy link

axic commented Mar 25, 2020

Thanks @pyrmont for the answer! @veox let me know if you need any help.

Squashed commits:

spec/lexers: Solidity spec, based on tutorial's Turtle spec.

samples: add Solidity sample (from pygments-lexer-solidity).

See https://gitlab.com/veox/pygments-lexer-solidity.

File permalink:

https://gitlab.com/veox/pygments-lexer-solidity/blob/8e9919b5e9e91a2022def2a4c51003bc99042686/example.sol

The Pygments lexer's example was written by me, and is licensed
under a BSD license.

demos: minimal Solidity demo.

lexers: track solidity.rb (verbatim copy of c.rb).

lexers/solidity: proper class, extensions, other meta stuff.

lexers/solidity: added some keywords (not all!).

lexers/solidity: remove float, added types TODO.

lexers/solidity: constants, strings.

lexers/solidity: clean-up + remove function state.

lexers/solidity: complex MxN types.

lexers: fix mimetype (`text/solidity` -> `text/x-solidity`).

spec: comment guess-by-source section that makes tests fail.

Test fails because something (?) is guessed as PlainText.

lexers/solidity: add missing `assert` and `require` keywords (+ demos/solidity: rewrite).

A few more keywords may well be missing. Used

https://github.com/ethereum/solidity/blob/0a04a35a2e02437ae038af41c947b3e829946bca/libsolidity/parsing/Token.h

to check - probably should look for "preprocessor" directives, or
built-ins, or the like, - in Solidity's source tree.

demos/solidity: fix to compile.

lexers/solidity: populate builtins + remove a few more C lexer leftovers.

SQ
This is done before "porting" in changes from Pygments' lexer,
so it's out of the way.
These are "ported" from Pygments' lexer. I'm not 100% on the
terminology.
Natspec, Assembly, Yul, and some built-in functions are still
unimplemented.
This calms down Rake warnings about ambivalence.
@veox veox force-pushed the add-lexer-solidity-squashed branch from 37dd378 to dbec54a Compare March 26, 2020 17:23
Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments:

lib/rouge/lexers/solidity.rb Outdated Show resolved Hide resolved
lib/rouge/lexers/solidity.rb Outdated Show resolved Hide resolved
@veox veox requested a review from pyrmont April 3, 2020 12:48
Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one final question, I think:

lib/rouge/lexers/solidity.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this is dragging out a bit :(

lib/rouge/lexers/solidity.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@veox Sorry about the comment before. I realise now what you were going to for with the open comment rule. I've tried a different solution. What do you think?

lib/rouge/lexers/solidity.rb Outdated Show resolved Hide resolved
lib/rouge/demos/solidity Outdated Show resolved Hide resolved
lib/rouge/lexers/solidity.rb Outdated Show resolved Hide resolved
veox and others added 2 commits April 5, 2020 17:39
Outline also why there should be no multi-level comments, demonstrate
it, and allow for reasonably bloodless manual testing by removing
spaces.
Thanks @axic!

Co-Authored-By: Alex Beregszaszi <alex@rtfs.hu>
@veox
Copy link
Contributor Author

veox commented Apr 5, 2020

Argh! The check was cancelled. >_<

@pyrmont
Copy link
Contributor

pyrmont commented Apr 5, 2020

@veox No problem. I've rerun the CI test and it's all green now. Will merge this into master. Thanks for the submission!

Two visual demo cases got conflated: the initial one of multiline
comments being open until the end of file, and the new one of no
such thing as nested multiline comment blocks.

This commits separates them.
@pyrmont pyrmont merged commit 561a429 into rouge-ruby:master Apr 5, 2020
@pyrmont pyrmont removed the author-action The PR has been reviewed but action by the author is needed label Apr 5, 2020
@pyrmont
Copy link
Contributor

pyrmont commented Apr 5, 2020

Thanks for the effort, everyone. This will be part of the next release of Rouge. We have that scheduled to go out on Tuesday 14 April 🎉

@axic
Copy link

axic commented Apr 5, 2020

Thanks @veox and @pyrmont for getting this through!

mattt pushed a commit to NSHipster/rouge that referenced this pull request May 21, 2020
This commit adds a lexer for Solidity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Solidity
10 participants