Exception: Ecu::LabParserError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/ecu/interfaces/lab/lab_parser_error.rb

Constant Summary collapse

CTXLENGHT =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

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

#contextObject



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_endlineObject



33
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 33

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

#ctx_startlineObject



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_strObject



34
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 34

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

#messageObject



16
# File 'lib/ecu/interfaces/lab/lab_parser_error.rb', line 16

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