solidity 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2450cdadc297a615031d2a910fc70e39b6a29514ee4387e532bb3a7febec7fb4
4
- data.tar.gz: 572f8c43f7cc641fc3d970b00287eec3e9adf7412ad046950d0bfa116930822c
3
+ metadata.gz: 7a34efb053c8fd9211832cedb2a99a05362f10fb3e43323d6bca7cd69783a88d
4
+ data.tar.gz: 3e113d90344d4a4745836b3b8bea5f18f4ac3c621d56914e5610c331f25dba20
5
5
  SHA512:
6
- metadata.gz: 2cdb28abe2cafb57f53df2d07af8a61c0f4c80177b0267bd7de2fa1afb96d423ff2399d628f11f34edd6896eaaeb4af3ebed5aa2b3489817c49c20560a536818
7
- data.tar.gz: bcef0cdea7f22b7960db8269738d612d6a51f46626560762e8e85ffd52dc343e8a3d652de74b1d4c6ca89ee98fe7a1066a4de85535b5c704e1d6aa732bef7033
6
+ metadata.gz: ea91690f94b665991f5f2e6934def21c1dd70ac475efc1e6cd578d84a05e31a7437dac0c1c3f9bffecb1283655ba3454d663f04a4ff190246ce240b4ea900535
7
+ data.tar.gz: f8b3f08e0691d3cfc34b25ab6652a632f41df90a6d0d593f699971886301a329fcb4f6fac048d3d041432d446030b89338cf9cabd01239a00a4a69aa50de9c45
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,6 +27,29 @@ 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
@@ -96,6 +136,15 @@ library EnumerableSet
96
136
 
97
137
 
98
138
 
139
+
140
+ ## Bonus: Solidity (Fuzzy) Parser in the Wild / Real-World
141
+
142
+ See [**Awesome (Ethereum) Contracts @ Open Blockchains »**](https://github.com/openblockchains/awesome-contracts)
143
+
144
+ Add your usage here. Yes, you can.
145
+
146
+
147
+
99
148
  ## License
100
149
 
101
150
  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,173 @@
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
+ SINGLE_QUOTE = %r{'
29
+ ( \\\\. | [^'] )*
30
+ '}x
31
+
32
+ DOUBLE_QUOTE = %r{"
33
+ ( \\\\. | [^"] )*
34
+ "}x
35
+
36
+
37
+ NAME = /[a-zA-Z][a-zA-Z0-9_]*/
38
+ END_OF_LINE = /\n|$/
39
+ ## inline comments (multi- or end-of-line)
40
+ END_OF_LINE_OR_COMMENT_OR_KEYWORD_OR_QUOTE = / \n
41
+ | $
42
+ | (?=['"])
43
+ | (?=\/(\/|\*))
44
+ | (?=\bpragma\b)
45
+ | (?=\bcontract\b)
46
+ | (?=\babstract\b)
47
+ | (?=\blibrary\b)
48
+ | (?=\binterface\b)
49
+ /x
50
+
51
+
52
+ def _norm_whitespace( str )
53
+ ## change newlines to spaces and
54
+ ## all multiple spaces to one
55
+ str = str.gsub( /[ \t\n\r]+/, ' ' )
56
+ str.strip
57
+ end
58
+
59
+ def _quick_pass_one
60
+ ## note: CANNOT handle inline comments
61
+ ## in pragma, contract, etc. (get "silently" slurped)
62
+ ## report a parse error - if comments slurped - why? why not?
63
+ ##
64
+
65
+
66
+ tree = []
67
+
68
+ s = StringScanner.new( @txt )
69
+
70
+ loop do
71
+ s.skip( /[ \t]+/ ) ## note: do NOT skip newlines here; pass along blank/empty lines for now - why? why not?
72
+ if s.check( "'" ) ## single-quoted string
73
+ str = s.scan( SINGLE_QUOTE )
74
+ tree << [:string, str]
75
+ elsif s.check( '"' ) ## double-quoted string
76
+ str = s.scan( DOUBLE_QUOTE )
77
+ tree << [:string, str]
78
+ elsif s.check( '/*' )
79
+ comment = s.scan_until( /\*\// )
80
+ ## print "multi-line comment:"
81
+ ## pp comment
82
+ tree << [:comment, comment]
83
+ elsif s.check( '//' )
84
+ comment = s.scan_until( END_OF_LINE ).rstrip
85
+ ## print "comment:"
86
+ ## pp comment
87
+ tree << [:comment, comment]
88
+ else
89
+ name = s.check( NAME )
90
+ case name
91
+ when 'pragma'
92
+ code = s.scan_until( /;/ )
93
+ code = _norm_whitespace( code )
94
+ ## print "pragma:"
95
+ ## pp code
96
+ tree << [:pragma, code]
97
+ when 'contract'
98
+ code = s.scan_until( /(?=\{)/ )
99
+ code = _norm_whitespace( code )
100
+ ## print "contract:"
101
+ ## pp code
102
+ tree << [:contract, code]
103
+ when 'abstract'
104
+ code = s.scan_until( /(?=\{)/ )
105
+ code = _norm_whitespace( code )
106
+ ## print "abstract contract:"
107
+ ## pp code
108
+ tree << [:abstract_contract, code]
109
+ when 'library'
110
+ code = s.scan_until( /(?=\{)/ )
111
+ code = _norm_whitespace( code )
112
+ ## print "library:"
113
+ ## pp code
114
+ tree << [:library, code]
115
+ when 'interface'
116
+ code = s.scan_until( /(?=\{)/ )
117
+ code = _norm_whitespace( code )
118
+ ## print "interface:"
119
+ ## pp code
120
+ tree << [:interface, code]
121
+ else
122
+ ## slurp chunk ,that is, until newline or comment or tracked keyword
123
+ chunk = s.scan_until( END_OF_LINE_OR_COMMENT_OR_KEYWORD_OR_QUOTE ).rstrip
124
+ ## puts "chunk: >#{chunk.inspect}<"
125
+ tree << chunk
126
+ end
127
+ end
128
+ break if s.eos?
129
+ end
130
+
131
+ tree
132
+ end
133
+
134
+
135
+ def outline
136
+ buf = String.new( '' )
137
+ tree = _quick_pass_one
138
+
139
+ tree.each do |node|
140
+ if node.is_a?( Array )
141
+ case node[0]
142
+ when :contract then buf << node[1] << "\n"
143
+ when :abstract_contract then buf << node[1] << "\n"
144
+ when :interface then buf << node[1] << "\n"
145
+ when :library then buf << node[1] << "\n"
146
+ else
147
+ end
148
+ end
149
+ end
150
+
151
+ buf
152
+ end
153
+
154
+ def pragmas
155
+ buf = String.new( '' )
156
+ tree = _quick_pass_one
157
+
158
+ tree.each do |node|
159
+ if node.is_a?( Array )
160
+ case node[0]
161
+ when :pragma then buf << node[1] << "\n"
162
+ end
163
+ end
164
+ end
165
+
166
+ buf
167
+ end
168
+
169
+
170
+ end # class Parser
171
+
172
+
173
+ 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 = 3
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.3
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: