Exception: PDoc::ParseError
- Inherits:
-
StandardError
- Object
- StandardError
- PDoc::ParseError
- Defined in:
- lib/pdoc/parser.rb
Overview
Thrown by PDoc::Parser if the documentation is malformed.
Instance Method Summary collapse
- #column ⇒ Object
- #expected_string ⇒ Object
- #failure_reason ⇒ Object
- #failures ⇒ Object
- #index ⇒ Object
-
#initialize(parser) ⇒ ParseError
constructor
A new instance of ParseError.
- #line ⇒ Object
- #message ⇒ Object
- #source_code ⇒ Object
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
#column ⇒ Object
76 77 78 |
# File 'lib/pdoc/parser.rb', line 76 def column @parser.failure_column end |
#expected_string ⇒ Object
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_reason ⇒ Object
95 96 97 |
# File 'lib/pdoc/parser.rb', line 95 def failure_reason "" end |
#failures ⇒ Object
80 81 82 |
# File 'lib/pdoc/parser.rb', line 80 def failures @parser.terminal_failures end |
#index ⇒ Object
84 85 86 |
# File 'lib/pdoc/parser.rb', line 84 def index @parser.failure_index end |
#line ⇒ Object
72 73 74 |
# File 'lib/pdoc/parser.rb', line 72 def line @parser.failure_line end |
#message ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/pdoc/parser.rb', line 62 def " \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_code ⇒ Object
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 |