Skip to content

Commit c913939

Browse files
authored
Merge branch 'master' into fix-escape-in-string
2 parents e104cd1 + 53f146a commit c913939

File tree

7 files changed

+332
-42
lines changed

7 files changed

+332
-42
lines changed

README.rdoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
= \RDoc - Ruby Documentation System
22

3-
home :: https://github.com/rdoc/rdoc
4-
rdoc :: https://rdoc.github.io/rdoc
5-
bugs :: https://github.com/rdoc/rdoc/issues
6-
build status :: {<img src="https://travis-ci.org/rdoc/rdoc.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/rdoc/rdoc]
7-
code quality :: {<img src="https://codeclimate.com/github/rdoc/rdoc/badges/gpa.svg" alt="Code Climate">}[https://codeclimate.com/github/rdoc/rdoc]
3+
home :: https://github.com/ruby/rdoc
4+
rdoc :: https://ruby.github.io/rdoc
5+
bugs :: https://github.com/ruby/rdoc/issues
6+
build status :: {<img src="https://travis-ci.org/ruby/rdoc.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/ruby/rdoc]
7+
code quality :: {<img src="https://codeclimate.com/github/ruby/rdoc/badges/gpa.svg" alt="Code Climate">}[https://codeclimate.com/github/ruby/rdoc]
88

99
== Description
1010

lib/rdoc/parser/ruby_tools.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,6 @@ def get_tk
3333

3434
tk = nil if TkEND_OF_SCRIPT === tk
3535

36-
if TkSYMBEG === tk then
37-
set_token_position tk.line_no, tk.char_no
38-
39-
case tk1 = get_tk
40-
when TkId, TkOp, TkSTRING, TkDSTRING, TkSTAR, TkAMPER then
41-
if tk1.respond_to?(:name) then
42-
tk = Token(TkSYMBOL).set_text(":" + tk1.name)
43-
else
44-
tk = Token(TkSYMBOL).set_text(":" + tk1.text)
45-
end
46-
47-
# remove the identifier we just read to replace it with a symbol
48-
@token_listeners.each do |obj|
49-
obj.pop_token
50-
end if @token_listeners
51-
else
52-
tk = tk1
53-
end
54-
end
55-
5636
# inform any listeners of our shiny new token
5737
@token_listeners.each do |obj|
5838
obj.add_token(tk)

lib/rdoc/ruby_lex.rb

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,22 @@ def token
361361
if @readed_auto_clean_up
362362
get_readed
363363
end
364+
365+
if TkSYMBEG === tk then
366+
tk1 = token
367+
set_token_position tk.seek, tk.line_no, tk.char_no
368+
369+
case tk1
370+
when TkId, TkOp, TkSTRING, TkDSTRING, TkSTAR, TkAMPER then
371+
if tk1.respond_to?(:name) then
372+
tk = Token(TkSYMBOL, ":" + tk1.name)
373+
else
374+
tk = Token(TkSYMBOL, ":" + tk1.text)
375+
end
376+
else
377+
tk = tk1
378+
end
379+
end
364380
# Tracer.off
365381
tk
366382
end
@@ -380,7 +396,9 @@ def token
380396
"r" => "/",
381397
"w" => "]",
382398
"W" => "]",
383-
"s" => ":"
399+
"s" => ":",
400+
"i" => "]",
401+
"I" => "]"
384402
}
385403

386404
PERCENT_PAREN = {
@@ -467,7 +485,7 @@ def lex_init()
467485
"=", "==", "===",
468486
"=~", "<=>",
469487
"<", "<=",
470-
">", ">=", ">>") do
488+
">", ">=", ">>", "=>") do
471489
|op, io|
472490
case @lex_state
473491
when :EXPR_FNAME, :EXPR_DOT
@@ -721,6 +739,7 @@ def lex_int2
721739

722740
@OP.def_rule("[") do
723741
|op, io|
742+
text = nil
724743
@indent += 1
725744
if @lex_state == :EXPR_FNAME
726745
tk_c = TkfLBRACK
@@ -729,13 +748,25 @@ def lex_int2
729748
tk_c = TkLBRACK
730749
elsif @lex_state == :EXPR_ARG && @space_seen
731750
tk_c = TkLBRACK
751+
elsif @lex_state == :EXPR_DOT
752+
if peek(0) == "]"
753+
tk_c = TkIDENTIFIER
754+
getc
755+
if peek(0) == "="
756+
text = "[]="
757+
else
758+
text = "[]"
759+
end
760+
else
761+
tk_c = TkOp
762+
end
732763
else
733764
tk_c = TkfLBRACK
734765
end
735766
@lex_state = :EXPR_BEG
736767
end
737768
@indent_stack.push tk_c
738-
Token(tk_c)
769+
Token(tk_c, text)
739770
end
740771

741772
@OP.def_rule("{") do
@@ -932,7 +963,12 @@ def identify_identifier
932963
@indent_stack.push token_c
933964
end
934965
else
935-
token_c = TkIDENTIFIER
966+
if peek(0) == ':' and !peek_match?(/^::/)
967+
token.concat getc
968+
token_c = TkSYMBOL
969+
else
970+
token_c = TkIDENTIFIER
971+
end
936972
end
937973

938974
elsif DEINDENT_CLAUSE.include?(token)
@@ -965,7 +1001,12 @@ def identify_identifier
9651001
elsif token[token.size - 1, 1] =~ /[!?]/
9661002
return Token(TkFID, token)
9671003
else
968-
return Token(TkIDENTIFIER, token)
1004+
if peek(0) == ':' and !peek_match?(/^::/)
1005+
token.concat getc
1006+
return Token(TkSYMBOL, token)
1007+
else
1008+
return Token(TkIDENTIFIER, token)
1009+
end
9691010
end
9701011
end
9711012

@@ -1125,6 +1166,7 @@ def identify_number(op = "")
11251166
type = TkINTEGER
11261167
allow_point = true
11271168
allow_e = true
1169+
allow_ri = true
11281170
non_digit = false
11291171
while ch = getc
11301172
num << ch
@@ -1154,8 +1196,25 @@ def identify_number(op = "")
11541196
num << getc
11551197
end
11561198
allow_e = false
1199+
allow_ri = false
11571200
allow_point = false
11581201
non_digit = ch
1202+
when allow_ri && "r"
1203+
if non_digit
1204+
raise Error, "trailing `#{non_digit}' in number"
1205+
end
1206+
type = TkRATIONAL
1207+
if peek(0) == 'i'
1208+
type = TkIMAGINARY
1209+
num << getc
1210+
end
1211+
break
1212+
when allow_ri && "i"
1213+
if non_digit && non_digit != "r"
1214+
raise Error, "trailing `#{non_digit}' in number"
1215+
end
1216+
type = TkIMAGINARY
1217+
break
11591218
else
11601219
if non_digit
11611220
raise Error, "trailing `#{non_digit}' in number"

lib/rdoc/ruby_token.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ module RDoc::RubyToken
2626
Symbol = Integer
2727
end
2828

29-
def set_token_position(line, char)
29+
def set_token_position(seek, line, char)
30+
@prev_seek = seek
3031
@prev_line_no = line
3132
@prev_char_no = char
3233
end
@@ -331,6 +332,8 @@ def Token(token, value = nil)
331332

332333
[:TkINTEGER, TkVal],
333334
[:TkFLOAT, TkVal],
335+
[:TkRATIONAL, TkVal],
336+
[:TkIMAGINARY, TkVal],
334337
[:TkSTRING, TkVal],
335338
[:TkHEREDOC, TkVal],
336339
[:TkXSTRING, TkVal],
@@ -353,6 +356,7 @@ def Token(token, value = nil)
353356
[:TkNEQ, TkOp, "!="],
354357
[:TkGEQ, TkOp, ">="],
355358
[:TkLEQ, TkOp, "<="],
359+
[:TkHASHROCKET, TkOp, "=>"],
356360
[:TkANDOP, TkOp, "&&"],
357361
[:TkOROP, TkOp, "||"],
358362
[:TkMATCH, TkOp, "=~"],

lib/rdoc/token_stream.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ def self.to_html token_stream
3636
when RDoc::RubyToken::TkIVAR then 'ruby-ivar'
3737
when RDoc::RubyToken::TkOp then 'ruby-operator'
3838
when RDoc::RubyToken::TkId then 'ruby-identifier'
39+
when RDoc::RubyToken::TkREGEXP then 'ruby-regexp'
40+
when RDoc::RubyToken::TkDREGEXP then 'ruby-regexp'
3941
when RDoc::RubyToken::TkNode then 'ruby-node'
4042
when RDoc::RubyToken::TkCOMMENT then 'ruby-comment'
41-
when RDoc::RubyToken::TkREGEXP then 'ruby-regexp'
4243
when RDoc::RubyToken::TkSTRING then 'ruby-string'
4344
when RDoc::RubyToken::TkVal then 'ruby-value'
4445
end

0 commit comments

Comments
 (0)