solidity 0.1.2 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2450cdadc297a615031d2a910fc70e39b6a29514ee4387e532bb3a7febec7fb4
4
- data.tar.gz: 572f8c43f7cc641fc3d970b00287eec3e9adf7412ad046950d0bfa116930822c
3
+ metadata.gz: 3920e32ab53156b256507811437d64f62f38bd42472aecb5c51a4fd3eb2f57e1
4
+ data.tar.gz: 4a5c36c583ba102881417af5d184c6351ef9d6a1f20154ab6096fb4722694bc6
5
5
  SHA512:
6
- metadata.gz: 2cdb28abe2cafb57f53df2d07af8a61c0f4c80177b0267bd7de2fa1afb96d423ff2399d628f11f34edd6896eaaeb4af3ebed5aa2b3489817c49c20560a536818
7
- data.tar.gz: bcef0cdea7f22b7960db8269738d612d6a51f46626560762e8e85ffd52dc343e8a3d652de74b1d4c6ca89ee98fe7a1066a4de85535b5c704e1d6aa732bef7033
6
+ metadata.gz: b7227cdec56deceba0230c0f8946ea0182e2e144919bb2b0227d52a19c4085d89a0b2f3a62c796b162c9fba59880d5ee1cb154bfc0f5de1455cb4bd353d4602d
7
+ data.tar.gz: 9840c43aade93aaec0b0222c2db7dc4f50246565da9e52c69363fe599e43bed8e0e800ac31349a846ab7cfeb4e28126bde9fcfd8d6a85b884d9d26240b1fc35b
data/Manifest.txt CHANGED
@@ -3,4 +3,5 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/solidity.rb
6
+ lib/solidity/parser.rb
6
7
  lib/solidity/version.rb
data/README.md CHANGED
@@ -1,3 +1,20 @@
1
+
2
+ ---
3
+
4
+ _The Ruby Programming Language for Contract / Transaction Scripts on the Blockchain World Computer - Yes, It's Just Ruby_
5
+
6
+ **sruby - Small, Smart, Secure, Safe, Solid & Sound (S6) Ruby**
7
+
8
+ sruby is a subset of mruby that is a subset of "classic" ruby.
9
+
10
+
11
+ For more see the [**Red Paper »**](https://github.com/s6ruby/redpaper)
12
+
13
+ ---
14
+
15
+
16
+
17
+
1
18
  # Solidity
2
19
 
3
20
  solidity gem - (fuzzy) parser for (crypto) contracts for ethereum & co.
@@ -10,12 +27,34 @@ solidity gem - (fuzzy) parser for (crypto) contracts for ethereum & co.
10
27
 
11
28
 
12
29
 
30
+ ## New to the Solidity (Contract) Programming Language?
31
+
32
+ _Official_
33
+
34
+ Solidity Language @ <https://soliditylang.org>
35
+
36
+ - Read the Docs @ <https://docs.soliditylang.org/en/latest/>
37
+ - Blog @ <https://blog.soliditylang.org>
38
+ - Forum @ <https://forum.soliditylang.org>
39
+ - Source @ <https://github.com/ethereum/solidity>
40
+
41
+ <!-- break -->
42
+
43
+ _More_
44
+
45
+ Solidity by Example @ <https://solidity-by-example.org>
46
+
47
+ Learn X in Y Minutes (Where X=Solidity) @ <https://learnxinyminutes.com/docs/solidity>
48
+
49
+ Awesome Solidity @ <https://github.com/bkrem/awesome-solidity>
50
+
51
+
52
+
13
53
 
14
54
 
15
55
  ## Usage
16
56
 
17
57
  Get / generate outline from source in the solidity (`.sol`) contract programming language:
18
-
19
58
  ```ruby
20
59
  [
21
60
  "0x34625ecaa75c0ea33733a05c584f4cf112c10b6b",
@@ -52,6 +91,36 @@ library Base64
52
91
  ```
53
92
 
54
93
 
94
+ Note: The outline includes:
95
+
96
+ 1. contract definitions e.g.
97
+
98
+ contract NounsDescriptor is INounsDescriptor, Ownable
99
+
100
+ 2. abstract contract definitions e.g.
101
+
102
+ abstract contract Ownable is Context
103
+ abstract contract Context
104
+
105
+ 3. library definitions e.g.
106
+
107
+ library Strings
108
+ library NFTDescriptor
109
+ library MultiPartRLEToSVG
110
+ library Base64
111
+
112
+ 4. interface definitions e.g.
113
+
114
+ interface INounsDescriptor
115
+ interface INounsSeeder
116
+
117
+
118
+
119
+
120
+ <!-- break -->
121
+
122
+ More outline samples:
123
+
55
124
  ```
56
125
  outline:
57
126
  contract Indelible is ERC721A, ReentrancyGuard, Ownable
@@ -96,6 +165,15 @@ library EnumerableSet
96
165
 
97
166
 
98
167
 
168
+
169
+ ## Bonus: Solidity (Fuzzy) Parser in the Wild / Real-World
170
+
171
+ See [**Awesome (Ethereum) Contracts @ Open Blockchains »**](https://github.com/openblockchains/awesome-contracts)
172
+
173
+ Add your usage here. Yes, you can.
174
+
175
+
176
+
99
177
  ## License
100
178
 
101
179
  The `solidity` scripts are dedicated to the public domain.
data/Rakefile CHANGED
@@ -1,6 +1,15 @@
1
1
  require 'hoe'
2
2
  require './lib/solidity/version.rb'
3
3
 
4
+
5
+ ###
6
+ # hack/ quick fix for broken intuit_values - overwrite with dummy
7
+ class Hoe
8
+ def intuit_values( input ); end
9
+ end
10
+
11
+
12
+
4
13
  Hoe.spec 'solidity' do
5
14
 
6
15
  self.version = Solidity::VERSION
@@ -0,0 +1,217 @@
1
+ module Solidity
2
+
3
+ class Parser
4
+
5
+ def self.read( path )
6
+ txt = read_text( path )
7
+ new( txt )
8
+ end
9
+
10
+
11
+
12
+ def initialize( txt )
13
+ @txt = txt
14
+ end
15
+
16
+
17
+ ###############
18
+ ## quotes
19
+ ##
20
+ ## note: regex pattern \\ needs to get escaped twice, thus, \\.
21
+ ## and for literal \\ use \\\\\.
22
+
23
+ ## => \\\\. -- allow backslash escapes e.g. \n \t \\ etc.
24
+ ## => [^`] -- everything except backquote
25
+
26
+ ## todo/fix - check if [^`] includes/matches newline too (yes)? -- add \n for multi-line!
27
+
28
+
29
+ ## from the solidity grammar
30
+ ##
31
+ ## StringLiteralFragment
32
+ ## : 'unicode'? '"' DoubleQuotedStringCharacter* '"'
33
+ ## | 'unicode'? '\'' SingleQuotedStringCharacter* '\'' ;
34
+ ##
35
+ ## fragment
36
+ ## DoubleQuotedStringCharacter
37
+ ## : ~["\r\n\\] | ('\\' .) ;
38
+ ##
39
+ ## fragment
40
+ ## SingleQuotedStringCharacter
41
+ ## : ~['\r\n\\] | ('\\' .) ;
42
+
43
+
44
+ SINGLE_QUOTE = %r{'
45
+ ( \\\\. | [^'] )*
46
+ '}x
47
+
48
+ DOUBLE_QUOTE = %r{"
49
+ ( \\\\. | [^"] )*
50
+ "}x
51
+
52
+
53
+ ## from the solidity grammar
54
+ ## > An identifier in solidity has to start with a letter,
55
+ ## > a dollar-sign or an underscore and
56
+ ## > may additionally contain numbers after the first symbol.
57
+ ##
58
+ ## Identifier
59
+ ## : IdentifierStart IdentifierPart* ;
60
+ ##
61
+ ## fragment
62
+ ## IdentifierStart
63
+ ## : [a-zA-Z$_] ;
64
+ ##
65
+ ## fragment
66
+ ## IdentifierPart
67
+ ## : [a-zA-Z0-9$_] ;
68
+
69
+ NAME = /[a-zA-Z$_][a-zA-Z0-9$_]*/
70
+
71
+
72
+ END_OF_LINE = /\n|$/
73
+ ## inline comments (multi- or end-of-line)
74
+ END_OF_LINE_OR_COMMENT_OR_KEYWORD_OR_QUOTE = / \n
75
+ | $
76
+ | (?=['"])
77
+ | (?=\/(\/|\*))
78
+ | (?=\bpragma\b)
79
+ | (?=\bcontract\b)
80
+ | (?=\babstract\b)
81
+ | (?=\blibrary\b)
82
+ | (?=\binterface\b)
83
+ /x
84
+
85
+
86
+ ## from the solidity grammar
87
+ ##
88
+ ## COMMENT
89
+ ## : '/*' .*? '*/' ;
90
+ ##
91
+ ## LINE_COMMENT
92
+ ## : '//' ~[\r\n]* ;
93
+
94
+
95
+
96
+ def _norm_whitespace( str )
97
+ ## change newlines to spaces and
98
+ ## all multiple spaces to one
99
+ str = str.gsub( /[ \t\n\r]+/, ' ' )
100
+ str.strip
101
+ end
102
+
103
+ def _quick_pass_one
104
+ ## note: CANNOT handle inline comments
105
+ ## in pragma, contract, etc. (get "silently" slurped)
106
+ ## report a parse error - if comments slurped - why? why not?
107
+ ##
108
+
109
+
110
+ tree = []
111
+
112
+ s = StringScanner.new( @txt )
113
+
114
+ loop do
115
+ s.skip( /[ \t]+/ ) ## note: do NOT skip newlines here; pass along blank/empty lines for now - why? why not?
116
+ if s.check( "'" ) ## single-quoted string
117
+ str = s.scan( SINGLE_QUOTE )
118
+ tree << [:string, str]
119
+ elsif s.check( '"' ) ## double-quoted string
120
+ str = s.scan( DOUBLE_QUOTE )
121
+ tree << [:string, str]
122
+ elsif s.check( '/*' )
123
+ comment = s.scan_until( /\*\// )
124
+ ## print "multi-line comment:"
125
+ ## pp comment
126
+ tree << [:comment, comment]
127
+ elsif s.check( '//' )
128
+ comment = s.scan_until( END_OF_LINE ).rstrip
129
+ ## print "comment:"
130
+ ## pp comment
131
+ tree << [:comment, comment]
132
+ else
133
+ name = s.check( NAME )
134
+ case name
135
+ when 'pragma'
136
+ code = s.scan_until( /;/ )
137
+ code = _norm_whitespace( code )
138
+ ## print "pragma:"
139
+ ## pp code
140
+ tree << [:pragma, code]
141
+ when 'contract'
142
+ code = s.scan_until( /(?=\{)/ )
143
+ code = _norm_whitespace( code )
144
+ ## print "contract:"
145
+ ## pp code
146
+ tree << [:contract, code]
147
+ when 'abstract'
148
+ code = s.scan_until( /(?=\{)/ )
149
+ code = _norm_whitespace( code )
150
+ ## print "abstract contract:"
151
+ ## pp code
152
+ tree << [:abstract_contract, code]
153
+ when 'library'
154
+ code = s.scan_until( /(?=\{)/ )
155
+ code = _norm_whitespace( code )
156
+ ## print "library:"
157
+ ## pp code
158
+ tree << [:library, code]
159
+ when 'interface'
160
+ code = s.scan_until( /(?=\{)/ )
161
+ code = _norm_whitespace( code )
162
+ ## print "interface:"
163
+ ## pp code
164
+ tree << [:interface, code]
165
+ else
166
+ ## slurp chunk ,that is, until newline or comment or tracked keyword
167
+ chunk = s.scan_until( END_OF_LINE_OR_COMMENT_OR_KEYWORD_OR_QUOTE ).rstrip
168
+ ## puts "chunk: >#{chunk.inspect}<"
169
+ tree << chunk
170
+ end
171
+ end
172
+ break if s.eos?
173
+ end
174
+
175
+ tree
176
+ end
177
+
178
+
179
+ def outline
180
+ buf = String.new( '' )
181
+ tree = _quick_pass_one
182
+
183
+ tree.each do |node|
184
+ if node.is_a?( Array )
185
+ case node[0]
186
+ when :contract then buf << node[1] << "\n"
187
+ when :abstract_contract then buf << node[1] << "\n"
188
+ when :interface then buf << node[1] << "\n"
189
+ when :library then buf << node[1] << "\n"
190
+ else
191
+ end
192
+ end
193
+ end
194
+
195
+ buf
196
+ end
197
+
198
+ def pragmas
199
+ buf = String.new( '' )
200
+ tree = _quick_pass_one
201
+
202
+ tree.each do |node|
203
+ if node.is_a?( Array )
204
+ case node[0]
205
+ when :pragma then buf << node[1] << "\n"
206
+ end
207
+ end
208
+ end
209
+
210
+ buf
211
+ end
212
+
213
+
214
+ end # class Parser
215
+
216
+
217
+ end # module Solidity
@@ -1,9 +1,8 @@
1
1
 
2
2
  module Solidity
3
-
4
3
  MAJOR = 0
5
4
  MINOR = 1
6
- PATCH = 2
5
+ PATCH = 4
7
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
7
 
9
8
  def self.version
data/lib/solidity.rb CHANGED
@@ -3,184 +3,9 @@ require 'cocos'
3
3
 
4
4
  ## our own code
5
5
  require_relative 'solidity/version' # note: let version always go first
6
+ require_relative 'solidity/parser'
6
7
 
7
8
 
8
9
 
9
10
 
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
-
186
11
  puts Solidity.banner ## say hello
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
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-30 00:00:00.000000000 Z
11
+ date: 2023-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocos
@@ -72,6 +72,7 @@ files:
72
72
  - README.md
73
73
  - Rakefile
74
74
  - lib/solidity.rb
75
+ - lib/solidity/parser.rb
75
76
  - lib/solidity/version.rb
76
77
  homepage: https://github.com/rubycocos/blockchain
77
78
  licenses: