Skip to content

Commit 92d542b

Browse files
committed
add offset in pos
1 parent d7417d0 commit 92d542b

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

autoload/vimlparser.vim

+6-11
Original file line numberDiff line numberDiff line change
@@ -3768,15 +3768,13 @@ endfunction
37683768
function! s:StringReader.__init__(lines)
37693769
let self.buf = []
37703770
let self.pos = []
3771-
let self.offset = []
37723771
let lnum = 0
37733772
let offset = 0
37743773
while lnum < len(a:lines)
37753774
let col = 0
37763775
for c in split(a:lines[lnum], '\zs')
37773776
call add(self.buf, c)
3778-
call add(self.pos, [lnum + 1, col + 1])
3779-
call add(self.offset, offset)
3777+
call add(self.pos, [lnum + 1, col + 1, offset])
37803778
let col += len(c)
37813779
let offset += len(c)
37823780
endfor
@@ -3790,8 +3788,7 @@ function! s:StringReader.__init__(lines)
37903788
endif
37913789
else
37923790
call add(self.buf, c)
3793-
call add(self.pos, [lnum + 2, col + 1])
3794-
call add(self.offset, offset)
3791+
call add(self.pos, [lnum + 2, col + 1, offset])
37953792
endif
37963793
let col += len(c)
37973794
let offset += len(c)
@@ -3800,14 +3797,12 @@ function! s:StringReader.__init__(lines)
38003797
let offset += 1
38013798
endwhile
38023799
call add(self.buf, '<EOL>')
3803-
call add(self.pos, [lnum + 1, col + 1])
3804-
call add(self.offset, offset)
3800+
call add(self.pos, [lnum + 1, col + 1, offset])
38053801
let lnum += 1
38063802
let offset += 1
38073803
endwhile
38083804
" for <EOF>
3809-
call add(self.pos, [lnum + 1, 0])
3810-
call add(self.offset, offset)
3805+
call add(self.pos, [lnum + 1, 0, offset])
38113806
let self.i = 0
38123807
endfunction
38133808

@@ -3901,8 +3896,8 @@ function! s:StringReader.getstr(begin, end)
39013896
endfunction
39023897

39033898
function! s:StringReader.getpos()
3904-
let [lnum, col] = self.pos[self.i]
3905-
return {'i': self.i, 'lnum': lnum, 'col': col, 'offset': self.offset[self.i]}
3899+
let [lnum, col, offset] = self.pos[self.i]
3900+
return {'i': self.i, 'lnum': lnum, 'col': col, 'offset': offset}
39063901
endfunction
39073902

39083903
function! s:StringReader.setpos(pos)

js/vimlparser.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -3662,7 +3662,6 @@ function StringReader() { this.__init__.apply(this, arguments); }
36623662
StringReader.prototype.__init__ = function(lines) {
36633663
this.buf = [];
36643664
this.pos = [];
3665-
this.offset = [];
36663665
var lnum = 0;
36673666
var offset = 0;
36683667
while (lnum < viml_len(lines)) {
@@ -3671,8 +3670,7 @@ StringReader.prototype.__init__ = function(lines) {
36713670
for (var __i7 = 0; __i7 < __c7.length; ++__i7) {
36723671
var c = __c7[__i7];
36733672
viml_add(this.buf, c);
3674-
viml_add(this.pos, [lnum + 1, col + 1]);
3675-
viml_add(this.offset, offset);
3673+
viml_add(this.pos, [lnum + 1, col + 1, offset]);
36763674
col += viml_len(c);
36773675
offset += viml_len(c);
36783676
}
@@ -3689,8 +3687,7 @@ StringReader.prototype.__init__ = function(lines) {
36893687
}
36903688
else {
36913689
viml_add(this.buf, c);
3692-
viml_add(this.pos, [lnum + 2, col + 1]);
3693-
viml_add(this.offset, offset);
3690+
viml_add(this.pos, [lnum + 2, col + 1, offset]);
36943691
}
36953692
col += viml_len(c);
36963693
offset += viml_len(c);
@@ -3699,14 +3696,12 @@ StringReader.prototype.__init__ = function(lines) {
36993696
offset += 1;
37003697
}
37013698
viml_add(this.buf, "<EOL>");
3702-
viml_add(this.pos, [lnum + 1, col + 1]);
3703-
viml_add(this.offset, offset);
3699+
viml_add(this.pos, [lnum + 1, col + 1, offset]);
37043700
lnum += 1;
37053701
offset += 1;
37063702
}
37073703
// for <EOF>
3708-
viml_add(this.pos, [lnum + 1, 0]);
3709-
viml_add(this.offset, offset);
3704+
viml_add(this.pos, [lnum + 1, 0, offset]);
37103705
this.i = 0;
37113706
}
37123707

@@ -3805,7 +3800,8 @@ StringReader.prototype.getpos = function() {
38053800
var __tmp = this.pos[this.i];
38063801
var lnum = __tmp[0];
38073802
var col = __tmp[1];
3808-
return {"i":this.i, "lnum":lnum, "col":col, "offset":this.offset[this.i]};
3803+
var offset = __tmp[2];
3804+
return {"i":this.i, "lnum":lnum, "col":col, "offset":offset};
38093805
}
38103806

38113807
StringReader.prototype.setpos = function(pos) {

py/vimlparser.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -2920,15 +2920,13 @@ class StringReader:
29202920
def __init__(self, lines):
29212921
self.buf = []
29222922
self.pos = []
2923-
self.offset = []
29242923
lnum = 0
29252924
offset = 0
29262925
while lnum < viml_len(lines):
29272926
col = 0
29282927
for c in viml_split(lines[lnum], "\\zs"):
29292928
viml_add(self.buf, c)
2930-
viml_add(self.pos, [lnum + 1, col + 1])
2931-
viml_add(self.offset, offset)
2929+
viml_add(self.pos, [lnum + 1, col + 1, offset])
29322930
col += viml_len(c)
29332931
offset += viml_len(c)
29342932
while lnum + 1 < viml_len(lines) and viml_eqregh(lines[lnum + 1], "^\\s*\\\\"):
@@ -2940,20 +2938,17 @@ def __init__(self, lines):
29402938
skip = FALSE
29412939
else:
29422940
viml_add(self.buf, c)
2943-
viml_add(self.pos, [lnum + 2, col + 1])
2944-
viml_add(self.offset, offset)
2941+
viml_add(self.pos, [lnum + 2, col + 1, offset])
29452942
col += viml_len(c)
29462943
offset += viml_len(c)
29472944
lnum += 1
29482945
offset += 1
29492946
viml_add(self.buf, "<EOL>")
2950-
viml_add(self.pos, [lnum + 1, col + 1])
2951-
viml_add(self.offset, offset)
2947+
viml_add(self.pos, [lnum + 1, col + 1, offset])
29522948
lnum += 1
29532949
offset += 1
29542950
# for <EOF>
2955-
viml_add(self.pos, [lnum + 1, 0])
2956-
viml_add(self.offset, offset)
2951+
viml_add(self.pos, [lnum + 1, 0, offset])
29572952
self.i = 0
29582953

29592954
def eof(self):
@@ -3025,8 +3020,8 @@ def getstr(self, begin, end):
30253020
return r
30263021

30273022
def getpos(self):
3028-
lnum, col = self.pos[self.i]
3029-
return AttributeDict({"i":self.i, "lnum":lnum, "col":col, "offset":self.offset[self.i]})
3023+
lnum, col, offset = self.pos[self.i]
3024+
return AttributeDict({"i":self.i, "lnum":lnum, "col":col, "offset":offset})
30303025

30313026
def setpos(self, pos):
30323027
self.i = pos.i

0 commit comments

Comments
 (0)