Skip to content

Commit 54c9ea9

Browse files
committed
up
1 parent 988de22 commit 54c9ea9

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

solidity/lib/solidity/lexer.rb

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,41 @@ def next
154154
## note: returns type lexeme (string content) for now
155155
## and NOT token struct for now - why? why not?
156156
t = @tokens[@pos]
157-
tt = t.nil? || t.is_a?( String ) ? t : t[1]
157+
str = t.nil? || t.is_a?( String ) ? t : t[1]
158158
@pos += 1 unless t.nil?
159-
tt
159+
str
160160
end
161161
def eos?() peek().nil?; end
162162

163163

164164

165+
166+
#################################################
167+
# "higher-level" helpers
168+
def scan_until( tt, include: false )
169+
code = String.new('')
170+
while (peek=self.peek) != tt do
171+
## note: turn inline comments into a single space
172+
code << if peek == :comment
173+
self.next ## note: next (w/o self) is parsed as keyword
174+
' '
175+
else
176+
self.next ## note: next (w/o self) is parsed as keyword
177+
end
178+
end
179+
code << self.next if include ## include ';' too - why? why not?
180+
code = _norm_whitespace( code )
181+
code
182+
end
183+
184+
def _norm_whitespace( str )
185+
## change newlines to spaces and
186+
## all multiple spaces to one
187+
str = str.gsub( /[ \t\n\r]+/, ' ' )
188+
str.strip
189+
end
190+
191+
192+
165193
end # class Lexer
166194
end # module Solidity

solidity/lib/solidity/parser.rb

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,6 @@ def initialize( txt )
1717

1818

1919

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-
4420
def _quick_pass_one
4521
tree = []
4622

@@ -55,28 +31,28 @@ def _quick_pass_one
5531
when :comment ## single or multi-line comment
5632
tree << [:comment, lex.next]
5733
when :pragma
58-
code = _scan_until( lex, :';',
59-
include: true )
34+
code = lex.scan_until( :';',
35+
include: true )
6036
## print "pragma:"
6137
## pp code
6238
tree << [:pragma, code]
6339
when :contract
64-
code = _scan_until( lex, :'{' )
40+
code = lex.scan_until( :'{' )
6541
## print "contract:"
6642
## pp code
6743
tree << [:contract, code]
6844
when :abstract
69-
code = _scan_until( lex, :'{' )
45+
code = lex.scan_until( :'{' )
7046
## print "abstract contract:"
7147
## pp code
7248
tree << [:abstract_contract, code]
7349
when :library
74-
code = _scan_until( lex, :'{' )
50+
code = lex.scan_until( :'{' )
7551
## print "library:"
7652
## pp code
7753
tree << [:library, code]
7854
when :interface
79-
code = _scan_until( lex, :'{' )
55+
code = lex.scan_until( :'{' )
8056
## print "interface:"
8157
## pp code
8258
tree << [:interface, code]

0 commit comments

Comments
 (0)