summaryrefslogtreecommitdiff
path: root/src/vim9compile.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-06-06 17:02:53 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-06 17:02:53 +0200
commit2067733b5c76e996238af938af36b8196366b7ce (patch)
tree07c435f04c6f6747e9abfe8e796a6c648cb687d1 /src/vim9compile.c
parentc64ed2b714e605930e7c4102d4e80a2b1d9ff9bf (diff)
downloadvim-git-2067733b5c76e996238af938af36b8196366b7ce.tar.gz
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.v8.2.2951
Problem: Vim9: cannot use heredoc in :def function for :python, :lua, etc. Solution: Concatenate the heredoc lines and pass them in the ISN_EXEC_SPLIT instruction.
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r--src/vim9compile.c56
1 files changed, 45 insertions, 11 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 573fa4365..0c73433d5 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -8668,6 +8668,29 @@ theend:
return nextcmd;
}
+/*
+ * A script command with heredoc, e.g.
+ * ruby << EOF
+ * command
+ * EOF
+ * Has been turned into one long line with NL characters by
+ * get_function_body():
+ * ruby << EOF<NL> command<NL>EOF
+ */
+ static char_u *
+compile_script(char_u *line, cctx_T *cctx)
+{
+ if (cctx->ctx_skip != SKIP_YES)
+ {
+ isn_T *isn;
+
+ if ((isn = generate_instr(cctx, ISN_EXEC_SPLIT)) == NULL)
+ return NULL;
+ isn->isn_arg.string = vim_strsave(line);
+ }
+ return (char_u *)"";
+}
+
/*
* :s/pat/repl/
@@ -9480,18 +9503,28 @@ compile_def_function(
line = (char_u *)"";
break;
- default:
- if (cctx.ctx_skip == SKIP_YES)
- {
- // We don't check for a next command here.
- line = (char_u *)"";
- }
- else
- {
- // Not recognized, execute with do_cmdline_cmd().
- ea.arg = p;
+ case CMD_lua:
+ case CMD_mzscheme:
+ case CMD_perl:
+ case CMD_py3:
+ case CMD_python3:
+ case CMD_python:
+ case CMD_pythonx:
+ case CMD_ruby:
+ case CMD_tcl:
+ ea.arg = p;
+ if (vim_strchr(line, '\n') == NULL)
line = compile_exec(line, &ea, &cctx);
- }
+ else
+ // heredoc lines have been concatenated with NL
+ // characters in get_function_body()
+ line = compile_script(line, &cctx);
+ break;
+
+ default:
+ // Not recognized, execute with do_cmdline_cmd().
+ ea.arg = p;
+ line = compile_exec(line, &ea, &cctx);
break;
}
nextline:
@@ -9674,6 +9707,7 @@ delete_instr(isn_T *isn)
{
case ISN_DEF:
case ISN_EXEC:
+ case ISN_EXEC_SPLIT:
case ISN_LEGACY_EVAL:
case ISN_LOADAUTO:
case ISN_LOADB: