solidity 0.1.5 → 0.2.0

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: 7039440cfd0f451c6d990c35cdbef3a23309b86ce3c380cb4716ad9647b27f5d
4
- data.tar.gz: e69c2a1a4273a5c9abc2858d5fe5a9cc27dc46656acf321e39cb520addb579c1
3
+ metadata.gz: 92328b174c85612323db86d1d50654934da8b46d878831b99d49086673cda0df
4
+ data.tar.gz: 487298452cd42474065d694a87ef23f8425371dfd8ce29742c38b38227beaade
5
5
  SHA512:
6
- metadata.gz: a97fb7eeac099baf18b2045fa60351b97ac36207c68517553498c35912f4eed73727aa94d8e9b70a7b2512e9efeb865d764161fa56876c1fcac2f87782333049
7
- data.tar.gz: 68abe7d1bb83abdbd5a45f6cd3303a9ff368ae87f73046a9f3d40858e4407fc4f8fb300e599aca915a68921a9d3ff286b88ae4b29746e5fcd7b2ac0d2634f324
6
+ metadata.gz: 18ee1772f0ea6d2c5579d955301140bf7930e3f9b94810682da34d5929c9c93c7b10f62e7781d01abe16527f54502837cd2424c773b0177c3fc767ba43734706
7
+ data.tar.gz: 1dcd402d83754b2bee56794fe465f02f7f874770188dffb971ff3fe34ea7aa0f084416f6a0f64508e90132d2ea03795e2f364c29f023b7f767e62d0d450a682d
@@ -43,15 +43,14 @@ class Lexer
43
43
  ## SingleQuotedStringCharacter
44
44
  ## : ~['\r\n\\] | ('\\' .) ;
45
45
 
46
+ DOUBLE_QUOTE = %r{"
47
+ ( \\\\. | [^"\r\n\\] )*
48
+ "}x
46
49
 
47
50
  SINGLE_QUOTE = %r{'
48
- ( \\\\. | [^'] )*
51
+ ( \\\\. | [^'\r\n\\] )*
49
52
  '}x
50
53
 
51
- DOUBLE_QUOTE = %r{"
52
- ( \\\\. | [^"] )*
53
- "}x
54
-
55
54
 
56
55
  ## from the solidity grammar
57
56
  ## > An identifier in solidity has to start with a letter,
@@ -76,40 +75,34 @@ class Lexer
76
75
  ##
77
76
  ## COMMENT
78
77
  ## : '/*' .*? '*/' ;
79
- ##
80
78
  ## LINE_COMMENT
81
79
  ## : '//' ~[\r\n]* ;
82
80
 
81
+ COMMENT = %r{/\*
82
+ .*?
83
+ \*/}x
84
+
85
+ LINE_COMMENT = %r{//
86
+ [^\r\n]*}x
83
87
 
84
88
  def tokenize
85
89
  t = []
86
90
  s = StringScanner.new( @txt )
87
91
 
88
92
  until s.eos? ## loop until hitting end-of-string (file)
89
- if s.check( /[ \t]*\/\*/ )
90
- ## note: auto-slurp leading (optinal) spaces!!!! - why? why not?
91
- comment = s.scan_until( /\*\// )
92
- ## print "multi-line comment:"
93
- ## pp comment
94
- t << [:comment, comment.lstrip]
95
- elsif s.check( /[ \t]*\/\// )
96
- ## note: auto-slurp leading (optinal) spaces!!!! - why? why not?
97
- ## note: auto-remove newline AND trailing whitespace - why? why not?
98
- comment = s.scan_until( /\n|$/ ).strip
99
- ## print "comment:"
100
- ## pp comment
101
- t << [:comment, comment]
102
- elsif s.scan( /[ \t]+/ ) ## one or more spaces
93
+ if s.scan( /[ \t]+/ ) ## one or more spaces
103
94
  ## note: (auto-)convert tab to space - why? why not?
104
95
  t << [:sp, s.matched.gsub( /[\t]/, ' ') ]
105
96
  elsif s.scan( /\r?\n/ ) ## check for (windows) carriage return (\r) - why? why not?
106
97
  t << [:nl, "\n" ]
107
- elsif s.check( "'" ) ## single-quoted string
108
- str = s.scan( SINGLE_QUOTE )
109
- t << [:string, str]
110
- elsif s.check( '"' ) ## double-quoted string
111
- str = s.scan( DOUBLE_QUOTE )
112
- t << [:string, str]
98
+ elsif s.scan( COMMENT )
99
+ t << [:comment, s.matched]
100
+ elsif s.scan( LINE_COMMENT )
101
+ t << [:comment, s.matched]
102
+ elsif s.scan( DOUBLE_QUOTE ) ## double-quoted string
103
+ t << [:string, s.matched]
104
+ elsif s.scan( SINGLE_QUOTE ) ## single-quoted string
105
+ t << [:string, s.matched]
113
106
  elsif s.scan( NAME )
114
107
  name = s.matched
115
108
  case name
@@ -154,13 +147,41 @@ class Lexer
154
147
  ## note: returns type lexeme (string content) for now
155
148
  ## and NOT token struct for now - why? why not?
156
149
  t = @tokens[@pos]
157
- tt = t.nil? || t.is_a?( String ) ? t : t[1]
150
+ str = t.nil? || t.is_a?( String ) ? t : t[1]
158
151
  @pos += 1 unless t.nil?
159
- tt
152
+ str
160
153
  end
161
154
  def eos?() peek().nil?; end
162
155
 
163
156
 
164
157
 
158
+
159
+ #################################################
160
+ # "higher-level" helpers
161
+ def scan_until( tt, include: false )
162
+ code = String.new('')
163
+ while (peek=self.peek) != tt do
164
+ ## note: turn inline comments into a single space
165
+ code << if peek == :comment
166
+ self.next ## note: next (w/o self) is parsed as keyword
167
+ ' '
168
+ else
169
+ self.next ## note: next (w/o self) is parsed as keyword
170
+ end
171
+ end
172
+ code << self.next if include ## include ';' too - why? why not?
173
+ code = _norm_whitespace( code )
174
+ code
175
+ end
176
+
177
+ def _norm_whitespace( str )
178
+ ## change newlines to spaces and
179
+ ## all multiple spaces to one
180
+ str = str.gsub( /[ \t\n\r]+/, ' ' )
181
+ str.strip
182
+ end
183
+
184
+
185
+
165
186
  end # class Lexer
166
187
  end # module Solidity
@@ -17,66 +17,40 @@ class Parser
17
17
 
18
18
 
19
19
 
20
- def _scan_until( lex, tt, include: false )
21
- code = String.new('')
22
- while (peek=lex.peek) != tt do
23
- ## note: turn inline comments into a single space
24
- code << if peek == :comment
25
- lex.next
26
- ' '
27
- else
28
- lex.next
29
- end
30
- end
31
- code << lex.next if include ## include ';' too - why? why not?
32
- code = _norm_whitespace( code )
33
- code
34
- end
35
-
36
- def _norm_whitespace( str )
37
- ## change newlines to spaces and
38
- ## all multiple spaces to one
39
- str = str.gsub( /[ \t\n\r]+/, ' ' )
40
- str.strip
41
- end
42
-
43
-
44
20
  def _quick_pass_one
45
21
  tree = []
46
22
 
47
23
  lex = Lexer.new( @txt )
48
24
 
49
25
  until lex.eos?
50
- while lex.peek == :sp do ## note: do NOT skip newlines here; pass along blank/empty lines for now - why? why not?
51
- lex.next
52
- end
53
-
54
26
  case lex.peek
55
27
  when :comment ## single or multi-line comment
56
28
  tree << [:comment, lex.next]
29
+ ## note: if next token is newline - slurp / ignore
30
+ lex.next if lex.peek == :nl
57
31
  when :pragma
58
- code = _scan_until( lex, :';',
59
- include: true )
32
+ code = lex.scan_until( :';',
33
+ include: true )
60
34
  ## print "pragma:"
61
35
  ## pp code
62
36
  tree << [:pragma, code]
63
37
  when :contract
64
- code = _scan_until( lex, :'{' )
38
+ code = lex.scan_until( :'{' )
65
39
  ## print "contract:"
66
40
  ## pp code
67
41
  tree << [:contract, code]
68
42
  when :abstract
69
- code = _scan_until( lex, :'{' )
43
+ code = lex.scan_until( :'{' )
70
44
  ## print "abstract contract:"
71
45
  ## pp code
72
46
  tree << [:abstract_contract, code]
73
47
  when :library
74
- code = _scan_until( lex, :'{' )
48
+ code = lex.scan_until( :'{' )
75
49
  ## print "library:"
76
50
  ## pp code
77
51
  tree << [:library, code]
78
52
  when :interface
79
- code = _scan_until( lex, :'{' )
53
+ code = lex.scan_until( :'{' )
80
54
  ## print "interface:"
81
55
  ## pp code
82
56
  tree << [:interface, code]
@@ -1,8 +1,8 @@
1
1
 
2
2
  module Solidity
3
3
  MAJOR = 0
4
- MINOR = 1
5
- PATCH = 5
4
+ MINOR = 2
5
+ PATCH = 0
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
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.5
4
+ version: 0.2.0
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-02-05 00:00:00.000000000 Z
11
+ date: 2023-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocos