summaryrefslogtreecommitdiff
path: root/lib/irb/ruby-lex.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/irb/ruby-lex.rb')
-rw-r--r--lib/irb/ruby-lex.rb90
1 files changed, 45 insertions, 45 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index b21f0d34f8..13b101ffc8 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -6,7 +6,7 @@
#
# --
#
-#
+#
#
require "e2mmap"
@@ -20,12 +20,12 @@ class RubyLex
def_exception(:AlreadyDefinedToken, "Already defined token(%s)")
def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
- def_exception(:TkReading2TokenDuplicateError,
+ def_exception(:TkReading2TokenDuplicateError,
"key duplicate(token_n='%s', key='%s')")
def_exception(:SyntaxError, "%s")
def_exception(:TerminateLineInput, "Terminate Line Input")
-
+
include RubyToken
class << self
@@ -53,7 +53,7 @@ class RubyLex
@lex_state = EXPR_BEG
@space_seen = false
@here_header = false
-
+
@continue = false
@line = ""
@@ -91,7 +91,7 @@ class RubyLex
else
@base_char_no += @readed.size
end
-
+
readed = @readed.join("")
@readed = []
readed
@@ -111,7 +111,7 @@ class RubyLex
end
@seek += 1
if c == "\n"
- @line_no += 1
+ @line_no += 1
@char_no = 0
else
@char_no += 1
@@ -148,10 +148,10 @@ class RubyLex
c2 = @here_readed.pop
end
c = c2 unless c
- @rests.unshift c #c =
+ @rests.unshift c #c =
@seek -= 1
if c == "\n"
- @line_no -= 1
+ @line_no -= 1
if idx = @readed.reverse.index("\n")
@char_no = @readed.size - idx
else
@@ -216,14 +216,14 @@ class RubyLex
@lex_state = EXPR_BEG
@space_seen = false
@here_header = false
-
+
@continue = false
prompt
@line = ""
@exp_line_no = @line_no
end
-
+
def each_top_level_statement
initialize_input
catch(:TERM_INPUT) do
@@ -297,7 +297,7 @@ class RubyLex
# Tracer.off
tk
end
-
+
ENINDENT_CLAUSE = [
"case", "class", "def", "do", "for", "if",
"module", "unless", "until", "while", "begin" #, "when"
@@ -314,7 +314,7 @@ class RubyLex
"W" => "]",
"s" => ":"
}
-
+
PERCENT_PAREN = {
"{" => "}",
"[" => "]",
@@ -354,7 +354,7 @@ class RubyLex
end
@OP.def_rule("=begin",
- proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do
+ proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do
|op, io|
@ltype = "="
until getc == "\n"; end
@@ -374,8 +374,8 @@ class RubyLex
else
@continue = false
@lex_state = EXPR_BEG
- until (@indent_stack.empty? ||
- [TkLPAREN, TkLBRACK, TkLBRACE,
+ until (@indent_stack.empty? ||
+ [TkLPAREN, TkLBRACK, TkLBRACE,
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
@indent_stack.pop
end
@@ -385,9 +385,9 @@ class RubyLex
Token(TkNL)
end
- @OP.def_rules("*", "**",
- "=", "==", "===",
- "=~", "<=>",
+ @OP.def_rules("*", "**",
+ "=", "==", "===",
+ "=~", "<=>",
"<", "<=",
">", ">=", ">>") do
|op, io|
@@ -455,7 +455,7 @@ class RubyLex
@lex_state = EXPR_BEG;
Token(TkQUESTION)
else
- if (ch == '\\')
+ if (ch == '\\')
read_escape
end
@lex_state = EXPR_END
@@ -469,8 +469,8 @@ class RubyLex
@lex_state = EXPR_BEG
Token(op)
end
-
- @OP.def_rules("+=", "-=", "*=", "**=",
+
+ @OP.def_rules("+=", "-=", "*=", "**=",
"&=", "|=", "^=", "<<=", ">>=", "||=", "&&=") do
|op, io|
@lex_state = EXPR_BEG
@@ -529,7 +529,7 @@ class RubyLex
lex_int2
end
-
+
def lex_int2
@OP.def_rules("]", "}", ")") do
|op, io|
@@ -572,7 +572,7 @@ class RubyLex
Token(TkOPASGN, "/") #/)
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
identify_string(op)
- else
+ else
@lex_state = EXPR_BEG
Token("/") #/)
end
@@ -588,7 +588,7 @@ class RubyLex
# @lex_state = EXPR_BEG
# Token(OP_ASGN, :^)
# end
-
+
@OP.def_rules(",") do
|op, io|
@lex_state = EXPR_BEG
@@ -598,8 +598,8 @@ class RubyLex
@OP.def_rules(";") do
|op, io|
@lex_state = EXPR_BEG
- until (@indent_stack.empty? ||
- [TkLPAREN, TkLBRACK, TkLBRACE,
+ until (@indent_stack.empty? ||
+ [TkLPAREN, TkLBRACK, TkLBRACE,
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
@indent_stack.pop
end
@@ -617,7 +617,7 @@ class RubyLex
@lex_state = EXPR_BEG
Token("~")
end
-
+
@OP.def_rule("(") do
|op, io|
@indent += 1
@@ -718,7 +718,7 @@ class RubyLex
end
end
- # @OP.def_rule("def", proc{|op, io| /\s/ =~ io.peek(0)}) do
+ # @OP.def_rule("def", proc{|op, io| /\s/ =~ io.peek(0)}) do
# |op, io|
# @indent += 1
# @lex_state = EXPR_FNAME
@@ -739,13 +739,13 @@ class RubyLex
printf "MATCH: end %s: %s\n", op, io.inspect if RubyLex.debug?
t
end
-
+
p @OP if RubyLex.debug?
end
-
+
def identify_gvar
@lex_state = EXPR_END
-
+
case ch = getc
when /[~_*$?!@\/\\;,=:<>".]/ #"
Token(TkGVAR, "$" + ch)
@@ -761,12 +761,12 @@ class RubyLex
ungetc
ungetc
identify_identifier
- else
+ else
ungetc
Token("$")
end
end
-
+
def identify_identifier
token = ""
if peek(0) =~ /[$@]/
@@ -781,7 +781,7 @@ class RubyLex
token.concat ch
end
ungetc
-
+
if (ch == "!" || ch == "?") && token[0,1] =~ /\w/ && peek(0) != "="
token.concat getc
end
@@ -799,7 +799,7 @@ class RubyLex
@lex_state = EXPR_END
return Token(TkIVAR, token)
end
-
+
if @lex_state != EXPR_DOT
print token, "\n" if RubyLex.debug?
@@ -927,7 +927,7 @@ class RubyLex
@lex_state = EXPR_END
Token(Ltype2Token[lt])
end
-
+
def identify_quotation
ch = getc
if lt = PERCENT_LTYPE[ch]
@@ -968,10 +968,10 @@ class RubyLex
match = /[0-7_]/
when /[89]/
RubyLex.fail SyntaxError, "Invalid octal digit"
- else
+ else
return Token(TkINTEGER)
end
-
+
len0 = true
non_digit = false
while ch = getc
@@ -999,7 +999,7 @@ class RubyLex
end
return Token(TkINTEGER)
end
-
+
type = TkINTEGER
allow_point = true
allow_e = true
@@ -1042,7 +1042,7 @@ class RubyLex
end
Token(type)
end
-
+
def identify_string(ltype, quoted = ltype)
@ltype = ltype
@quoted = quoted
@@ -1063,7 +1063,7 @@ class RubyLex
elsif ch == '\\' #'
read_escape
end
- if PERCENT_PAREN.values.include?(@quoted)
+ if PERCENT_PAREN.values.include?(@quoted)
if PERCENT_PAREN[ch] == @quoted
nest += 1
elsif ch == @quoted
@@ -1087,7 +1087,7 @@ class RubyLex
@lex_state = EXPR_END
end
end
-
+
def identify_comment
@ltype = "#"
@@ -1103,7 +1103,7 @@ class RubyLex
end
return Token(TkCOMMENT)
end
-
+
def read_escape
case ch = getc
when "\n", "\r", "\f"
@@ -1120,7 +1120,7 @@ class RubyLex
break
end
end
-
+
when "x"
2.times do
case ch = getc
@@ -1149,7 +1149,7 @@ class RubyLex
read_escape
end
else
- # other characters
+ # other characters
end
end
end