Skip to content

Commit 0bdc2ba

Browse files
committed
fix for compile_heredoc
1 parent d96150e commit 0bdc2ba

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
@@ -5600,16 +5600,10 @@ function! s:Compiler.compile_lambda(node) abort
56005600
endfunction
56015601

56025602
function! s:Compiler.compile_heredoc(node) abort
5603-
if empty(a:node.rlist)
5604-
let rlist = '(list)'
5605-
else
5606-
let rlist = '(list ' . join(map(a:node.rlist, 'self.escape_string(v:val.value)'), ' ') . ')'
5607-
endif
5608-
if empty(a:node.body)
5609-
let body = '(list)'
5610-
else
5611-
let body = '(list ' . join(map(a:node.body, 'self.escape_string(v:val.value)'), ' ') . ')'
5612-
endif
5603+
let rlist = empty(a:node.rlist) ? '(list)'
5604+
\ : '(list ' . join(map(a:node.rlist, 'self.escape_string(v:val.value)'), ' ') . ')'
5605+
let body = empty(a:node.body) ? '(list)'
5606+
\ : '(list ' . join(map(a:node.body, 'self.escape_string(v:val.value)'), ' ') . ')'
56135607
let op = self.escape_string(a:node.op)
56145608
return printf('(heredoc %s %s %s)', rlist, op, body)
56155609
endfunction

go/gocompiler.vim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,8 @@ function s:GoCompiler.compile_ternary(node)
642642
let right = self.compile(a:node.right)
643643
if cond =~ '^node\.rlist\[\d\]' && left == '"nil"'
644644
return printf('func() string { if %s {return %s} else {return %s.(string)} }()', cond, left, right)
645+
elseif cond =~ '^viml_empty' && left == '"(list)"'
646+
return printf('func() string { if %s {return %s} else {return %s} }()', cond, left, right)
645647
elseif cond == 'is_litdict'
646648
return printf('func() *VimNode { if %s {return %s} else {return %s} }()', cond, left, right)
647649
else
@@ -841,7 +843,6 @@ function s:GoCompiler.compile_call(node)
841843
let rlist = map(a:node.rlist, 'self.compile(v:val)')
842844
let left = self.compile(a:node.left)
843845
if left == 'map' && len(rlist) == 2 && rlist[1] == '"self.compile(v:val)"'
844-
" throw 'NotImplemented: map()'
845846
return printf(join([
846847
\ 'func() []string {',
847848
\ 'var ss []string',
@@ -851,6 +852,16 @@ function s:GoCompiler.compile_call(node)
851852
\ 'return ss',
852853
\ '}()',
853854
\ ], ";"), rlist[0], substitute(rlist[1][1:-2], 'v:val', 'vval', 'g'))
855+
elseif left == 'map' && len(rlist) == 2 && rlist[1] == '"self.escape_string(v:val.value)"'
856+
return printf(join([
857+
\ 'func() []string {',
858+
\ 'var ss []string',
859+
\ 'for _, vval := range %s {',
860+
\ 'ss = append(ss, %s)',
861+
\ '}',
862+
\ 'return ss',
863+
\ '}()',
864+
\ ], ";"), rlist[0], substitute(rlist[1][1:-2], 'v:val\.value', 'vval.value.(string)', 'g'))
854865
elseif left == 'call' && rlist[0][0] =~ '[''"]'
855866
return printf('viml_%s(*%s)', rlist[0][1:-2], rlist[1])
856867
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)