Skip to content

Commit

Permalink
Use prism as a parser
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Jul 22, 2024
1 parent 92457ba commit 24df3db
Show file tree
Hide file tree
Showing 4 changed files with 800 additions and 2,117 deletions.
16 changes: 9 additions & 7 deletions lib/rdoc/markup/pre_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,18 @@ def initialize(input_file_name, include_path)
# RDoc::CodeObject#metadata for details.

def handle text, code_object = nil, &block
first_line = 1
if RDoc::Comment === text then
comment = text
text = text.text
first_line = comment.line || 1
end

# regexp helper (square brackets for optional)
# $1 $2 $3 $4 $5
# [prefix][\]:directive:[spaces][param]newline
text = text.gsub(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?(\r?\n|$)/) do
text = text.lines.map.with_index(first_line) do |line, num|
next line unless line =~ /\A([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):([\w-]+):([ \t]*)(.+)?(\r?\n|$)/
# skip something like ':toto::'
next $& if $4.empty? and $5 and $5[0, 1] == ':'

Expand All @@ -119,9 +122,8 @@ def handle text, code_object = nil, &block
comment.format = $5.downcase
next "#{$1.strip}\n"
end

handle_directive $1, $3, $5, code_object, text.encoding, &block
end
handle_directive $1, $3, $5, code_object, text.encoding, num, &block
end.join

if comment then
comment.text = text
Expand All @@ -148,7 +150,7 @@ def handle text, code_object = nil, &block
# When 1.8.7 support is ditched prefix can be defaulted to ''

def handle_directive prefix, directive, param, code_object = nil,
encoding = nil
encoding = nil, line = nil
blankline = "#{prefix.strip}\n"
directive = directive.downcase

Expand Down Expand Up @@ -220,11 +222,11 @@ def handle_directive prefix, directive, param, code_object = nil,
# remove parameter &block
code_object.params = code_object.params.sub(/,?\s*&\w+/, '') if code_object.params

code_object.block_params = param
code_object.block_params = param || ''

blankline
else
result = yield directive, param if block_given?
result = yield directive, param, line if block_given?

case result
when nil then
Expand Down
Loading

0 comments on commit 24df3db

Please sign in to comment.