Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change s:isnamec to only include colon with scope #81

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
14 changes: 1 addition & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ git:

matrix:
include:
- env:
- VIM_VERSION=v7.4
- MAKE_TARGET=test
- TEST_PROFILE=vim-profile-v7.4.txt
- env:
- VIM_VERSION=v8.0.0000
- MAKE_TARGET=test
- TEST_PROFILE=vim-profile-v8.0.txt
- env:
- VIM_VERSION=master
- MAKE_TARGET=test
- TEST_PROFILE=vim-profile-master.txt
- env:
- VIM_VERSION=installed
- MAKE_TARGET="clean_compiled check js/test py/test test/node_position/test_position.out"
Expand All @@ -34,7 +22,7 @@ script:
- uname -a
- which -a vim
- vim --cmd version --cmd quit
- make $MAKE_TARGET
- make --keep-going $MAKE_TARGET

after_success:
- covimerage write_coverage $TEST_PROFILE
Expand Down
18 changes: 15 additions & 3 deletions autoload/vimlparser.vim
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function! s:iswhite(c)
endfunction

function! s:isnamec(c)
return a:c =~# '^[0-9A-Za-z_:#]$'
return a:c =~# '^[0-9A-Za-z_#]$'
endfunction

function! s:isnamec1(c)
Expand Down Expand Up @@ -3570,7 +3570,8 @@ function! s:ExprParser.parse_dot(token, left)
endif
let pos = self.reader.getpos()
let name = self.reader.read_word()
if s:isnamec(self.reader.p(0))
let c = self.reader.p(0)
if c ==# ':' || c ==# '#'
" XXX: foo is str => ok, foo is obj => invalid expression
" foo.s:bar or foo.bar#baz
return s:NIL
Expand Down Expand Up @@ -3979,7 +3980,18 @@ function! s:StringReader.read_nonwhite()
endfunction

function! s:StringReader.read_name()
let r = ''
" We come here for valid names only.
let r = self.getn(1)

" Colon only allowed at 2nd position, with scope identifiers.
let c = self.peekn(1)
if c ==# ':'
if r !~# '[vgslabwt]'
return r
endif
let r .= self.getn(1)
endif

while s:isnamec(self.peekn(1))
let r .= self.getn(1)
endwhile
Expand Down
3 changes: 2 additions & 1 deletion js/vimlfunc.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ var pat_vim2js = {
"^[0-9A-Fa-f]$" : "^[0-9A-Fa-f]$",
"^[0-9A-Za-z_]$" : "^[0-9A-Za-z_]$",
"^[A-Za-z_]$" : "^[A-Za-z_]$",
"^[0-9A-Za-z_:#]$" : "^[0-9A-Za-z_:#]$",
"^[0-9A-Za-z_#]$" : "^[0-9A-Za-z_#]$",
"^[A-Za-z_][0-9A-Za-z_]*$" : "^[A-Za-z_][0-9A-Za-z_]*$",
"^[A-Z]$" : "^[A-Z]$",
"^[a-z]$" : "^[a-z]$",
"^[vgslabwt]:$\\|^\\([vgslabwt]:\\)\\?[A-Za-z_][0-9A-Za-z_#]*$" : "^[vgslabwt]:$|^([vgslabwt]:)?[A-Za-z_][0-9A-Za-z_#]*$",
"[vgslabwt]" : "[vgslabwt]",
"^[0-7]$" : "^[0-7]$",
}

Expand Down
19 changes: 15 additions & 4 deletions js/vimlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ var pat_vim2js = {
"^[0-9A-Fa-f]$" : "^[0-9A-Fa-f]$",
"^[0-9A-Za-z_]$" : "^[0-9A-Za-z_]$",
"^[A-Za-z_]$" : "^[A-Za-z_]$",
"^[0-9A-Za-z_:#]$" : "^[0-9A-Za-z_:#]$",
"^[0-9A-Za-z_#]$" : "^[0-9A-Za-z_#]$",
"^[A-Za-z_][0-9A-Za-z_]*$" : "^[A-Za-z_][0-9A-Za-z_]*$",
"^[A-Z]$" : "^[A-Z]$",
"^[a-z]$" : "^[a-z]$",
"^[vgslabwt]:$\\|^\\([vgslabwt]:\\)\\?[A-Za-z_][0-9A-Za-z_#]*$" : "^[vgslabwt]:$|^([vgslabwt]:)?[A-Za-z_][0-9A-Za-z_#]*$",
"[vgslabwt]" : "[vgslabwt]",
"^[0-7]$" : "^[0-7]$",
}

Expand Down Expand Up @@ -426,7 +427,7 @@ function iswhite(c) {
}

function isnamec(c) {
return viml_eqregh(c, "^[0-9A-Za-z_:#]$");
return viml_eqregh(c, "^[0-9A-Za-z_#]$");
}

function isnamec1(c) {
Expand Down Expand Up @@ -3455,7 +3456,8 @@ ExprParser.prototype.parse_dot = function(token, left) {
}
var pos = this.reader.getpos();
var name = this.reader.read_word();
if (isnamec(this.reader.p(0))) {
var c = this.reader.p(0);
if (c == ":" || c == "#") {
// XXX: foo is str => ok, foo is obj => invalid expression
// foo.s:bar or foo.bar#baz
return NIL;
Expand Down Expand Up @@ -3883,7 +3885,16 @@ StringReader.prototype.read_nonwhite = function() {
}

StringReader.prototype.read_name = function() {
var r = "";
// We come here for valid names only.
var r = this.getn(1);
// Colon only allowed at 2nd position, with scope identifiers.
var c = this.peekn(1);
if (c == ":") {
if (!viml_eqregh(r, "[vgslabwt]")) {
return r;
}
r += this.getn(1);
}
while (isnamec(this.peekn(1))) {
r += this.getn(1);
}
Expand Down
3 changes: 2 additions & 1 deletion py/vimlfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ class AttributeDict(dict):
"^[0-9A-Fa-f]$" : "^[0-9A-Fa-f]$",
"^[0-9A-Za-z_]$" : "^[0-9A-Za-z_]$",
"^[A-Za-z_]$" : "^[A-Za-z_]$",
"^[0-9A-Za-z_:#]$" : "^[0-9A-Za-z_:#]$",
"^[0-9A-Za-z_#]$" : "^[0-9A-Za-z_#]$",
"^[A-Za-z_][0-9A-Za-z_]*$" : "^[A-Za-z_][0-9A-Za-z_]*$",
"^[A-Z]$" : "^[A-Z]$",
"^[a-z]$" : "^[a-z]$",
"^[vgslabwt]:$\\|^\\([vgslabwt]:\\)\\?[A-Za-z_][0-9A-Za-z_#]*$" : "^[vgslabwt]:$|^([vgslabwt]:)?[A-Za-z_][0-9A-Za-z_#]*$",
"[vgslabwt]" : "[vgslabwt]",
"^[0-7]$" : "^[0-7]$",
}

Expand Down
17 changes: 13 additions & 4 deletions py/vimlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ class AttributeDict(dict):
"^[0-9A-Fa-f]$" : "^[0-9A-Fa-f]$",
"^[0-9A-Za-z_]$" : "^[0-9A-Za-z_]$",
"^[A-Za-z_]$" : "^[A-Za-z_]$",
"^[0-9A-Za-z_:#]$" : "^[0-9A-Za-z_:#]$",
"^[0-9A-Za-z_#]$" : "^[0-9A-Za-z_#]$",
"^[A-Za-z_][0-9A-Za-z_]*$" : "^[A-Za-z_][0-9A-Za-z_]*$",
"^[A-Z]$" : "^[A-Z]$",
"^[a-z]$" : "^[a-z]$",
"^[vgslabwt]:$\\|^\\([vgslabwt]:\\)\\?[A-Za-z_][0-9A-Za-z_#]*$" : "^[vgslabwt]:$|^([vgslabwt]:)?[A-Za-z_][0-9A-Za-z_#]*$",
"[vgslabwt]" : "[vgslabwt]",
"^[0-7]$" : "^[0-7]$",
}

Expand Down Expand Up @@ -372,7 +373,7 @@ def iswhite(c):
return viml_eqregh(c, "^[ \\t]$")

def isnamec(c):
return viml_eqregh(c, "^[0-9A-Za-z_:#]$")
return viml_eqregh(c, "^[0-9A-Za-z_#]$")

def isnamec1(c):
return viml_eqregh(c, "^[A-Za-z_]$")
Expand Down Expand Up @@ -2752,7 +2753,8 @@ def parse_dot(self, token, left):
return NIL
pos = self.reader.getpos()
name = self.reader.read_word()
if isnamec(self.reader.p(0)):
c = self.reader.p(0)
if c == ":" or c == "#":
# XXX: foo is str => ok, foo is obj => invalid expression
# foo.s:bar or foo.bar#baz
return NIL
Expand Down Expand Up @@ -3085,7 +3087,14 @@ def read_nonwhite(self):
return r

def read_name(self):
r = ""
# We come here for valid names only.
r = self.getn(1)
# Colon only allowed at 2nd position, with scope identifiers.
c = self.peekn(1)
if c == ":":
if not viml_eqregh(r, "[vgslabwt]"):
return r
r += self.getn(1)
while isnamec(self.peekn(1)):
r += self.getn(1)
return r
Expand Down
5 changes: 5 additions & 0 deletions test/test_slice_var.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(let = s '123')
(let = a 1)
(let = b (- 1))
(echo (slice s a b))
(echo (slice s a b))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function! s:do_test(b)
  let v = [1,2,3]
  echo v[a:b]
endfunction

call s:do_test(1)

This should be 2.

5 changes: 5 additions & 0 deletions test/test_slice_var.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let s = '123'
let a = 1
let b = -1
echo s[a : b]
echo s[a:b]