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
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
afd8be9
spec/lexers/sampes/demos: add Solidity lexer (squashed branch).
veox Aug 19, 2017
672ee0a
lexers/solidity: don't map/merge sets on every invocation - just the …
veox Aug 22, 2017
d5f6378
lexers/solidity: add new keywords mentioned in feedback.
veox Mar 26, 2020
e1b6522
lexers/solidity: add changes up to (mostly) Solidity v0.4.22.
veox Mar 26, 2020
e65c995
lexers/solidity: add new keywords from Solidity v0.6.0.
veox Mar 26, 2020
612c65b
samples/solidity: copy updated sample over from Pygments.
veox Mar 26, 2020
dbec54a
lexers/solidity: mark regexes in rules explicitly.
veox Mar 26, 2020
c219854
spec/solidity: uncomment and fix "test by source".
veox Mar 26, 2020
a8ee009
lexers/solidity: variables can have `$` + `string` is a type.
veox Mar 31, 2020
7692571
Fix alphabetical ordering of types
pyrmont Mar 31, 2020
9ca9556
Replace character ranges with metacharacter
pyrmont Mar 31, 2020
aded449
Fix 'uintb' typo
pyrmont Mar 31, 2020
4ba1cf7
samples/solidity: show `$` is a valid character in the visual sample.
veox Mar 31, 2020
f416146
lexers/solidity: move [u]fixed type to `reserved` + add missing `byte`.
veox Mar 31, 2020
2a14012
lexer/solidity: `receive`, `override`, `virtual` are now actual keywo…
veox Mar 31, 2020
a828d47
lexers/solidity: update `[u]fixed{M}x{N}` types to "new" scheme.
veox Mar 31, 2020
8b09d51
lexers/solidity: add missing `calldata` keyword.
veox Apr 1, 2020
5f81d9b
lexers/solidity: user regex to match [u]fixed{M}x{N} instead.
veox Apr 2, 2020
6f793ba
lexers/solidity: [u]fixed{M}x{N} should have at least one digit for M…
veox Apr 3, 2020
2242a4d
lexers/solidity: use regex for bytes{N} and [u]int{N}, too.
veox Apr 3, 2020
d7ccc70
lexers/solidity: remove duplicate rule for (block|msg|tx).{stuff}.
veox Apr 3, 2020
f19341e
lexers/solidity: catch case of unclosed multi-line comment.
veox Apr 4, 2020
8b42435
spec/solidity: update with less incorrect language syntax.
veox Apr 4, 2020
6d46215
Add nested comments
pyrmont Apr 5, 2020
c8d3f3f
Add state for multiline comments
pyrmont Apr 5, 2020
2e824fa
Simplify demo
pyrmont Apr 5, 2020
b56f33c
Remove nested closing comments
pyrmont Apr 5, 2020
479a6d2
Remove nesting rule from comment state
pyrmont Apr 5, 2020
8b471bb
samples/solidity: make example of comment-to-EOF more wordy.
veox Apr 5, 2020
103718e
lexers/solidity: add missing `abi.decode`.
veox Apr 5, 2020
1555984
samples/solidity: split no-multiline-nesting and multiline-to-eof cases.
veox Apr 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions lib/rouge/demos/solidity
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ interface IMirror {
contract Mirror is IMirror {
event logMessage(address indexed sender, uint256 value, uint256 gas, bytes data);

function reflect() external payable returns(bool retval) {
assert(msg.sender != address(this));
require(msg.value != 0);

IMirror rorrim = IMirror(msg.sender);
retval = rorrim.reflect.value(msg.value).gas(msg.gas)();

logMessage(msg.sender, msg.value, msg.gas, msg.data);
return retval;
}

pyrmont marked this conversation as resolved.
Show resolved Hide resolved
function () { // no funny stuff
revert();
}
Expand Down
10 changes: 8 additions & 2 deletions lib/rouge/lexers/solidity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def self.reserved
state :inline_whitespace do
rule %r/[ \t\r]+/, Text
rule %r/\\\n/, Text # line continuation
rule %r(/[*].*?[*]/)m, Comment::Multiline
rule %r(/\*.*(\*/){0})m, Comment::Multiline # open to EOF
rule %r(/\*), Comment::Multiline, :comment_multi
end

state :whitespace do
Expand Down Expand Up @@ -175,6 +174,13 @@ def self.reserved
rule %r/\'/, Str, :pop!
rule %r/\"/, Str
end

state :comment_multi do
rule %r(\*/), Comment::Multiline, :pop!
rule %r(/\*), Comment::Multiline, :comment_multi
rule %r([^*/]+), Comment::Multiline
rule %r([*/]), Comment::Multiline
end
pyrmont marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
4 changes: 2 additions & 2 deletions spec/visual/samples/solidity
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ contract MoreBadPractices is BadPractices {
* /
\* /

/ * no modifiers to check ownership * /
/* no modifiers to check ownership */
fallback() external payable {
balance += msg.value;

/ * vulnerable to re-entry * /
/* vulnerable to re-entry */
if (!msg.sender.send(this.balance / 10)) throw;
balance -= this.balance;
}
Expand Down