Mercurial > vim
diff src/vim9compile.c @ 24826:a8d64f1a223b v8.2.2951
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Commit: https://github.com/vim/vim/commit/2067733b5c76e996238af938af36b8196366b7ce
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 6 17:02:53 2021 +0200
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 06 Jun 2021 17:15:03 +0200 |
parents | 7c1375eb1636 |
children | adcd50a18236 |
line wrap: on
line diff
--- 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; + 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: - 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; - line = compile_exec(line, &ea, &cctx); - } + // 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: