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 2 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
3 changes: 2 additions & 1 deletion lib/rouge/lexers/solidity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def self.reserved
state :inline_whitespace do
rule %r/[ \t\r]+/, Text
rule %r/\\\n/, Text # line continuation
rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
rule %r(/[*].*?[*]/)m, Comment::Multiline
rule %r(/\*.*(\*/){0})m, Comment::Multiline # open to EOF
pyrmont marked this conversation as resolved.
Show resolved Hide resolved
end

state :whitespace do
Expand Down
23 changes: 13 additions & 10 deletions spec/visual/samples/solidity
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pragma experimental SMTChecker;
/* Comments relevant to the code are multi-line. */

library Assembly {
public function junk(address _addr) private returns (address _ret) {
function junk(address _addr) private returns (address _ret) {
assembly {
let tmp := 0

Expand Down Expand Up @@ -51,7 +51,7 @@ and it's multi-line. // no comment"; // comment ok // even nested :)
and it\'s multi-line. // no comment'; // same thing, single-quote
string hexstr = hex'537472696e67732e73656e6428746869732e62616c616e6365293b';

fallback() external {}
fallback() external payable virtual {}

receive() external payable {
revert();
Expand Down Expand Up @@ -83,7 +83,7 @@ contract Types is Strings {
string str; // dynamic array (not a value-type)
bytes bs; // same as above
//var v = 5; // `var` is a keyword, not a type, and compiler chokes
var unu$ed; // `var` is highlighted, though, and `$` is a valid char
uint unu$ed; // `var` is highlighted, though, and `$` is a valid char

address a = "0x1"; // lexer parses as string
struct AddressMap {
Expand All @@ -94,25 +94,25 @@ contract Types is Strings {
}
mapping (address => AddressMap) touchedMe;

public function failOnNegative(int8 _arg)
function failOnNegative(int8 _arg)
private
constant
pure
returns (uint256)
{
/* implicit type conversion from `int8` to `uint256` */
return _arg;
}

// some arithmetic operators + built-in names
public function opportunisticSend(address k) private {
function opportunisticSend(address k) private {
/* `touchedMe[k].result` et al are addresses, so
`send()` available */
touchedMe[k].origin.send(k**2 % 100 finney);
touchedMe[k].origin.send(uint256(k)**2 % 100 finney);
touchedMe[k].result.send(1 wei);
touchedMe[k].sender.send(mulmod(1 szabo, k, 42));
}

fallback() external payable {
fallback() external payable override {
/* inferred type: address */
var k = msg.sender;
/* inferred type: `ufixed0x256` */
Expand Down Expand Up @@ -178,13 +178,14 @@ contract BadPractices {
mutex = false;
}

constructor {
constructor() external {
creator = tx.origin;
owner = msg.sender;
}

/* Dangerous - function public, and doesn't check who's calling. */
public function withdraw(uint _amount)
function withdraw(uint _amount)
public
critical
returns (bool)
{ /* `mutex` set via modifier */
Expand All @@ -203,6 +204,8 @@ contract BadPractices {
owner++;
}
}

/* receive()?.. nah, why bother */
}

/*
Expand Down