Permalink
Browse files

Replace += with << in tokenizer and scanner; partly because it may be…

… more efficient, partly because it removes an obstacle to self-hosting
  • Loading branch information...
vidarh committed Sep 11, 2014
1 parent a18cdef commit 7ae9623587dc536fbb37a908a11f6231e050c52f
Showing with 13 additions and 13 deletions.
  1. +1 −1 scanner.rb
  2. +12 −12 tokens.rb
View
@@ -83,7 +83,7 @@ def unget(c)
else
#STDERR.puts "unget without position: #{c}"
end
@buf += c
@buf << c
end
# If &block is passed, it is a callback to parse an expression
View
@@ -94,24 +94,24 @@ def self.expect(s)
return Sym.expect(s) if c == ?: # This is a hack. Shoud be handled separately
if c == ?@ || c == ?$
tmp += s.get
tmp += s.get if c == ?@ && s.peek == ?@
tmp << s.get
tmp << s.get if c == ?@ && s.peek == ?@
end
if (c = s.peek) && (c == ?_ || (?a .. ?z).member?(c) || (?A .. ?Z).member?(c))
tmp += s.get
tmp << s.get
while (c = s.peek) && ((?a .. ?z).member?(c) ||
(?A .. ?Z).member?(c) ||
(?0 .. ?9).member?(c) || ?_ == c)
tmp += s.get
tmp << s.get
end
elsif tmp == "$"
tmp += s.get # FIXME: Need to check what characters are legal after $ (and not covered above)
tmp << s.get # FIXME: Need to check what characters are legal after $ (and not covered above)
return tmp.to_sym
end
if tmp.size > 0 && (s.peek == ?! || s.peek == ??)
tmp += s.get
tmp << s.get
end
return nil if tmp == ""
return tmp.to_sym
@@ -146,9 +146,9 @@ def self.expect(s)
class Int
def self.expect(s)
tmp = ""
tmp += s.get if s.peek == ?-
tmp << s.get if s.peek == ?-
while (c = s.peek) && (?0 .. ?9).member?(c)
tmp += s.get
tmp << s.get
end
return nil if tmp == ""
tmp.to_i
@@ -226,7 +226,7 @@ def self.expect_dquoted(s,q='"')
s.expect("}")
end
else
buf += e
buf << e
end
end
raise "Unterminated string" if !s.expect(q)
@@ -242,11 +242,11 @@ def self.expect_squoted(s,q = "'" )
buf = ""
while (e = s.get) && e != q
if e == '"'
buf += "\\\""
buf << "\\\""
elsif e == "\\" && (s.peek == ?' || s.peek == "\\"[0])
buf += "\\" + s.get
buf << "\\" + s.get
else
buf += e
buf << e
end
end
raise "Unterminated string" if e != "'"

0 comments on commit 7ae9623

Please sign in to comment.