solidity 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +80 -4
- data/Rakefile +2 -1
- data/lib/solidity/version.rb +1 -1
- data/lib/solidity.rb +180 -1
- metadata +18 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2450cdadc297a615031d2a910fc70e39b6a29514ee4387e532bb3a7febec7fb4
|
4
|
+
data.tar.gz: 572f8c43f7cc641fc3d970b00287eec3e9adf7412ad046950d0bfa116930822c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cdb28abe2cafb57f53df2d07af8a61c0f4c80177b0267bd7de2fa1afb96d423ff2399d628f11f34edd6896eaaeb4af3ebed5aa2b3489817c49c20560a536818
|
7
|
+
data.tar.gz: bcef0cdea7f22b7960db8269738d612d6a51f46626560762e8e85ffd52dc343e8a3d652de74b1d4c6ca89ee98fe7a1066a4de85535b5c704e1d6aa732bef7033
|
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,93 @@ 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
|
+
parser = Solidity::Parser.read( path )
|
28
|
+
|
29
|
+
puts "---"
|
30
|
+
puts "outline:"
|
31
|
+
puts parser.outline
|
32
|
+
|
33
|
+
## bonus: dump the pragmas (required solidity compiler versions)
|
34
|
+
puts
|
35
|
+
puts "pragmas:"
|
36
|
+
puts parser.pragmas
|
37
|
+
```
|
38
|
+
|
39
|
+
Resulting in:
|
40
|
+
|
41
|
+
```
|
42
|
+
outline:
|
43
|
+
contract NounsDescriptor is INounsDescriptor, Ownable
|
44
|
+
abstract contract Ownable is Context
|
45
|
+
library Strings
|
46
|
+
interface INounsDescriptor
|
47
|
+
interface INounsSeeder
|
48
|
+
library NFTDescriptor
|
49
|
+
library MultiPartRLEToSVG
|
50
|
+
abstract contract Context
|
51
|
+
library Base64
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
```
|
56
|
+
outline:
|
57
|
+
contract Indelible is ERC721A, ReentrancyGuard, Ownable
|
58
|
+
library DynamicBuffer
|
59
|
+
library HelperLib
|
60
|
+
library SSTORE2
|
61
|
+
library Bytecode
|
62
|
+
abstract contract Ownable is Context
|
63
|
+
abstract contract ReentrancyGuard
|
64
|
+
library Address
|
65
|
+
library Base64
|
66
|
+
abstract contract Context
|
67
|
+
library MerkleProof
|
68
|
+
interface ERC721A__IERC721Receiver
|
69
|
+
contract ERC721A is IERC721A
|
70
|
+
interface IERC721A
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
```
|
75
|
+
outline:
|
76
|
+
contract CryptoZunks is Ownable, ERC721Enumerable, ERC721Burnable, ReentrancyGuard
|
77
|
+
abstract contract Ownable is Context
|
78
|
+
abstract contract ReentrancyGuard
|
79
|
+
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata
|
80
|
+
abstract contract ERC721Burnable is Context, ERC721
|
81
|
+
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable
|
82
|
+
library Strings
|
83
|
+
library EnumerableMap
|
84
|
+
library console
|
85
|
+
abstract contract Context
|
86
|
+
interface IERC721 is IERC165
|
87
|
+
interface IERC721Receiver
|
88
|
+
interface IERC721Metadata is IERC721
|
89
|
+
library Address
|
90
|
+
abstract contract ERC165 is IERC165
|
91
|
+
interface IERC165
|
92
|
+
interface IERC721Enumerable is IERC721
|
93
|
+
library EnumerableSet
|
94
|
+
```
|
17
95
|
|
18
96
|
|
19
97
|
|
20
98
|
|
21
99
|
## License
|
22
100
|
|
23
|
-

|
24
|
-
|
25
101
|
The `solidity` scripts are dedicated to the public domain.
|
26
102
|
Use it as you please with no restrictions whatsoever.
|
27
103
|
|
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,186 @@
|
|
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
|
+
|
14
|
+
def self.read( path )
|
15
|
+
txt = read_text( path )
|
16
|
+
new( txt )
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
def initialize( txt )
|
22
|
+
@txt = txt
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
###############
|
27
|
+
## quotes
|
28
|
+
##
|
29
|
+
## note: regex pattern \\ needs to get escaped twice, thus, \\.
|
30
|
+
## and for literal \\ use \\\\\.
|
31
|
+
|
32
|
+
## => \\\\. -- allow backslash escapes e.g. \n \t \\ etc.
|
33
|
+
## => [^`] -- everything except backquote
|
34
|
+
|
35
|
+
## todo/fix - check if [^`] includes/matches newline too (yes)? -- add \n for multi-line!
|
36
|
+
|
37
|
+
SINGLE_QUOTE = %r{'
|
38
|
+
( \\\\. | [^'] )*
|
39
|
+
'}x
|
40
|
+
|
41
|
+
DOUBLE_QUOTE = %r{"
|
42
|
+
( \\\\. | [^"] )*
|
43
|
+
"}x
|
44
|
+
|
45
|
+
|
46
|
+
NAME = /[a-zA-Z][a-zA-Z0-9_]*/
|
47
|
+
END_OF_LINE = /\n|$/
|
48
|
+
## inline comments (multi- or end-of-line)
|
49
|
+
END_OF_LINE_OR_COMMENT_OR_KEYWORD_OR_QUOTE = / \n
|
50
|
+
| $
|
51
|
+
| (?=['"])
|
52
|
+
| (?=\/(\/|\*))
|
53
|
+
| (?=pragma\b)
|
54
|
+
| (?=contract\b)
|
55
|
+
| (?=abstract\b)
|
56
|
+
| (?=library\b)
|
57
|
+
| (?=interface\b)
|
58
|
+
/x
|
59
|
+
|
60
|
+
|
61
|
+
def _norm_whitespace( str )
|
62
|
+
## change newlines to spaces and
|
63
|
+
## all multiple spaces to one
|
64
|
+
str = str.gsub( /[ \t\n\r]+/, ' ' )
|
65
|
+
str.strip
|
66
|
+
end
|
67
|
+
|
68
|
+
def _quick_pass_one
|
69
|
+
## note: CANNOT handle inline comments
|
70
|
+
## in pragma, contract, etc. (get "silently" slurped)
|
71
|
+
## report a parse error - if comments slurped - why? why not?
|
72
|
+
##
|
73
|
+
|
74
|
+
|
75
|
+
tree = []
|
76
|
+
|
77
|
+
s = StringScanner.new( @txt )
|
78
|
+
|
79
|
+
loop do
|
80
|
+
s.skip( /[ \t]+/ ) ## note: do NOT skip newlines here; pass along blank/empty lines for now - why? why not?
|
81
|
+
if s.check( "'" ) ## single-quoted string
|
82
|
+
str = s.scan( SINGLE_QUOTE )
|
83
|
+
tree << [:string, str]
|
84
|
+
elsif s.check( '"' ) ## double-quoted string
|
85
|
+
str = s.scan( DOUBLE_QUOTE )
|
86
|
+
tree << [:string, str]
|
87
|
+
elsif s.check( '/*' )
|
88
|
+
comment = s.scan_until( /\*\// )
|
89
|
+
## print "multi-line comment:"
|
90
|
+
## pp comment
|
91
|
+
tree << [:comment, comment]
|
92
|
+
elsif s.check( '//' )
|
93
|
+
comment = s.scan_until( END_OF_LINE ).rstrip
|
94
|
+
## print "comment:"
|
95
|
+
## pp comment
|
96
|
+
tree << [:comment, comment]
|
97
|
+
else
|
98
|
+
name = s.check( NAME )
|
99
|
+
case name
|
100
|
+
when 'pragma'
|
101
|
+
code = s.scan_until( /;/ )
|
102
|
+
code = _norm_whitespace( code )
|
103
|
+
## print "pragma:"
|
104
|
+
## pp code
|
105
|
+
tree << [:pragma, code]
|
106
|
+
when 'contract'
|
107
|
+
code = s.scan_until( /(?=\{)/ )
|
108
|
+
code = _norm_whitespace( code )
|
109
|
+
## print "contract:"
|
110
|
+
## pp code
|
111
|
+
tree << [:contract, code]
|
112
|
+
when 'abstract'
|
113
|
+
code = s.scan_until( /(?=\{)/ )
|
114
|
+
code = _norm_whitespace( code )
|
115
|
+
## print "abstract contract:"
|
116
|
+
## pp code
|
117
|
+
tree << [:abstract_contract, code]
|
118
|
+
when 'library'
|
119
|
+
code = s.scan_until( /(?=\{)/ )
|
120
|
+
code = _norm_whitespace( code )
|
121
|
+
## print "library:"
|
122
|
+
## pp code
|
123
|
+
tree << [:library, code]
|
124
|
+
when 'interface'
|
125
|
+
code = s.scan_until( /(?=\{)/ )
|
126
|
+
code = _norm_whitespace( code )
|
127
|
+
## print "interface:"
|
128
|
+
## pp code
|
129
|
+
tree << [:interface, code]
|
130
|
+
else
|
131
|
+
## slurp chunk ,that is, until newline or comment or tracked keyword
|
132
|
+
chunk = s.scan_until( END_OF_LINE_OR_COMMENT_OR_KEYWORD_OR_QUOTE ).rstrip
|
133
|
+
## puts "chunk: >#{chunk.inspect}<"
|
134
|
+
tree << chunk
|
135
|
+
end
|
136
|
+
end
|
137
|
+
break if s.eos?
|
138
|
+
end
|
139
|
+
|
140
|
+
tree
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
def outline
|
145
|
+
buf = String.new( '' )
|
146
|
+
tree = _quick_pass_one
|
147
|
+
|
148
|
+
tree.each do |node|
|
149
|
+
if node.is_a?( Array )
|
150
|
+
case node[0]
|
151
|
+
when :contract then buf << node[1] << "\n"
|
152
|
+
when :abstract_contract then buf << node[1] << "\n"
|
153
|
+
when :interface then buf << node[1] << "\n"
|
154
|
+
when :library then buf << node[1] << "\n"
|
155
|
+
else
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
buf
|
161
|
+
end
|
162
|
+
|
163
|
+
def pragmas
|
164
|
+
buf = String.new( '' )
|
165
|
+
tree = _quick_pass_one
|
166
|
+
|
167
|
+
tree.each do |node|
|
168
|
+
if node.is_a?( Array )
|
169
|
+
case node[0]
|
170
|
+
when :pragma then buf << node[1] << "\n"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
buf
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
end # class Parser
|
180
|
+
|
181
|
+
|
182
|
+
end # module Solidity
|
183
|
+
|
184
|
+
|
185
|
+
|
7
186
|
puts Solidity.banner ## say hello
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-30 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: []
|