Skip to content

Commit b38f1f5

Browse files
committed
fix for compile_heredoc
1 parent 5d510af commit b38f1f5

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

autoload/vimlparser.vim

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5595,16 +5595,10 @@ function! s:Compiler.compile_lambda(node) abort
55955595
endfunction
55965596

55975597
function! s:Compiler.compile_heredoc(node) abort
5598-
if empty(a:node.rlist)
5599-
let rlist = '(list)'
5600-
else
5601-
let rlist = '(list ' . join(map(a:node.rlist, 'self.escape_string(v:val.value)'), ' ') . ')'
5602-
endif
5603-
if empty(a:node.body)
5604-
let body = '(list)'
5605-
else
5606-
let body = '(list ' . join(map(a:node.body, 'self.escape_string(v:val.value)'), ' ') . ')'
5607-
endif
5598+
let rlist = empty(a:node.rlist) ? '(list)'
5599+
\ : '(list ' . join(map(a:node.rlist, 'self.escape_string(v:val.value)'), ' ') . ')'
5600+
let body = empty(a:node.body) ? '(list)'
5601+
\ : '(list ' . join(map(a:node.body, 'self.escape_string(v:val.value)'), ' ') . ')'
56085602
let op = self.escape_string(a:node.op)
56095603
return printf('(heredoc %s %s %s)', rlist, op, body)
56105604
endfunction

go/gocompiler.vim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ function s:GoCompiler.compile_ternary(node)
639639
let right = self.compile(a:node.right)
640640
if cond =~ '^node\.rlist\[\d\]' && left == '"nil"'
641641
return printf('func() string { if %s {return %s} else {return %s.(string)} }()', cond, left, right)
642+
elseif cond =~ '^viml_empty' && left == '"(list)"'
643+
return printf('func() string { if %s {return %s} else {return %s} }()', cond, left, right)
642644
elseif cond == 'is_litdict'
643645
return printf('func() *VimNode { if %s {return %s} else {return %s} }()', cond, left, right)
644646
else
@@ -838,7 +840,6 @@ function s:GoCompiler.compile_call(node)
838840
let rlist = map(a:node.rlist, 'self.compile(v:val)')
839841
let left = self.compile(a:node.left)
840842
if left == 'map' && len(rlist) == 2 && rlist[1] == '"self.compile(v:val)"'
841-
" throw 'NotImplemented: map()'
842843
return printf(join([
843844
\ 'func() []string {',
844845
\ 'var ss []string',
@@ -848,6 +849,16 @@ function s:GoCompiler.compile_call(node)
848849
\ 'return ss',
849850
\ '}()',
850851
\ ], ";"), rlist[0], substitute(rlist[1][1:-2], 'v:val', 'vval', 'g'))
852+
elseif left == 'map' && len(rlist) == 2 && rlist[1] == '"self.escape_string(v:val.value)"'
853+
return printf(join([
854+
\ 'func() []string {',
855+
\ 'var ss []string',
856+
\ 'for _, vval := range %s {',
857+
\ 'ss = append(ss, %s)',
858+
\ '}',
859+
\ 'return ss',
860+
\ '}()',
861+
\ ], ";"), rlist[0], substitute(rlist[1][1:-2], 'v:val\.value', 'vval.value.(string)', 'g'))
851862
elseif left == 'call' && rlist[0][0] =~ '[''"]'
852863
return printf('viml_%s(*%s)', rlist[0][1:-2], rlist[1])
853864
elseif left =~ 'ExArg'

go/vimlparser.go

Lines changed: 26 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)