solidity 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +81 -4
- data/Rakefile +2 -1
- data/lib/solidity/version.rb +1 -1
- data/lib/solidity.rb +122 -1
- metadata +17 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e72e223ba2202849d7dbb405a56b1edf7345b911813b3449bbf2059a9ebe87e5
|
4
|
+
data.tar.gz: 2aa7d53cc55bc04929440cb3c49c99b85cc3efe0a151d24f9b887c2ac6297f09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25a530da83da24bbbf6ae85bc97a4ecac8d27eb0745d2952f3f43fda6ad3422021d798edffcafc9e03afcf6bd6d0c7985103fec52caa34987ffdb5d84a8699fd
|
7
|
+
data.tar.gz: '09339328d15e47d6d9a6345f000cbc1dee7fce14dee04e14765f82add73824dbce6fa41ba0dfe1a190059b5aeef93b6c27dc3acf759f67bb0348556098f127e5'
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Solidity
|
2
2
|
|
3
|
-
solidity gem - (fuzzy) parser for
|
3
|
+
solidity gem - (fuzzy) parser for (crypto) contracts for ethereum & co.
|
4
4
|
|
5
5
|
|
6
6
|
* home :: [github.com/rubycocos/blockchain](https://github.com/rubycocos/blockchain)
|
@@ -11,17 +11,94 @@ solidity gem - (fuzzy) parser for type-safe (crypto) contracts for ethereum & co
|
|
11
11
|
|
12
12
|
|
13
13
|
|
14
|
+
|
14
15
|
## Usage
|
15
16
|
|
16
|
-
|
17
|
+
Get / generate outline from source in the solidity (`.sol`) contract programming language:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
[
|
21
|
+
"0x34625ecaa75c0ea33733a05c584f4cf112c10b6b",
|
22
|
+
"0x0cfdb3ba1694c2bb2cfacb0339ad7b1ae5932b63",
|
23
|
+
"0x031920cc2d9f5c10b444fd44009cd64f829e7be2"
|
24
|
+
].each do |addr|
|
25
|
+
|
26
|
+
path = "awesome-contracts/address/#{addr}/contract.sol"
|
27
|
+
txt = read_text( path )
|
28
|
+
|
29
|
+
parser = Solidity::Parser.new( txt )
|
30
|
+
|
31
|
+
puts "---"
|
32
|
+
puts "outline:"
|
33
|
+
puts parser.outline
|
34
|
+
|
35
|
+
## bonus: dump the pragmas (required solidity compiler versions)
|
36
|
+
puts
|
37
|
+
puts "pragmas:"
|
38
|
+
puts parser.pragmas
|
39
|
+
```
|
40
|
+
|
41
|
+
Resulting in:
|
42
|
+
|
43
|
+
```
|
44
|
+
outline:
|
45
|
+
contract NounsDescriptor is INounsDescriptor, Ownable
|
46
|
+
abstract contract Ownable is Context
|
47
|
+
library Strings
|
48
|
+
interface INounsDescriptor
|
49
|
+
interface INounsSeeder
|
50
|
+
library NFTDescriptor
|
51
|
+
library MultiPartRLEToSVG
|
52
|
+
abstract contract Context
|
53
|
+
library Base64
|
54
|
+
```
|
55
|
+
|
56
|
+
|
57
|
+
```
|
58
|
+
outline:
|
59
|
+
contract Indelible is ERC721A, ReentrancyGuard, Ownable
|
60
|
+
library DynamicBuffer
|
61
|
+
library HelperLib
|
62
|
+
library SSTORE2
|
63
|
+
library Bytecode
|
64
|
+
abstract contract Ownable is Context
|
65
|
+
abstract contract ReentrancyGuard
|
66
|
+
library Address
|
67
|
+
library Base64
|
68
|
+
abstract contract Context
|
69
|
+
library MerkleProof
|
70
|
+
contract ERC721A is IERC721A
|
71
|
+
interface IERC721A
|
72
|
+
```
|
73
|
+
|
74
|
+
|
75
|
+
```
|
76
|
+
outline:
|
77
|
+
contract CryptoZunks is Ownable, ERC721Enumerable, ERC721Burnable, ReentrancyGuard
|
78
|
+
abstract contract Ownable is Context
|
79
|
+
abstract contract ReentrancyGuard
|
80
|
+
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata
|
81
|
+
abstract contract ERC721Burnable is Context, ERC721
|
82
|
+
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable
|
83
|
+
library Strings
|
84
|
+
library EnumerableMap
|
85
|
+
library console
|
86
|
+
abstract contract Context
|
87
|
+
interface IERC721 is IERC165
|
88
|
+
interface IERC721Receiver
|
89
|
+
interface IERC721Metadata is IERC721
|
90
|
+
library Address
|
91
|
+
abstract contract ERC165 is IERC165
|
92
|
+
interface IERC165
|
93
|
+
interface IERC721Enumerable is IERC721
|
94
|
+
library EnumerableSet
|
95
|
+
```
|
17
96
|
|
18
97
|
|
19
98
|
|
20
99
|
|
21
100
|
## License
|
22
101
|
|
23
|
-
![](https://publicdomainworks.github.io/buttons/zero88x31.png)
|
24
|
-
|
25
102
|
The `solidity` scripts are dedicated to the public domain.
|
26
103
|
Use it as you please with no restrictions whatsoever.
|
27
104
|
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ Hoe.spec 'solidity' do
|
|
5
5
|
|
6
6
|
self.version = Solidity::VERSION
|
7
7
|
|
8
|
-
self.summary = "solidity - (fuzzy) parser for
|
8
|
+
self.summary = "solidity - (fuzzy) parser for (crypto) contracts for ethereum & co."
|
9
9
|
self.description = summary
|
10
10
|
|
11
11
|
self.urls = { home: 'https://github.com/rubycocos/blockchain' }
|
@@ -18,6 +18,7 @@ Hoe.spec 'solidity' do
|
|
18
18
|
self.history_file = 'CHANGELOG.md'
|
19
19
|
|
20
20
|
self.extra_deps = [
|
21
|
+
['cocos'],
|
21
22
|
]
|
22
23
|
|
23
24
|
self.licenses = ['Public Domain']
|
data/lib/solidity/version.rb
CHANGED
data/lib/solidity.rb
CHANGED
@@ -1,7 +1,128 @@
|
|
1
|
-
require '
|
1
|
+
require 'cocos'
|
2
|
+
|
2
3
|
|
3
4
|
## our own code
|
4
5
|
require_relative 'solidity/version' # note: let version always go first
|
5
6
|
|
6
7
|
|
8
|
+
|
9
|
+
|
10
|
+
module Solidity
|
11
|
+
|
12
|
+
class Parser
|
13
|
+
def initialize( txt )
|
14
|
+
@txt = txt
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
SINGLE_COMMENT_RX = %r{^[ ]*//}
|
19
|
+
MULTI_COMMENT_BEGIN_RX = %r{^[ ]*/\*}
|
20
|
+
MULTI_COMMENT_END_RX = %r{\*/[ ]*$}
|
21
|
+
|
22
|
+
ID = '[a-zA-Z][a-zA-Z0-9]*'
|
23
|
+
|
24
|
+
PRAGMA_RX = %r{^[ ]*pragma}
|
25
|
+
LIBRARY_RX = %r{^[ ]*library[ ]+(?<id>#{ID})[ \{]}
|
26
|
+
ABSTRACT_CONTRACT_RX = %r{^[ ]*abstract[ ]+contract[ ]+(?<id>#{ID})[ \{]}
|
27
|
+
CONTRACT_RX = %r{^[ ]*contract[ ]+(?<id>#{ID})[ \{]}
|
28
|
+
INTERFACE_RX = %r{^[ ]*interface[ ]+(?<id>#{ID})[ \{]}
|
29
|
+
|
30
|
+
|
31
|
+
def _quick_pass_one
|
32
|
+
tree = []
|
33
|
+
node = nil
|
34
|
+
|
35
|
+
inside_comment = false
|
36
|
+
|
37
|
+
@txt.each_line do |line|
|
38
|
+
line = line.chomp ## remove trailing newline
|
39
|
+
## pp line
|
40
|
+
|
41
|
+
if inside_comment
|
42
|
+
node[1] << line
|
43
|
+
if MULTI_COMMENT_END_RX.match( line )
|
44
|
+
tree << node
|
45
|
+
inside_comment = false
|
46
|
+
end
|
47
|
+
else
|
48
|
+
if SINGLE_COMMENT_RX.match( line ) # end-of-line comments
|
49
|
+
line = line.strip ## remove leading & trailing spaces
|
50
|
+
## note: fold end-of-line comments into a block (if not separated by newline)
|
51
|
+
node = tree[-1]
|
52
|
+
if node.is_a?( Array ) &&
|
53
|
+
node[0] == :comment && node[1][0].start_with?( '//' )
|
54
|
+
node[1] << line
|
55
|
+
else
|
56
|
+
tree << [:comment, [line]]
|
57
|
+
end
|
58
|
+
elsif MULTI_COMMENT_BEGIN_RX.match( line )
|
59
|
+
inside_comment = true
|
60
|
+
node = [:comment, [line]]
|
61
|
+
elsif PRAGMA_RX.match( line )
|
62
|
+
line = line.strip
|
63
|
+
tree << [:pragma, line]
|
64
|
+
elsif LIBRARY_RX.match( line )
|
65
|
+
line = line.strip
|
66
|
+
tree << [:library, line]
|
67
|
+
elsif ABSTRACT_CONTRACT_RX.match( line )
|
68
|
+
line = line.strip
|
69
|
+
tree << [:abstract_contract, line]
|
70
|
+
elsif CONTRACT_RX.match( line )
|
71
|
+
line = line.strip
|
72
|
+
tree << [:contract, line]
|
73
|
+
elsif INTERFACE_RX.match( line )
|
74
|
+
line = line.strip
|
75
|
+
tree << [:interface, line]
|
76
|
+
else
|
77
|
+
tree << line
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end # each_line
|
81
|
+
|
82
|
+
tree
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def outline
|
87
|
+
buf = String.new( '' )
|
88
|
+
tree = _quick_pass_one
|
89
|
+
|
90
|
+
tree.each do |node|
|
91
|
+
if node.is_a?( Array )
|
92
|
+
case node[0]
|
93
|
+
when :contract then buf << node[1] << "\n"
|
94
|
+
when :abstract_contract then buf << node[1] << "\n"
|
95
|
+
when :interface then buf << node[1] << "\n"
|
96
|
+
when :library then buf << node[1] << "\n"
|
97
|
+
else
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
buf
|
103
|
+
end
|
104
|
+
|
105
|
+
def pragmas
|
106
|
+
buf = String.new( '' )
|
107
|
+
tree = _quick_pass_one
|
108
|
+
|
109
|
+
tree.each do |node|
|
110
|
+
if node.is_a?( Array )
|
111
|
+
case node[0]
|
112
|
+
when :pragma then buf << node[1] << "\n"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
buf
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
end # class Parser
|
122
|
+
|
123
|
+
|
124
|
+
end # module Solidity
|
125
|
+
|
126
|
+
|
127
|
+
|
7
128
|
puts Solidity.banner ## say hello
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2023-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cocos
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rdoc
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,8 +58,7 @@ dependencies:
|
|
44
58
|
- - "~>"
|
45
59
|
- !ruby/object:Gem::Version
|
46
60
|
version: '3.23'
|
47
|
-
description: solidity - (fuzzy) parser for
|
48
|
-
& co.
|
61
|
+
description: solidity - (fuzzy) parser for (crypto) contracts for ethereum & co.
|
49
62
|
email: wwwmake@googlegroups.com
|
50
63
|
executables: []
|
51
64
|
extensions: []
|
@@ -84,6 +97,5 @@ requirements: []
|
|
84
97
|
rubygems_version: 3.3.7
|
85
98
|
signing_key:
|
86
99
|
specification_version: 4
|
87
|
-
summary: solidity - (fuzzy) parser for
|
88
|
-
co.
|
100
|
+
summary: solidity - (fuzzy) parser for (crypto) contracts for ethereum & co.
|
89
101
|
test_files: []
|