Exception: Ecu::DcmParserError
- Inherits:
-
StandardError
- Object
- StandardError
- Ecu::DcmParserError
- Defined in:
- lib/ecu/interfaces/dcm/dcm_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) ⇒ DcmParserError
constructor
A new instance of DcmParserError.
- #message ⇒ Object
- #present(line, n, highlight) ⇒ Object
Constructor Details
#initialize(msg, lexer) ⇒ DcmParserError
Returns a new instance of DcmParserError.
7 8 9 10 11 |
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 7 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.
6 7 8 |
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 6 def doc @doc end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
6 7 8 |
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 6 def lineno @lineno end |
Instance Method Details
#context ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 14 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
30 |
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 30 def ctx_endline = @endline ||= [doc.lines.count - 1, lineno + CTXLENGHT].min |
#ctx_startline ⇒ Object
29 |
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 29 def ctx_startline = [0, lineno - CTXLENGHT].max |
#fmt(n) ⇒ Object
32 |
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 32 def fmt(n) = fmt_str % n |
#fmt_str ⇒ Object
31 |
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 31 def fmt_str = "%#{(ctx_endline + 1).to_s.length}d" |
#message ⇒ Object
13 |
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 13 def = @msg |
#present(line, n, highlight) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 22 def present(line, n, highlight) case highlight when true then fmt(n) + " => | " + line when false then fmt(n) + " | " + line end end |