Exception: Ecu::LabParserError
- Inherits:
-
StandardError
- Object
- StandardError
- Ecu::LabParserError
- Defined in:
- lib/ecu/interfaces/lab/lab_parser_error.rb
Constant Summary collapse
- CTXLENGHT =
5
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
Instance Method Summary collapse
- #context ⇒ Object
- #ctx_endline ⇒ Object
- #ctx_startline ⇒ Object
- #fmt(n) ⇒ Object
- #fmt_str ⇒ Object
-
#initialize(msg, lexer) ⇒ LabParserError
constructor
A new instance of LabParserError.
- #message ⇒ Object
- #present(line, n, highlight) ⇒ Object
Constructor Details
#initialize(msg, lexer) ⇒ LabParserError
Returns a new instance of LabParserError.
10 11 12 13 14 |
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 10 def initialize(msg, lexer) @msg = msg @doc = lexer.doc @lineno = lexer.lineno end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
9 10 11 |
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 9 def doc @doc end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
9 10 11 |
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 9 def lineno @lineno end |
Instance Method Details
#context ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 17 def context @doc .lines[ctx_startline..ctx_endline] .each .with_index(ctx_startline + 1) .map { |line, n| present(line, n, n == lineno) } end |
#ctx_endline ⇒ Object
33 |
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 33 def ctx_endline = @endline ||= [doc.lines.count - 1, lineno + CTXLENGHT].min |
#ctx_startline ⇒ Object
32 |
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 32 def ctx_startline = [0, lineno - CTXLENGHT].max |
#fmt(n) ⇒ Object
35 |
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 35 def fmt(n) = fmt_str % n |
#fmt_str ⇒ Object
34 |
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 34 def fmt_str = "%#{(ctx_endline + 1).to_s.length}d" |
#message ⇒ Object
16 |
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 16 def = @msg |
#present(line, n, highlight) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 25 def present(line, n, highlight) case highlight when true then fmt(n) + " => | " + line when false then fmt(n) + " | " + line end end |