Merge RDoc-6.5.0
This commit is contained in:
parent
a4e14b9d9d
commit
4cbd3e1944
Notes:
git
2022-12-09 07:36:45 +00:00
@ -209,45 +209,75 @@ class RDoc::Markdown
|
|||||||
attr_accessor :result, :pos
|
attr_accessor :result, :pos
|
||||||
|
|
||||||
def current_column(target=pos)
|
def current_column(target=pos)
|
||||||
if c = string.rindex("\n", target-1)
|
if string[target] == "\n" && (c = string.rindex("\n", target-1) || -1)
|
||||||
return target - c - 1
|
return target - c
|
||||||
|
elsif c = string.rindex("\n", target)
|
||||||
|
return target - c
|
||||||
end
|
end
|
||||||
|
|
||||||
target + 1
|
target + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def position_line_offsets
|
||||||
|
unless @position_line_offsets
|
||||||
|
@position_line_offsets = []
|
||||||
|
total = 0
|
||||||
|
string.each_line do |line|
|
||||||
|
total += line.size
|
||||||
|
@position_line_offsets << total
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@position_line_offsets
|
||||||
|
end
|
||||||
|
|
||||||
if [].respond_to? :bsearch_index
|
if [].respond_to? :bsearch_index
|
||||||
def current_line(target=pos)
|
def current_line(target=pos)
|
||||||
unless @line_offsets
|
if line = position_line_offsets.bsearch_index {|x| x > target }
|
||||||
@line_offsets = []
|
return line + 1
|
||||||
total = 0
|
|
||||||
string.each_line do |line|
|
|
||||||
total += line.size
|
|
||||||
@line_offsets << total
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
raise "Target position #{target} is outside of string"
|
||||||
@line_offsets.bsearch_index {|x| x >= target } + 1 || -1
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
def current_line(target=pos)
|
def current_line(target=pos)
|
||||||
cur_offset = 0
|
if line = position_line_offsets.index {|x| x > target }
|
||||||
cur_line = 0
|
return line + 1
|
||||||
|
|
||||||
string.each_line do |line|
|
|
||||||
cur_line += 1
|
|
||||||
cur_offset += line.size
|
|
||||||
return cur_line if cur_offset >= target
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-1
|
raise "Target position #{target} is outside of string"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_character(target=pos)
|
||||||
|
if target < 0 || target >= string.size
|
||||||
|
raise "Target position #{target} is outside of string"
|
||||||
|
end
|
||||||
|
string[target, 1]
|
||||||
|
end
|
||||||
|
|
||||||
|
KpegPosInfo = Struct.new(:pos, :lno, :col, :line, :char)
|
||||||
|
|
||||||
|
def current_pos_info(target=pos)
|
||||||
|
l = current_line target
|
||||||
|
c = current_column target
|
||||||
|
ln = get_line(l-1)
|
||||||
|
chr = string[target,1]
|
||||||
|
KpegPosInfo.new(target, l, c, ln, chr)
|
||||||
|
end
|
||||||
|
|
||||||
def lines
|
def lines
|
||||||
lines = []
|
string.lines
|
||||||
string.each_line { |l| lines << l }
|
end
|
||||||
lines
|
|
||||||
|
def get_line(no)
|
||||||
|
loff = position_line_offsets
|
||||||
|
if no < 0
|
||||||
|
raise "Line No is out of range: #{no} < 0"
|
||||||
|
elsif no >= loff.size
|
||||||
|
raise "Line No is out of range: #{no} >= #{loff.size}"
|
||||||
|
end
|
||||||
|
lend = loff[no]-1
|
||||||
|
lstart = no > 0 ? loff[no-1] : 0
|
||||||
|
string[lstart..lend]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -261,6 +291,7 @@ class RDoc::Markdown
|
|||||||
@string = string
|
@string = string
|
||||||
@string_size = string ? string.size : 0
|
@string_size = string ? string.size : 0
|
||||||
@pos = pos
|
@pos = pos
|
||||||
|
@position_line_offsets = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_pos
|
def show_pos
|
||||||
@ -285,30 +316,22 @@ class RDoc::Markdown
|
|||||||
end
|
end
|
||||||
|
|
||||||
def failure_caret
|
def failure_caret
|
||||||
l = current_line @failing_rule_offset
|
p = current_pos_info @failing_rule_offset
|
||||||
c = current_column @failing_rule_offset
|
"#{p.line.chomp}\n#{' ' * (p.col - 1)}^"
|
||||||
|
|
||||||
line = lines[l-1]
|
|
||||||
"#{line}\n#{' ' * (c - 1)}^"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure_character
|
def failure_character
|
||||||
l = current_line @failing_rule_offset
|
current_character @failing_rule_offset
|
||||||
c = current_column @failing_rule_offset
|
|
||||||
lines[l-1][c-1, 1]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure_oneline
|
def failure_oneline
|
||||||
l = current_line @failing_rule_offset
|
p = current_pos_info @failing_rule_offset
|
||||||
c = current_column @failing_rule_offset
|
|
||||||
|
|
||||||
char = lines[l-1][c-1, 1]
|
|
||||||
|
|
||||||
if @failed_rule.kind_of? Symbol
|
if @failed_rule.kind_of? Symbol
|
||||||
info = self.class::Rules[@failed_rule]
|
info = self.class::Rules[@failed_rule]
|
||||||
"@#{l}:#{c} failed rule '#{info.name}', got '#{char}'"
|
"@#{p.lno}:#{p.col} failed rule '#{info.name}', got '#{p.char}'"
|
||||||
else
|
else
|
||||||
"@#{l}:#{c} failed rule '#{@failed_rule}', got '#{char}'"
|
"@#{p.lno}:#{p.col} failed rule '#{@failed_rule}', got '#{p.char}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -321,10 +344,9 @@ class RDoc::Markdown
|
|||||||
|
|
||||||
def show_error(io=STDOUT)
|
def show_error(io=STDOUT)
|
||||||
error_pos = @failing_rule_offset
|
error_pos = @failing_rule_offset
|
||||||
line_no = current_line(error_pos)
|
p = current_pos_info(error_pos)
|
||||||
col_no = current_column(error_pos)
|
|
||||||
|
|
||||||
io.puts "On line #{line_no}, column #{col_no}:"
|
io.puts "On line #{p.lno}, column #{p.col}:"
|
||||||
|
|
||||||
if @failed_rule.kind_of? Symbol
|
if @failed_rule.kind_of? Symbol
|
||||||
info = self.class::Rules[@failed_rule]
|
info = self.class::Rules[@failed_rule]
|
||||||
@ -333,10 +355,9 @@ class RDoc::Markdown
|
|||||||
io.puts "Failed to match rule '#{@failed_rule}'"
|
io.puts "Failed to match rule '#{@failed_rule}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
io.puts "Got: #{string[error_pos,1].inspect}"
|
io.puts "Got: #{p.char.inspect}"
|
||||||
line = lines[line_no-1]
|
io.puts "=> #{p.line}"
|
||||||
io.puts "=> #{line}"
|
io.print(" " * (p.col + 2))
|
||||||
io.print(" " * (col_no + 3))
|
|
||||||
io.puts "^"
|
io.puts "^"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -445,6 +466,7 @@ class RDoc::Markdown
|
|||||||
end
|
end
|
||||||
|
|
||||||
def apply_with_args(rule, *args)
|
def apply_with_args(rule, *args)
|
||||||
|
@result = nil
|
||||||
memo_key = [rule, args]
|
memo_key = [rule, args]
|
||||||
if m = @memoizations[memo_key][@pos]
|
if m = @memoizations[memo_key][@pos]
|
||||||
@pos = m.pos
|
@pos = m.pos
|
||||||
@ -478,6 +500,7 @@ class RDoc::Markdown
|
|||||||
end
|
end
|
||||||
|
|
||||||
def apply(rule)
|
def apply(rule)
|
||||||
|
@result = nil
|
||||||
if m = @memoizations[rule][@pos]
|
if m = @memoizations[rule][@pos]
|
||||||
@pos = m.pos
|
@pos = m.pos
|
||||||
if !m.set
|
if !m.set
|
||||||
|
@ -39,45 +39,75 @@ class RDoc::Markdown::Literals
|
|||||||
attr_accessor :result, :pos
|
attr_accessor :result, :pos
|
||||||
|
|
||||||
def current_column(target=pos)
|
def current_column(target=pos)
|
||||||
if c = string.rindex("\n", target-1)
|
if string[target] == "\n" && (c = string.rindex("\n", target-1) || -1)
|
||||||
return target - c - 1
|
return target - c
|
||||||
|
elsif c = string.rindex("\n", target)
|
||||||
|
return target - c
|
||||||
end
|
end
|
||||||
|
|
||||||
target + 1
|
target + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def position_line_offsets
|
||||||
|
unless @position_line_offsets
|
||||||
|
@position_line_offsets = []
|
||||||
|
total = 0
|
||||||
|
string.each_line do |line|
|
||||||
|
total += line.size
|
||||||
|
@position_line_offsets << total
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@position_line_offsets
|
||||||
|
end
|
||||||
|
|
||||||
if [].respond_to? :bsearch_index
|
if [].respond_to? :bsearch_index
|
||||||
def current_line(target=pos)
|
def current_line(target=pos)
|
||||||
unless @line_offsets
|
if line = position_line_offsets.bsearch_index {|x| x > target }
|
||||||
@line_offsets = []
|
return line + 1
|
||||||
total = 0
|
|
||||||
string.each_line do |line|
|
|
||||||
total += line.size
|
|
||||||
@line_offsets << total
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
raise "Target position #{target} is outside of string"
|
||||||
@line_offsets.bsearch_index {|x| x >= target } + 1 || -1
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
def current_line(target=pos)
|
def current_line(target=pos)
|
||||||
cur_offset = 0
|
if line = position_line_offsets.index {|x| x > target }
|
||||||
cur_line = 0
|
return line + 1
|
||||||
|
|
||||||
string.each_line do |line|
|
|
||||||
cur_line += 1
|
|
||||||
cur_offset += line.size
|
|
||||||
return cur_line if cur_offset >= target
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-1
|
raise "Target position #{target} is outside of string"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_character(target=pos)
|
||||||
|
if target < 0 || target >= string.size
|
||||||
|
raise "Target position #{target} is outside of string"
|
||||||
|
end
|
||||||
|
string[target, 1]
|
||||||
|
end
|
||||||
|
|
||||||
|
KpegPosInfo = Struct.new(:pos, :lno, :col, :line, :char)
|
||||||
|
|
||||||
|
def current_pos_info(target=pos)
|
||||||
|
l = current_line target
|
||||||
|
c = current_column target
|
||||||
|
ln = get_line(l-1)
|
||||||
|
chr = string[target,1]
|
||||||
|
KpegPosInfo.new(target, l, c, ln, chr)
|
||||||
|
end
|
||||||
|
|
||||||
def lines
|
def lines
|
||||||
lines = []
|
string.lines
|
||||||
string.each_line { |l| lines << l }
|
end
|
||||||
lines
|
|
||||||
|
def get_line(no)
|
||||||
|
loff = position_line_offsets
|
||||||
|
if no < 0
|
||||||
|
raise "Line No is out of range: #{no} < 0"
|
||||||
|
elsif no >= loff.size
|
||||||
|
raise "Line No is out of range: #{no} >= #{loff.size}"
|
||||||
|
end
|
||||||
|
lend = loff[no]-1
|
||||||
|
lstart = no > 0 ? loff[no-1] : 0
|
||||||
|
string[lstart..lend]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -91,6 +121,7 @@ class RDoc::Markdown::Literals
|
|||||||
@string = string
|
@string = string
|
||||||
@string_size = string ? string.size : 0
|
@string_size = string ? string.size : 0
|
||||||
@pos = pos
|
@pos = pos
|
||||||
|
@position_line_offsets = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_pos
|
def show_pos
|
||||||
@ -115,30 +146,22 @@ class RDoc::Markdown::Literals
|
|||||||
end
|
end
|
||||||
|
|
||||||
def failure_caret
|
def failure_caret
|
||||||
l = current_line @failing_rule_offset
|
p = current_pos_info @failing_rule_offset
|
||||||
c = current_column @failing_rule_offset
|
"#{p.line.chomp}\n#{' ' * (p.col - 1)}^"
|
||||||
|
|
||||||
line = lines[l-1]
|
|
||||||
"#{line}\n#{' ' * (c - 1)}^"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure_character
|
def failure_character
|
||||||
l = current_line @failing_rule_offset
|
current_character @failing_rule_offset
|
||||||
c = current_column @failing_rule_offset
|
|
||||||
lines[l-1][c-1, 1]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure_oneline
|
def failure_oneline
|
||||||
l = current_line @failing_rule_offset
|
p = current_pos_info @failing_rule_offset
|
||||||
c = current_column @failing_rule_offset
|
|
||||||
|
|
||||||
char = lines[l-1][c-1, 1]
|
|
||||||
|
|
||||||
if @failed_rule.kind_of? Symbol
|
if @failed_rule.kind_of? Symbol
|
||||||
info = self.class::Rules[@failed_rule]
|
info = self.class::Rules[@failed_rule]
|
||||||
"@#{l}:#{c} failed rule '#{info.name}', got '#{char}'"
|
"@#{p.lno}:#{p.col} failed rule '#{info.name}', got '#{p.char}'"
|
||||||
else
|
else
|
||||||
"@#{l}:#{c} failed rule '#{@failed_rule}', got '#{char}'"
|
"@#{p.lno}:#{p.col} failed rule '#{@failed_rule}', got '#{p.char}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -151,10 +174,9 @@ class RDoc::Markdown::Literals
|
|||||||
|
|
||||||
def show_error(io=STDOUT)
|
def show_error(io=STDOUT)
|
||||||
error_pos = @failing_rule_offset
|
error_pos = @failing_rule_offset
|
||||||
line_no = current_line(error_pos)
|
p = current_pos_info(error_pos)
|
||||||
col_no = current_column(error_pos)
|
|
||||||
|
|
||||||
io.puts "On line #{line_no}, column #{col_no}:"
|
io.puts "On line #{p.lno}, column #{p.col}:"
|
||||||
|
|
||||||
if @failed_rule.kind_of? Symbol
|
if @failed_rule.kind_of? Symbol
|
||||||
info = self.class::Rules[@failed_rule]
|
info = self.class::Rules[@failed_rule]
|
||||||
@ -163,10 +185,9 @@ class RDoc::Markdown::Literals
|
|||||||
io.puts "Failed to match rule '#{@failed_rule}'"
|
io.puts "Failed to match rule '#{@failed_rule}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
io.puts "Got: #{string[error_pos,1].inspect}"
|
io.puts "Got: #{p.char.inspect}"
|
||||||
line = lines[line_no-1]
|
io.puts "=> #{p.line}"
|
||||||
io.puts "=> #{line}"
|
io.print(" " * (p.col + 2))
|
||||||
io.print(" " * (col_no + 3))
|
|
||||||
io.puts "^"
|
io.puts "^"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -275,6 +296,7 @@ class RDoc::Markdown::Literals
|
|||||||
end
|
end
|
||||||
|
|
||||||
def apply_with_args(rule, *args)
|
def apply_with_args(rule, *args)
|
||||||
|
@result = nil
|
||||||
memo_key = [rule, args]
|
memo_key = [rule, args]
|
||||||
if m = @memoizations[memo_key][@pos]
|
if m = @memoizations[memo_key][@pos]
|
||||||
@pos = m.pos
|
@pos = m.pos
|
||||||
@ -308,6 +330,7 @@ class RDoc::Markdown::Literals
|
|||||||
end
|
end
|
||||||
|
|
||||||
def apply(rule)
|
def apply(rule)
|
||||||
|
@result = nil
|
||||||
if m = @memoizations[rule][@pos]
|
if m = @memoizations[rule][@pos]
|
||||||
@pos = m.pos
|
@pos = m.pos
|
||||||
if !m.set
|
if !m.set
|
||||||
|
Loading…
x
Reference in New Issue
Block a user