Skip to content

Commit 088d1fb

Browse files
committed
Merge branch 'master' into dotdot
2 parents 543ef61 + edd6a79 commit 088d1fb

File tree

8 files changed

+144
-23
lines changed

8 files changed

+144
-23
lines changed

.codecov.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
coverage:
22
status:
3-
project:
4-
default:
5-
target: 0%
6-
patch:
7-
default:
8-
target: 0%
3+
project: yes
4+
patch: yes
5+
changes: no
96

107
comment: false

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[run]
22
plugins = covimerage
3-
data_file = .coverage.covimerage
3+
data_file = .coverage_covimerage

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ script:
3939
after_success:
4040
- covimerage write_coverage $TEST_PROFILE
4141
- coverage xml
42-
- bash <(curl -s https://codecov.io/bash)
42+
- bash <(curl -s https://codecov.io/bash) -f coverage.xml

autoload/vimlparser.vim

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ let s:TOKEN_DOTDOTDOT = 63
205205
let s:TOKEN_SHARP = 64
206206
let s:TOKEN_ARROW = 65
207207
let s:TOKEN_BLOB = 66
208-
let s:TOKEN_DOTDOT = 67
208+
let s:TOKEN_LITCOPEN = 67
209+
let s:TOKEN_DOTDOT = 68
209210

210211
let s:MAX_FUNC_ARGS = 20
211212

@@ -2780,8 +2781,13 @@ function! s:ExprTokenizer.get2()
27802781
call r.seek_cur(1)
27812782
return self.token(s:TOKEN_COLON, ':', pos)
27822783
elseif c ==# '#'
2783-
call r.seek_cur(1)
2784-
return self.token(s:TOKEN_SHARP, '#', pos)
2784+
if r.p(1) ==# '{'
2785+
call r.seek_cur(2)
2786+
return self.token(s:TOKEN_LITCOPEN, '#{', pos)
2787+
else
2788+
call r.seek_cur(1)
2789+
return self.token(s:TOKEN_SHARP, '#', pos)
2790+
endif
27852791
elseif c ==# '('
27862792
call r.seek_cur(1)
27872793
return self.token(s:TOKEN_POPEN, '(', pos)
@@ -2901,6 +2907,29 @@ function! s:ExprTokenizer.get_dstring()
29012907
return s
29022908
endfunction
29032909

2910+
function! s:ExprTokenizer.get_dict_literal_key()
2911+
call self.reader.skip_white()
2912+
let r = self.reader
2913+
let c = r.peek()
2914+
if !s:isalnum(c) && c != '_' && c != '-'
2915+
throw s:Err(printf('unexpected token: %s', token.value), token.pos)
2916+
endif
2917+
let s = c
2918+
call self.reader.seek_cur(1)
2919+
while s:TRUE
2920+
let c = self.reader.p(0)
2921+
if c ==# '<EOF>' || c ==# '<EOL>'
2922+
throw s:Err('unexpectd EOL', self.reader.getpos())
2923+
endif
2924+
if !s:isalnum(c) && c != '_' && c != '-'
2925+
break
2926+
endif
2927+
call self.reader.seek_cur(1)
2928+
let s .= c
2929+
endwhile
2930+
return s
2931+
endfunction
2932+
29042933
let s:ExprParser = {}
29052934

29062935
function! s:ExprParser.new(...)
@@ -3396,6 +3425,7 @@ endfunction
33963425
" 'string'
33973426
" [expr1, ...]
33983427
" {expr1: expr1, ...}
3428+
" #{literal_key1: expr1, ...}
33993429
" {args -> expr1}
34003430
" &option
34013431
" (expr1)
@@ -3452,7 +3482,8 @@ function! s:ExprParser.parse_expr9()
34523482
endif
34533483
endwhile
34543484
endif
3455-
elseif token.type == s:TOKEN_COPEN
3485+
elseif token.type == s:TOKEN_COPEN || token.type == s:TOKEN_LITCOPEN
3486+
let is_litdict = token.type == s:TOKEN_LITCOPEN
34563487
let savepos = self.reader.tell()
34573488
let nodepos = token.pos
34583489
let token = self.tokenizer.get()
@@ -3540,7 +3571,7 @@ function! s:ExprParser.parse_expr9()
35403571
return node
35413572
endif
35423573
while 1
3543-
let key = self.parse_expr1()
3574+
let key = is_litdict ? self.parse_dict_literal_key() : self.parse_expr1()
35443575
let token = self.tokenizer.get()
35453576
if token.type == s:TOKEN_CCLOSE
35463577
if !empty(node.value)
@@ -3605,6 +3636,13 @@ function! s:ExprParser.parse_expr9()
36053636
return node
36063637
endfunction
36073638

3639+
function! s:ExprParser.parse_dict_literal_key()
3640+
let node = s:Node(s:NODE_STRING)
3641+
let node.pos = self.reader.tell()
3642+
let node.value = "'" . self.tokenizer.get_dict_literal_key() . "'"
3643+
return node
3644+
endfunction
3645+
36083646
" SUBSCRIPT or CONCAT
36093647
" dict "." [0-9A-Za-z_]+ => (subscript dict key)
36103648
" str "." expr6 => (concat str expr6)

js/vimlparser.js

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ var TOKEN_DOTDOTDOT = 63;
397397
var TOKEN_SHARP = 64;
398398
var TOKEN_ARROW = 65;
399399
var TOKEN_BLOB = 66;
400-
var TOKEN_DOTDOT = 67;
400+
var TOKEN_LITCOPEN = 67;
401+
var TOKEN_DOTDOT = 68;
401402
var MAX_FUNC_ARGS = 20;
402403
function isalpha(c) {
403404
return viml_eqregh(c, "^[A-Za-z]$");
@@ -2563,8 +2564,14 @@ ExprTokenizer.prototype.get2 = function() {
25632564
return this.token(TOKEN_COLON, ":", pos);
25642565
}
25652566
else if (c == "#") {
2566-
r.seek_cur(1);
2567-
return this.token(TOKEN_SHARP, "#", pos);
2567+
if (r.p(1) == "{") {
2568+
r.seek_cur(2);
2569+
return this.token(TOKEN_LITCOPEN, "#{", pos);
2570+
}
2571+
else {
2572+
r.seek_cur(1);
2573+
return this.token(TOKEN_SHARP, "#", pos);
2574+
}
25682575
}
25692576
else if (c == "(") {
25702577
r.seek_cur(1);
@@ -2708,6 +2715,29 @@ ExprTokenizer.prototype.get_dstring = function() {
27082715
return s;
27092716
}
27102717

2718+
ExprTokenizer.prototype.get_dict_literal_key = function() {
2719+
this.reader.skip_white();
2720+
var r = this.reader;
2721+
var c = r.peek();
2722+
if (!isalnum(c) && c != "_" && c != "-") {
2723+
throw Err(viml_printf("unexpected token: %s", token.value), token.pos);
2724+
}
2725+
var s = c;
2726+
this.reader.seek_cur(1);
2727+
while (TRUE) {
2728+
var c = this.reader.p(0);
2729+
if (c == "<EOF>" || c == "<EOL>") {
2730+
throw Err("unexpectd EOL", this.reader.getpos());
2731+
}
2732+
if (!isalnum(c) && c != "_" && c != "-") {
2733+
break;
2734+
}
2735+
this.reader.seek_cur(1);
2736+
s += c;
2737+
}
2738+
return s;
2739+
}
2740+
27112741
function ExprParser() { this.__init__.apply(this, arguments); }
27122742
ExprParser.prototype.__init__ = function(reader) {
27132743
this.reader = reader;
@@ -3250,6 +3280,7 @@ ExprParser.prototype.parse_expr8 = function() {
32503280
// 'string'
32513281
// [expr1, ...]
32523282
// {expr1: expr1, ...}
3283+
// #{literal_key1: expr1, ...}
32533284
// {args -> expr1}
32543285
// &option
32553286
// (expr1)
@@ -3314,7 +3345,8 @@ ExprParser.prototype.parse_expr9 = function() {
33143345
}
33153346
}
33163347
}
3317-
else if (token.type == TOKEN_COPEN) {
3348+
else if (token.type == TOKEN_COPEN || token.type == TOKEN_LITCOPEN) {
3349+
var is_litdict = token.type == TOKEN_LITCOPEN;
33183350
var savepos = this.reader.tell();
33193351
var nodepos = token.pos;
33203352
var token = this.tokenizer.get();
@@ -3409,7 +3441,7 @@ ExprParser.prototype.parse_expr9 = function() {
34093441
return node;
34103442
}
34113443
while (1) {
3412-
var key = this.parse_expr1();
3444+
var key = is_litdict ? this.parse_dict_literal_key() : this.parse_expr1();
34133445
var token = this.tokenizer.get();
34143446
if (token.type == TOKEN_CCLOSE) {
34153447
if (!viml_empty(node.value)) {
@@ -3485,6 +3517,13 @@ ExprParser.prototype.parse_expr9 = function() {
34853517
return node;
34863518
}
34873519

3520+
ExprParser.prototype.parse_dict_literal_key = function() {
3521+
var node = Node(NODE_STRING);
3522+
node.pos = this.reader.tell();
3523+
node.value = "'" + this.tokenizer.get_dict_literal_key() + "'";
3524+
return node;
3525+
}
3526+
34883527
// SUBSCRIPT or CONCAT
34893528
// dict "." [0-9A-Za-z_]+ => (subscript dict key)
34903529
// str "." expr6 => (concat str expr6)

py/vimlparser.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ def viml_type(obj):
351351
TOKEN_SHARP = 64
352352
TOKEN_ARROW = 65
353353
TOKEN_BLOB = 66
354-
TOKEN_DOTDOT = 67
354+
TOKEN_LITCOPEN = 67
355+
TOKEN_DOTDOT = 68
355356
MAX_FUNC_ARGS = 20
356357
def isalpha(c):
357358
return viml_eqregh(c, "^[A-Za-z]$")
@@ -2032,8 +2033,12 @@ def get2(self):
20322033
r.seek_cur(1)
20332034
return self.token(TOKEN_COLON, ":", pos)
20342035
elif c == "#":
2035-
r.seek_cur(1)
2036-
return self.token(TOKEN_SHARP, "#", pos)
2036+
if r.p(1) == "{":
2037+
r.seek_cur(2)
2038+
return self.token(TOKEN_LITCOPEN, "#{", pos)
2039+
else:
2040+
r.seek_cur(1)
2041+
return self.token(TOKEN_SHARP, "#", pos)
20372042
elif c == "(":
20382043
r.seek_cur(1)
20392044
return self.token(TOKEN_POPEN, "(", pos)
@@ -2140,6 +2145,24 @@ def get_dstring(self):
21402145
s += c
21412146
return s
21422147

2148+
def get_dict_literal_key(self):
2149+
self.reader.skip_white()
2150+
r = self.reader
2151+
c = r.peek()
2152+
if not isalnum(c) and c != "_" and c != "-":
2153+
raise VimLParserException(Err(viml_printf("unexpected token: %s", token.value), token.pos))
2154+
s = c
2155+
self.reader.seek_cur(1)
2156+
while TRUE:
2157+
c = self.reader.p(0)
2158+
if c == "<EOF>" or c == "<EOL>":
2159+
raise VimLParserException(Err("unexpectd EOL", self.reader.getpos()))
2160+
if not isalnum(c) and c != "_" and c != "-":
2161+
break
2162+
self.reader.seek_cur(1)
2163+
s += c
2164+
return s
2165+
21432166
class ExprParser:
21442167
def __init__(self, reader):
21452168
self.reader = reader
@@ -2594,6 +2617,7 @@ def parse_expr8(self):
25942617
# 'string'
25952618
# [expr1, ...]
25962619
# {expr1: expr1, ...}
2620+
# #{literal_key1: expr1, ...}
25972621
# {args -> expr1}
25982622
# &option
25992623
# (expr1)
@@ -2646,7 +2670,8 @@ def parse_expr9(self):
26462670
break
26472671
else:
26482672
raise VimLParserException(Err(viml_printf("unexpected token: %s", token.value), token.pos))
2649-
elif token.type == TOKEN_COPEN:
2673+
elif token.type == TOKEN_COPEN or token.type == TOKEN_LITCOPEN:
2674+
is_litdict = token.type == TOKEN_LITCOPEN
26502675
savepos = self.reader.tell()
26512676
nodepos = token.pos
26522677
token = self.tokenizer.get()
@@ -2722,7 +2747,7 @@ def parse_expr9(self):
27222747
self.tokenizer.get()
27232748
return node
27242749
while 1:
2725-
key = self.parse_expr1()
2750+
key = self.parse_dict_literal_key() if is_litdict else self.parse_expr1()
27262751
token = self.tokenizer.get()
27272752
if token.type == TOKEN_CCLOSE:
27282753
if not viml_empty(node.value):
@@ -2778,6 +2803,12 @@ def parse_expr9(self):
27782803
raise VimLParserException(Err(viml_printf("unexpected token: %s", token.value), token.pos))
27792804
return node
27802805

2806+
def parse_dict_literal_key(self):
2807+
node = Node(NODE_STRING)
2808+
node.pos = self.reader.tell()
2809+
node.value = "'" + self.tokenizer.get_dict_literal_key() + "'"
2810+
return node
2811+
27812812
# SUBSCRIPT or CONCAT
27822813
# dict "." [0-9A-Za-z_]+ => (subscript dict key)
27832814
# str "." expr6 => (concat str expr6)

test/test_litdict.ok

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(echo (dict))
2+
(echo (dict ('foo-bar' 42)))
3+
(echo (dict ('foo-' 42)))
4+
(echo (dict ('-bar' 42)))
5+
(echo (dict ('1-1' 0)))
6+
(echo (dict ('one' 1) ('two2' 2) ('3three' 3) ('44' 4)))
7+
(echo (dict ('x' (dict))))
8+
(echo (list (dict)))

test/test_litdict.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
echo #{}
2+
echo #{foo-bar: 42}
3+
echo #{foo-: 42}
4+
echo #{-bar: 42}
5+
echo #{1-1:0}
6+
echo #{one: 1, two2: 2, 3three: 3, 44: 4}
7+
echo #{x : {},}
8+
echo [#{},]

0 commit comments

Comments
 (0)