Exception: Ecu::DcmParserError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/ecu/interfaces/dcm/dcm_parser_error.rb

Constant Summary collapse

CTXLENGHT =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#docObject (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

#linenoObject (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

#contextObject



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_endlineObject



30
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 30

def ctx_endline   = @endline ||= [doc.lines.count - 1, lineno + CTXLENGHT].min

#ctx_startlineObject



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_strObject



31
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 31

def fmt_str = "%#{(ctx_endline + 1).to_s.length}d"

#messageObject



13
# File 'lib/ecu/interfaces/dcm/dcm_parser_error.rb', line 13

def message = @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