Class: Platform::IEL::SexpParser::ParseContext

Inherits:
Object
  • Object
show all
Defined in:
lib/introhive_expression_language/iel/sexp_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ ParseContext

Returns a new instance of ParseContext.



55
56
57
# File 'lib/introhive_expression_language/iel/sexp_parser.rb', line 55

def initialize(code)
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



53
54
55
# File 'lib/introhive_expression_language/iel/sexp_parser.rb', line 53

def code
  @code
end

Instance Method Details

#code_line(offset) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/introhive_expression_language/iel/sexp_parser.rb', line 59

def code_line(offset)
  idx = 0
  line = 1
  pos = 0
  last_line_start = 0
  line_location = 1
  @code.chars.each do |c|
    if c == "\n"
      line += 1
      pos = 0
      last_line_start = idx + 1
    else
      pos += 1
    end
    if idx == offset
      line_location = pos
      break
    end
    idx += 1
  end

  code_line = ''
  @code[last_line_start..-1].chars.each do |c|
    if c == "\n"
      break
    else
      code_line += c
    end
  end

  " at Line #{line}, Pos #{line_location}\n#{code_line}\n#{'-' * (line_location-1)}^"
end