-
Notifications
You must be signed in to change notification settings - Fork 743
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
Conversation
To be transparent: Solidity's not in github's 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. |
Any chance of this getting merged? It'd be really handy. |
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! ❤️ |
Is there any chance this will ever get merged or what is holding this back @jneen @dblessing ? |
Would love to see this merged too... |
Actually linguist merged the PR on 12th Jan 2018: github-linguist/linguist#3973 |
@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. |
@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 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. |
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.) |
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.
37dd378
to
dbec54a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments:
They are already covered in `def self.builtins`.
There was a problem hiding this 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:
There was a problem hiding this 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 :(
There was a problem hiding this 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?
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>
Argh! The check was cancelled. >_< |
@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.
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 🎉 |
This commit adds a lexer for Solidity.
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 indemos
was written specifically for Rouge.Compared to the linked Pygments lexer, the one here has
moreless up-to-date keywords,butand doesn't have a distinctassembly
state (yet). This is not a big issue: the low-level assembly keywords (e.g.let
) are listed (inself.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 pageThis fixes #987.