Exception: PDoc::ParseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/pdoc/parser.rb

Overview

Thrown by PDoc::Parser if the documentation is malformed.

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ ParseError

Returns a new instance of ParseError.



57
58
59
60
# File 'lib/pdoc/parser.rb', line 57

def initialize(parser)
  @parser = parser
  @lines = @parser.input.split("\n").unshift("")
end

Instance Method Details

#columnObject



76
77
78
# File 'lib/pdoc/parser.rb', line 76

def column
  @parser.failure_column
end

#expected_stringObject



99
100
101
102
103
104
105
106
107
# File 'lib/pdoc/parser.rb', line 99

def expected_string
  if failures.size == 1
    failures.first.expected_string.inspect
  else
    expected = failures.map { |f| f.expected_string.inspect }.uniq
    last = expected.pop
    "one of #{expected.join(', ')} or #{last}"
  end
end

#failure_reasonObject



95
96
97
# File 'lib/pdoc/parser.rb', line 95

def failure_reason
  ""
end

#failuresObject



80
81
82
# File 'lib/pdoc/parser.rb', line 80

def failures
  @parser.terminal_failures
end

#indexObject



84
85
86
# File 'lib/pdoc/parser.rb', line 84

def index
  @parser.failure_index
end

#lineObject



72
73
74
# File 'lib/pdoc/parser.rb', line 72

def line
  @parser.failure_line
end

#messageObject



62
63
64
65
66
67
68
69
70
# File 'lib/pdoc/parser.rb', line 62

def message
  "  \nParseError: Expected \#{expected_string} at line \#{line}, column \#{column} (byte \#{index + 1}) after \#{@parser.input[@parser.index...index].inspect}.\n  \n\#{source_code}\n  \n  EOS\nend\n"

#source_codeObject



88
89
90
91
92
93
# File 'lib/pdoc/parser.rb', line 88

def source_code
  ((line-2)..(line+2)).map do |index|
    result = index == line ? "-->" : "   "
    "#{result} #{index.to_s.rjust(5)} #{@lines[index]}"
  end.join("\n")
end