rdoc 6.0.4 → 6.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rdoc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +7 -6
- data/Rakefile +6 -1
- data/lib/rdoc.rb +1 -5
- data/lib/rdoc/cross_reference.rb +29 -11
- data/lib/rdoc/generator/markup.rb +2 -12
- data/lib/rdoc/generator/template/json_index/js/navigation.js +3 -4
- data/lib/rdoc/markup.rb +10 -12
- data/lib/rdoc/markup/attribute_manager.rb +22 -22
- data/lib/rdoc/markup/attributes.rb +6 -6
- data/lib/rdoc/markup/formatter.rb +24 -23
- data/lib/rdoc/markup/heading.rb +3 -3
- data/lib/rdoc/markup/to_bs.rb +3 -3
- data/lib/rdoc/markup/to_html.rb +20 -20
- data/lib/rdoc/markup/to_html_crossref.rb +9 -14
- data/lib/rdoc/markup/to_html_snippet.rb +9 -9
- data/lib/rdoc/markup/to_label.rb +9 -9
- data/lib/rdoc/markup/to_markdown.rb +7 -7
- data/lib/rdoc/markup/to_rdoc.rb +5 -5
- data/lib/rdoc/markup/to_tt_only.rb +2 -2
- data/lib/rdoc/parser/ripper_state_lex.rb +53 -83
- data/lib/rdoc/parser/ruby.rb +149 -78
- data/lib/rdoc/parser/ruby_tools.rb +15 -7
- data/lib/rdoc/rdoc.rb +1 -1
- data/lib/rdoc/store.rb +15 -5
- data/lib/rdoc/tom_doc.rb +9 -3
- data/lib/rdoc/top_level.rb +8 -2
- data/lib/rdoc/version.rb +8 -0
- data/rdoc.gemspec +5 -10
- metadata +17 -4
- data/lib/rdoc/markup/inline.rb +0 -2
- data/lib/rdoc/markup/special.rb +0 -41
data/lib/rdoc/markup/heading.rb
CHANGED
@@ -23,12 +23,12 @@ RDoc::Markup::Heading =
|
|
23
23
|
return @to_html if @to_html
|
24
24
|
|
25
25
|
markup = RDoc::Markup.new
|
26
|
-
markup.
|
26
|
+
markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
|
27
27
|
|
28
28
|
@to_html = RDoc::Markup::ToHtml.new nil
|
29
29
|
|
30
|
-
def @to_html.
|
31
|
-
|
30
|
+
def @to_html.handle_regexp_CROSSREF target
|
31
|
+
target.text.sub(/^\\/, '')
|
32
32
|
end
|
33
33
|
|
34
34
|
@to_html
|
data/lib/rdoc/markup/to_bs.rb
CHANGED
@@ -41,7 +41,7 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
|
|
41
41
|
end
|
42
42
|
|
43
43
|
##
|
44
|
-
# Turns on or off
|
44
|
+
# Turns on or off regexp handling for +convert_string+
|
45
45
|
|
46
46
|
def annotate tag
|
47
47
|
case tag
|
@@ -54,9 +54,9 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
|
|
54
54
|
end
|
55
55
|
|
56
56
|
##
|
57
|
-
# Calls convert_string on the result of
|
57
|
+
# Calls convert_string on the result of convert_regexp_handling
|
58
58
|
|
59
|
-
def
|
59
|
+
def convert_regexp_handling target
|
60
60
|
convert_string super
|
61
61
|
end
|
62
62
|
|
data/lib/rdoc/markup/to_html.rb
CHANGED
@@ -53,18 +53,18 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
53
53
|
@hard_break = "<br>\n"
|
54
54
|
|
55
55
|
# external links
|
56
|
-
@markup.
|
57
|
-
|
56
|
+
@markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
|
57
|
+
:HYPERLINK)
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
add_regexp_handling_RDOCLINK
|
60
|
+
add_regexp_handling_TIDYLINK
|
61
61
|
|
62
62
|
init_tags
|
63
63
|
end
|
64
64
|
|
65
|
-
# :section:
|
65
|
+
# :section: Regexp Handling
|
66
66
|
#
|
67
|
-
# These methods
|
67
|
+
# These methods are used by regexp handling markup added by RDoc::Markup#add_regexp_handling.
|
68
68
|
|
69
69
|
def handle_RDOCLINK url # :nodoc:
|
70
70
|
case url
|
@@ -91,14 +91,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
91
91
|
end
|
92
92
|
|
93
93
|
##
|
94
|
-
# +
|
94
|
+
# +target+ is a <code><br></code>
|
95
95
|
|
96
|
-
def
|
96
|
+
def handle_regexp_HARD_BREAK target
|
97
97
|
'<br>'
|
98
98
|
end
|
99
99
|
|
100
100
|
##
|
101
|
-
# +
|
101
|
+
# +target+ is a potential link. The following schemes are handled:
|
102
102
|
#
|
103
103
|
# <tt>mailto:</tt>::
|
104
104
|
# Inserted as-is.
|
@@ -109,14 +109,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
109
109
|
# <tt>link:</tt>::
|
110
110
|
# Reference to a local file relative to the output directory.
|
111
111
|
|
112
|
-
def
|
113
|
-
url =
|
112
|
+
def handle_regexp_HYPERLINK(target)
|
113
|
+
url = target.text
|
114
114
|
|
115
115
|
gen_url url, url
|
116
116
|
end
|
117
117
|
|
118
118
|
##
|
119
|
-
# +
|
119
|
+
# +target+ is an rdoc-schemed link that will be converted into a hyperlink.
|
120
120
|
#
|
121
121
|
# For the +rdoc-ref+ scheme the named reference will be returned without
|
122
122
|
# creating a link.
|
@@ -124,16 +124,16 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
124
124
|
# For the +rdoc-label+ scheme the footnote and label prefixes are stripped
|
125
125
|
# when creating a link. All other contents will be linked verbatim.
|
126
126
|
|
127
|
-
def
|
128
|
-
handle_RDOCLINK
|
127
|
+
def handle_regexp_RDOCLINK target
|
128
|
+
handle_RDOCLINK target.text
|
129
129
|
end
|
130
130
|
|
131
131
|
##
|
132
|
-
# This +
|
132
|
+
# This +target+ is a link where the label is different from the URL
|
133
133
|
# <tt>label[url]</tt> or <tt>{long label}[url]</tt>
|
134
134
|
|
135
|
-
def
|
136
|
-
text =
|
135
|
+
def handle_regexp_TIDYLINK(target)
|
136
|
+
text = target.text
|
137
137
|
|
138
138
|
return text unless
|
139
139
|
text =~ /^\{(.*)\}\[(.*?)\]$/ or text =~ /^(\S+)\[(.*?)\]$/
|
@@ -186,7 +186,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
186
186
|
@res << "\n<p>"
|
187
187
|
text = paragraph.text @hard_break
|
188
188
|
text = text.gsub(/\r?\n/, ' ')
|
189
|
-
@res <<
|
189
|
+
@res << to_html(text)
|
190
190
|
@res << "</p>\n"
|
191
191
|
end
|
192
192
|
|
@@ -200,7 +200,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
200
200
|
|
201
201
|
content = if verbatim.ruby? or parseable? text then
|
202
202
|
begin
|
203
|
-
tokens = RDoc::RipperStateLex.parse text
|
203
|
+
tokens = RDoc::Parser::RipperStateLex.parse text
|
204
204
|
klass = ' class="ruby"'
|
205
205
|
|
206
206
|
result = RDoc::TokenStream.to_html tokens
|
@@ -312,7 +312,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
312
312
|
|
313
313
|
##
|
314
314
|
# Generate a link to +url+ with content +text+. Handles the special cases
|
315
|
-
# for img: and link: described under
|
315
|
+
# for img: and link: described under handle_regexp_HYPERLINK
|
316
316
|
|
317
317
|
def gen_url url, text
|
318
318
|
scheme, url, id = parse_url url
|
@@ -40,7 +40,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|
40
40
|
@show_hash = @options.show_hash
|
41
41
|
|
42
42
|
crossref_re = @hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
|
43
|
-
@markup.
|
43
|
+
@markup.add_regexp_handling crossref_re, :CROSSREF
|
44
44
|
|
45
45
|
@cross_reference = RDoc::CrossReference.new @context
|
46
46
|
end
|
@@ -68,8 +68,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|
68
68
|
# example, ToHtml is found, even without the <tt>RDoc::Markup::</tt> prefix,
|
69
69
|
# because we look for it in module Markup first.
|
70
70
|
|
71
|
-
def
|
72
|
-
name =
|
71
|
+
def handle_regexp_CROSSREF(target)
|
72
|
+
name = target.text
|
73
73
|
|
74
74
|
return name if name =~ /@[\w-]+\.[\w-]/ # labels that look like emails
|
75
75
|
|
@@ -87,22 +87,22 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|
87
87
|
# Handles <tt>rdoc-ref:</tt> scheme links and allows RDoc::Markup::ToHtml to
|
88
88
|
# handle other schemes.
|
89
89
|
|
90
|
-
def
|
91
|
-
return cross_reference $' if
|
90
|
+
def handle_regexp_HYPERLINK target
|
91
|
+
return cross_reference $' if target.text =~ /\Ardoc-ref:/
|
92
92
|
|
93
93
|
super
|
94
94
|
end
|
95
95
|
|
96
96
|
##
|
97
|
-
# +
|
97
|
+
# +target+ is an rdoc-schemed link that will be converted into a hyperlink.
|
98
98
|
# For the rdoc-ref scheme the cross-reference will be looked up and the
|
99
99
|
# given name will be used.
|
100
100
|
#
|
101
101
|
# All other contents are handled by
|
102
|
-
# {the superclass}[rdoc-ref:RDoc::Markup::ToHtml#
|
102
|
+
# {the superclass}[rdoc-ref:RDoc::Markup::ToHtml#handle_regexp_RDOCLINK]
|
103
103
|
|
104
|
-
def
|
105
|
-
url =
|
104
|
+
def handle_regexp_RDOCLINK target
|
105
|
+
url = target.text
|
106
106
|
|
107
107
|
case url
|
108
108
|
when /\Ardoc-ref:/ then
|
@@ -126,8 +126,6 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|
126
126
|
# Creates an HTML link to +name+ with the given +text+.
|
127
127
|
|
128
128
|
def link name, text
|
129
|
-
original_name = name
|
130
|
-
|
131
129
|
if name =~ /(.*[^#:])@/ then
|
132
130
|
name = $1
|
133
131
|
label = $'
|
@@ -135,9 +133,6 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|
135
133
|
|
136
134
|
ref = @cross_reference.resolve name, text
|
137
135
|
|
138
|
-
text = ref.output_name @context if
|
139
|
-
RDoc::MethodAttr === ref and text == original_name
|
140
|
-
|
141
136
|
case ref
|
142
137
|
when String then
|
143
138
|
ref
|
@@ -44,7 +44,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|
44
44
|
@mask = 0
|
45
45
|
@paragraphs = 0
|
46
46
|
|
47
|
-
@markup.
|
47
|
+
@markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
|
48
48
|
end
|
49
49
|
|
50
50
|
##
|
@@ -71,7 +71,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|
71
71
|
|
72
72
|
text = paragraph.text @hard_break
|
73
73
|
|
74
|
-
@res << "#{para}#{
|
74
|
+
@res << "#{para}#{to_html text}\n"
|
75
75
|
|
76
76
|
add_paragraph
|
77
77
|
end
|
@@ -123,16 +123,16 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|
123
123
|
end
|
124
124
|
|
125
125
|
##
|
126
|
-
# Removes escaping from the cross-references in +
|
126
|
+
# Removes escaping from the cross-references in +target+
|
127
127
|
|
128
|
-
def
|
129
|
-
|
128
|
+
def handle_regexp_CROSSREF target
|
129
|
+
target.text.sub(/\A\\/, '')
|
130
130
|
end
|
131
131
|
|
132
132
|
##
|
133
|
-
# +
|
133
|
+
# +target+ is a <code><br></code>
|
134
134
|
|
135
|
-
def
|
135
|
+
def handle_regexp_HARD_BREAK target
|
136
136
|
@characters -= 4
|
137
137
|
'<br>'
|
138
138
|
end
|
@@ -226,8 +226,8 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|
226
226
|
when String then
|
227
227
|
text = convert_string item
|
228
228
|
res << truncate(text)
|
229
|
-
when RDoc::Markup::
|
230
|
-
text =
|
229
|
+
when RDoc::Markup::RegexpHandling then
|
230
|
+
text = convert_regexp_handling item
|
231
231
|
res << truncate(text)
|
232
232
|
else
|
233
233
|
raise "Unknown flow element: #{item.inspect}"
|
data/lib/rdoc/markup/to_label.rb
CHANGED
@@ -16,8 +16,8 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|
16
16
|
def initialize markup = nil
|
17
17
|
super nil, markup
|
18
18
|
|
19
|
-
@markup.
|
20
|
-
@markup.
|
19
|
+
@markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
|
20
|
+
@markup.add_regexp_handling(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
|
21
21
|
|
22
22
|
add_tag :BOLD, '', ''
|
23
23
|
add_tag :TT, '', ''
|
@@ -36,20 +36,20 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|
36
36
|
end
|
37
37
|
|
38
38
|
##
|
39
|
-
# Converts the CROSSREF +
|
39
|
+
# Converts the CROSSREF +target+ to plain text, removing the suppression
|
40
40
|
# marker, if any
|
41
41
|
|
42
|
-
def
|
43
|
-
text =
|
42
|
+
def handle_regexp_CROSSREF target
|
43
|
+
text = target.text
|
44
44
|
|
45
45
|
text.sub(/^\\/, '')
|
46
46
|
end
|
47
47
|
|
48
48
|
##
|
49
|
-
# Converts the TIDYLINK +
|
49
|
+
# Converts the TIDYLINK +target+ to just the text part
|
50
50
|
|
51
|
-
def
|
52
|
-
text =
|
51
|
+
def handle_regexp_TIDYLINK target
|
52
|
+
text = target.text
|
53
53
|
|
54
54
|
return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
|
55
55
|
|
@@ -68,7 +68,7 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|
68
68
|
alias accept_rule ignore
|
69
69
|
alias accept_verbatim ignore
|
70
70
|
alias end_accepting ignore
|
71
|
-
alias
|
71
|
+
alias handle_regexp_HARD_BREAK ignore
|
72
72
|
alias start_accepting ignore
|
73
73
|
|
74
74
|
end
|
@@ -19,8 +19,8 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|
19
19
|
@headings[5] = ['##### ', '']
|
20
20
|
@headings[6] = ['###### ', '']
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
add_regexp_handling_RDOCLINK
|
23
|
+
add_regexp_handling_TIDYLINK
|
24
24
|
|
25
25
|
@hard_break = " \n"
|
26
26
|
end
|
@@ -37,7 +37,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|
37
37
|
##
|
38
38
|
# Adds a newline to the output
|
39
39
|
|
40
|
-
def
|
40
|
+
def handle_regexp_HARD_BREAK target
|
41
41
|
" \n"
|
42
42
|
end
|
43
43
|
|
@@ -166,8 +166,8 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|
166
166
|
##
|
167
167
|
# Converts the RDoc markup tidylink into a Markdown.style link.
|
168
168
|
|
169
|
-
def
|
170
|
-
text =
|
169
|
+
def handle_regexp_TIDYLINK target
|
170
|
+
text = target.text
|
171
171
|
|
172
172
|
return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
|
173
173
|
|
@@ -184,8 +184,8 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|
184
184
|
##
|
185
185
|
# Converts the rdoc-...: links into a Markdown.style links.
|
186
186
|
|
187
|
-
def
|
188
|
-
handle_rdoc_link
|
187
|
+
def handle_regexp_RDOCLINK target
|
188
|
+
handle_rdoc_link target.text
|
189
189
|
end
|
190
190
|
|
191
191
|
end
|
data/lib/rdoc/markup/to_rdoc.rb
CHANGED
@@ -45,7 +45,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|
45
45
|
def initialize markup = nil
|
46
46
|
super nil, markup
|
47
47
|
|
48
|
-
@markup.
|
48
|
+
@markup.add_regexp_handling(/\\\S/, :SUPPRESSED_CROSSREF)
|
49
49
|
@width = 78
|
50
50
|
init_tags
|
51
51
|
|
@@ -253,10 +253,10 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|
253
253
|
end
|
254
254
|
|
255
255
|
##
|
256
|
-
# Removes preceding \\ from the suppressed crossref +
|
256
|
+
# Removes preceding \\ from the suppressed crossref +target+
|
257
257
|
|
258
|
-
def
|
259
|
-
text =
|
258
|
+
def handle_regexp_SUPPRESSED_CROSSREF target
|
259
|
+
text = target.text
|
260
260
|
text = text.sub('\\', '') unless in_tt?
|
261
261
|
text
|
262
262
|
end
|
@@ -264,7 +264,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|
264
264
|
##
|
265
265
|
# Adds a newline to the output
|
266
266
|
|
267
|
-
def
|
267
|
+
def handle_regexp_HARD_BREAK target
|
268
268
|
"\n"
|
269
269
|
end
|
270
270
|
|
@@ -91,8 +91,8 @@ class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
|
|
91
91
|
when RDoc::Markup::AttrChanger then
|
92
92
|
off_tags res, item
|
93
93
|
on_tags res, item
|
94
|
-
when RDoc::Markup::
|
95
|
-
@res <<
|
94
|
+
when RDoc::Markup::RegexpHandling then
|
95
|
+
@res << convert_regexp_handling(item) if in_tt? # TODO can this happen?
|
96
96
|
else
|
97
97
|
raise "Unknown flow element: #{item.inspect}"
|
98
98
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'ripper'
|
3
3
|
|
4
|
-
class RDoc::RipperStateLex
|
4
|
+
class RDoc::Parser::RipperStateLex
|
5
5
|
# TODO: Remove this constants after Ruby 2.4 EOL
|
6
6
|
RIPPER_HAS_LEX_STATE = Ripper::Filter.method_defined?(:state)
|
7
7
|
|
8
|
+
Token = Struct.new(:line_no, :char_no, :kind, :text, :state)
|
9
|
+
|
8
10
|
EXPR_NONE = 0
|
9
11
|
EXPR_BEG = 1
|
10
12
|
EXPR_END = 2
|
@@ -48,7 +50,7 @@ class RDoc::RipperStateLex
|
|
48
50
|
@continue = false
|
49
51
|
@lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
|
50
52
|
end
|
51
|
-
|
53
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
52
54
|
end
|
53
55
|
|
54
56
|
def on_ignored_nl(tok, data)
|
@@ -59,7 +61,7 @@ class RDoc::RipperStateLex
|
|
59
61
|
@continue = false
|
60
62
|
@lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
|
61
63
|
end
|
62
|
-
|
64
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
63
65
|
end
|
64
66
|
|
65
67
|
def on_op(tok, data)
|
@@ -101,7 +103,7 @@ class RDoc::RipperStateLex
|
|
101
103
|
@lex_state = EXPR_BEG
|
102
104
|
end
|
103
105
|
end
|
104
|
-
|
106
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
105
107
|
end
|
106
108
|
|
107
109
|
def on_kw(tok, data)
|
@@ -114,7 +116,7 @@ class RDoc::RipperStateLex
|
|
114
116
|
@continue = true
|
115
117
|
@in_fname = true
|
116
118
|
when 'if', 'unless', 'while', 'until'
|
117
|
-
if ((EXPR_END | EXPR_ENDARG | EXPR_ENDFN | EXPR_ARG | EXPR_CMDARG) & @lex_state) != 0 # postfix if
|
119
|
+
if ((EXPR_MID | EXPR_END | EXPR_ENDARG | EXPR_ENDFN | EXPR_ARG | EXPR_CMDARG) & @lex_state) != 0 # postfix if
|
118
120
|
@lex_state = EXPR_BEG | EXPR_LABEL
|
119
121
|
else
|
120
122
|
@lex_state = EXPR_BEG
|
@@ -130,54 +132,54 @@ class RDoc::RipperStateLex
|
|
130
132
|
@lex_state = EXPR_END
|
131
133
|
end
|
132
134
|
end
|
133
|
-
|
135
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
134
136
|
end
|
135
137
|
|
136
138
|
def on_tstring_beg(tok, data)
|
137
139
|
@lex_state = EXPR_BEG
|
138
|
-
|
140
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
139
141
|
end
|
140
142
|
|
141
143
|
def on_tstring_end(tok, data)
|
142
144
|
@lex_state = EXPR_END | EXPR_ENDARG
|
143
|
-
|
145
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
144
146
|
end
|
145
147
|
|
146
148
|
def on_CHAR(tok, data)
|
147
149
|
@lex_state = EXPR_END
|
148
|
-
|
150
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
149
151
|
end
|
150
152
|
|
151
153
|
def on_period(tok, data)
|
152
154
|
@lex_state = EXPR_DOT
|
153
|
-
|
155
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
154
156
|
end
|
155
157
|
|
156
158
|
def on_int(tok, data)
|
157
159
|
@lex_state = EXPR_END | EXPR_ENDARG
|
158
|
-
|
160
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
159
161
|
end
|
160
162
|
|
161
163
|
def on_float(tok, data)
|
162
164
|
@lex_state = EXPR_END | EXPR_ENDARG
|
163
|
-
|
165
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
164
166
|
end
|
165
167
|
|
166
168
|
def on_rational(tok, data)
|
167
169
|
@lex_state = EXPR_END | EXPR_ENDARG
|
168
|
-
|
170
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
169
171
|
end
|
170
172
|
|
171
173
|
def on_imaginary(tok, data)
|
172
174
|
@lex_state = EXPR_END | EXPR_ENDARG
|
173
|
-
|
175
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
174
176
|
end
|
175
177
|
|
176
178
|
def on_symbeg(tok, data)
|
177
179
|
@lex_state = EXPR_FNAME
|
178
180
|
@continue = true
|
179
181
|
@in_fname = true
|
180
|
-
|
182
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
181
183
|
end
|
182
184
|
|
183
185
|
private def on_variables(event, tok, data)
|
@@ -196,7 +198,7 @@ class RDoc::RipperStateLex
|
|
196
198
|
else
|
197
199
|
@lex_state = EXPR_CMDARG
|
198
200
|
end
|
199
|
-
|
201
|
+
data << Token.new(lineno, column, event, tok, @lex_state)
|
200
202
|
end
|
201
203
|
|
202
204
|
def on_ident(tok, data)
|
@@ -225,32 +227,32 @@ class RDoc::RipperStateLex
|
|
225
227
|
|
226
228
|
def on_lparen(tok, data)
|
227
229
|
@lex_state = EXPR_LABEL | EXPR_BEG
|
228
|
-
|
230
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
229
231
|
end
|
230
232
|
|
231
233
|
def on_rparen(tok, data)
|
232
234
|
@lex_state = EXPR_ENDFN
|
233
|
-
|
235
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
234
236
|
end
|
235
237
|
|
236
238
|
def on_lbrace(tok, data)
|
237
239
|
@lex_state = EXPR_LABEL | EXPR_BEG
|
238
|
-
|
240
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
239
241
|
end
|
240
242
|
|
241
243
|
def on_rbrace(tok, data)
|
242
244
|
@lex_state = EXPR_ENDARG
|
243
|
-
|
245
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
244
246
|
end
|
245
247
|
|
246
248
|
def on_lbracket(tok, data)
|
247
249
|
@lex_state = EXPR_LABEL | EXPR_BEG
|
248
|
-
|
250
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
249
251
|
end
|
250
252
|
|
251
253
|
def on_rbracket(tok, data)
|
252
254
|
@lex_state = EXPR_ENDARG
|
253
|
-
|
255
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
254
256
|
end
|
255
257
|
|
256
258
|
def on_const(tok, data)
|
@@ -262,41 +264,43 @@ class RDoc::RipperStateLex
|
|
262
264
|
else
|
263
265
|
@lex_state = EXPR_CMDARG
|
264
266
|
end
|
265
|
-
|
267
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
266
268
|
end
|
267
269
|
|
268
270
|
def on_sp(tok, data)
|
269
|
-
|
271
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
270
272
|
end
|
271
273
|
|
272
274
|
def on_comma(tok, data)
|
273
275
|
@lex_state = EXPR_BEG | EXPR_LABEL if (EXPR_ARG_ANY & @lex_state) != 0
|
274
|
-
|
276
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
275
277
|
end
|
276
278
|
|
277
279
|
def on_comment(tok, data)
|
278
280
|
@lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
|
279
|
-
|
281
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
280
282
|
end
|
281
283
|
|
282
284
|
def on_ignored_sp(tok, data)
|
283
285
|
@lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
|
284
|
-
|
286
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
287
|
+
end
|
288
|
+
|
289
|
+
def on_heredoc_beg(tok, data)
|
290
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
291
|
+
@lex_state = EXPR_END
|
292
|
+
data
|
285
293
|
end
|
286
294
|
|
287
295
|
def on_heredoc_end(tok, data)
|
288
|
-
|
296
|
+
data << Token.new(lineno, column, __method__, tok, @lex_state)
|
289
297
|
@lex_state = EXPR_BEG
|
298
|
+
data
|
290
299
|
end
|
291
300
|
|
292
301
|
def on_default(event, tok, data)
|
293
302
|
reset
|
294
|
-
|
295
|
-
end
|
296
|
-
|
297
|
-
def each(&block)
|
298
|
-
@callback = block
|
299
|
-
parse
|
303
|
+
data << Token.new(lineno, column, event, tok, @lex_state)
|
300
304
|
end
|
301
305
|
end unless RIPPER_HAS_LEX_STATE
|
302
306
|
|
@@ -306,21 +310,17 @@ class RDoc::RipperStateLex
|
|
306
310
|
end
|
307
311
|
|
308
312
|
def on_default(event, tok, data)
|
309
|
-
|
310
|
-
end
|
311
|
-
|
312
|
-
def each(&block)
|
313
|
-
@callback = block
|
314
|
-
parse
|
313
|
+
data << Token.new(lineno, column, event, tok, state)
|
315
314
|
end
|
316
315
|
end if RIPPER_HAS_LEX_STATE
|
317
316
|
|
318
317
|
def get_squashed_tk
|
319
318
|
if @buf.empty?
|
320
|
-
tk = @
|
319
|
+
tk = @tokens.shift
|
321
320
|
else
|
322
321
|
tk = @buf.shift
|
323
322
|
end
|
323
|
+
return nil if tk.nil?
|
324
324
|
case tk[:kind]
|
325
325
|
when :on_symbeg then
|
326
326
|
tk = get_symbol_tk(tk)
|
@@ -367,7 +367,7 @@ class RDoc::RipperStateLex
|
|
367
367
|
|
368
368
|
private def get_symbol_tk(tk)
|
369
369
|
is_symbol = true
|
370
|
-
symbol_tk =
|
370
|
+
symbol_tk = Token.new(tk.line_no, tk.char_no, :on_symbol)
|
371
371
|
if ":'" == tk[:text] or ':"' == tk[:text]
|
372
372
|
tk1 = get_string_tk(tk)
|
373
373
|
symbol_tk[:text] = tk1[:text]
|
@@ -436,13 +436,7 @@ class RDoc::RipperStateLex
|
|
436
436
|
end
|
437
437
|
end
|
438
438
|
end
|
439
|
-
|
440
|
-
:line_no => tk[:line_no],
|
441
|
-
:char_no => tk[:char_no],
|
442
|
-
:kind => kind,
|
443
|
-
:text => string,
|
444
|
-
:state => state
|
445
|
-
}
|
439
|
+
Token.new(tk.line_no, tk.char_no, kind, string, state)
|
446
440
|
end
|
447
441
|
|
448
442
|
private def get_regexp_tk(tk)
|
@@ -460,13 +454,7 @@ class RDoc::RipperStateLex
|
|
460
454
|
string = string + inner_str_tk[:text]
|
461
455
|
end
|
462
456
|
end
|
463
|
-
|
464
|
-
:line_no => tk[:line_no],
|
465
|
-
:char_no => tk[:char_no],
|
466
|
-
:kind => :on_regexp,
|
467
|
-
:text => string,
|
468
|
-
:state => state
|
469
|
-
}
|
457
|
+
Token.new(tk.line_no, tk.char_no, :on_regexp, string, state)
|
470
458
|
end
|
471
459
|
|
472
460
|
private def get_embdoc_tk(tk)
|
@@ -475,20 +463,14 @@ class RDoc::RipperStateLex
|
|
475
463
|
string = string + embdoc_tk[:text]
|
476
464
|
end
|
477
465
|
string = string + embdoc_tk[:text]
|
478
|
-
|
479
|
-
:line_no => tk[:line_no],
|
480
|
-
:char_no => tk[:char_no],
|
481
|
-
:kind => :on_embdoc,
|
482
|
-
:text => string,
|
483
|
-
:state => embdoc_tk[:state]
|
484
|
-
}
|
466
|
+
Token.new(tk.line_no, tk.char_no, :on_embdoc, string, embdoc_tk.state)
|
485
467
|
end
|
486
468
|
|
487
469
|
private def get_heredoc_tk(heredoc_name, indent)
|
488
470
|
string = ''
|
489
471
|
start_tk = nil
|
490
472
|
prev_tk = nil
|
491
|
-
until heredoc_end?(heredoc_name, indent, tk = @
|
473
|
+
until heredoc_end?(heredoc_name, indent, tk = @tokens.shift) do
|
492
474
|
start_tk = tk unless start_tk
|
493
475
|
if (prev_tk.nil? or "\n" == prev_tk[:text][-1]) and 0 != tk[:char_no]
|
494
476
|
string = string + (' ' * tk[:char_no])
|
@@ -499,13 +481,7 @@ class RDoc::RipperStateLex
|
|
499
481
|
start_tk = tk unless start_tk
|
500
482
|
prev_tk = tk unless prev_tk
|
501
483
|
@buf.unshift tk # closing heredoc
|
502
|
-
heredoc_tk =
|
503
|
-
:line_no => start_tk[:line_no],
|
504
|
-
:char_no => start_tk[:char_no],
|
505
|
-
:kind => :on_heredoc,
|
506
|
-
:text => string,
|
507
|
-
:state => prev_tk[:state]
|
508
|
-
}
|
484
|
+
heredoc_tk = Token.new(start_tk.line_no, start_tk.char_no, :on_heredoc, string, prev_tk.state)
|
509
485
|
@buf.unshift heredoc_tk
|
510
486
|
end
|
511
487
|
|
@@ -561,13 +537,7 @@ class RDoc::RipperStateLex
|
|
561
537
|
end
|
562
538
|
end
|
563
539
|
text = "#{start_token}#{string}#{end_token}"
|
564
|
-
|
565
|
-
:line_no => line_no,
|
566
|
-
:char_no => char_no,
|
567
|
-
:kind => :on_dstring,
|
568
|
-
:text => text,
|
569
|
-
:state => state
|
570
|
-
}
|
540
|
+
Token.new(line_no, char_no, :on_dstring, text, state)
|
571
541
|
end
|
572
542
|
|
573
543
|
private def get_op_tk(tk)
|
@@ -583,6 +553,10 @@ class RDoc::RipperStateLex
|
|
583
553
|
tk[:text] += tk_ahead[:text]
|
584
554
|
tk[:kind] = tk_ahead[:kind]
|
585
555
|
tk[:state] = tk_ahead[:state]
|
556
|
+
when :on_heredoc_beg, :on_tstring, :on_dstring # frozen/non-frozen string literal
|
557
|
+
tk[:text] += tk_ahead[:text]
|
558
|
+
tk[:kind] = tk_ahead[:kind]
|
559
|
+
tk[:state] = tk_ahead[:state]
|
586
560
|
else
|
587
561
|
@buf.unshift tk_ahead
|
588
562
|
end
|
@@ -594,11 +568,7 @@ class RDoc::RipperStateLex
|
|
594
568
|
@buf = []
|
595
569
|
@heredoc_queue = []
|
596
570
|
@inner_lex = InnerStateLex.new(code)
|
597
|
-
@
|
598
|
-
@inner_lex.each do |tk|
|
599
|
-
y << tk
|
600
|
-
end
|
601
|
-
end
|
571
|
+
@tokens = @inner_lex.parse([])
|
602
572
|
end
|
603
573
|
|
604
574
|
def self.parse(code)
|