Skip to content

Commit e96d747

Browse files
authored
Merge pull request #512 from aycabta/use-ripper
Use Ripper for lexical analyser
2 parents ba49e2f + 1946c08 commit e96d747

14 files changed

+1193
-2012
lines changed

lib/rdoc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def self.load_yaml
148148

149149
autoload :KNOWN_CLASSES, 'rdoc/known_classes'
150150

151-
autoload :RubyLex, 'rdoc/ruby_lex'
151+
autoload :RipperStateLex, 'rdoc/parser/ripper_state_lex'
152152
autoload :RubyToken, 'rdoc/ruby_token'
153153
autoload :TokenStream, 'rdoc/token_stream'
154154

lib/rdoc/markup/to_html.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,12 @@ def accept_verbatim verbatim
200200

201201
content = if verbatim.ruby? or parseable? text then
202202
begin
203-
tokens = RDoc::RubyLex.tokenize text, @options
203+
tokens = RDoc::RipperStateLex.parse text
204204
klass = ' class="ruby"'
205205

206-
RDoc::TokenStream.to_html tokens
206+
result = RDoc::TokenStream.to_html tokens
207+
result = result + "\n" unless "\n" == result[-1]
208+
result
207209
rescue RDoc::RubyLex::Error
208210
CGI.escapeHTML text
209211
end
@@ -212,7 +214,7 @@ def accept_verbatim verbatim
212214
end
213215

214216
if @options.pipe then
215-
@res << "\n<pre><code>#{CGI.escapeHTML text}</code></pre>\n"
217+
@res << "\n<pre><code>#{CGI.escapeHTML text}\n</code></pre>\n"
216218
else
217219
@res << "\n<pre#{klass}>#{content}</pre>\n"
218220
end

lib/rdoc/parser/c.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,7 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
666666

667667
#meth_obj.params = params
668668
meth_obj.start_collecting_tokens
669-
tk = RDoc::RubyToken::Token.new nil, 1, 1
670-
tk.set_text body
669+
tk = { :line_no => 1, :char_no => 1, :text => body }
671670
meth_obj.add_token tk
672671
meth_obj.comment = comment
673672
meth_obj.line = file_content[0, offset].count("\n") + 1
@@ -684,8 +683,7 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
684683
find_modifiers comment, meth_obj
685684

686685
meth_obj.start_collecting_tokens
687-
tk = RDoc::RubyToken::Token.new nil, 1, 1
688-
tk.set_text body
686+
tk = { :line_no => 1, :char_no => 1, :text => body }
689687
meth_obj.add_token tk
690688
meth_obj.comment = comment
691689
meth_obj.line = file_content[0, offset].count("\n") + 1

0 commit comments

Comments
 (0)