Class: TSJSON::Location
- Inherits:
-
Object
- Object
- TSJSON::Location
- Defined in:
- lib/language/lexer/location.rb
Class Method Summary collapse
Class Method Details
.get_location(source, position) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/language/lexer/location.rb', line 3 def self.get_location(source, position) lineRegexp = /\r\n|[\n\r]/ line = 1 column = position + 1 body = source.body new_lines_indexes = (0...body.length).find_all { |i| body[i, 1] == "\n" } new_lines_indexes.each do |index| break if index >= position line += 1 column = position + 1 - (index + 1) end return { line: line, column: column } end |