From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5925F469710 for ; Tue, 26 May 2020 15:20:09 +0300 (MSK) Date: Tue, 26 May 2020 15:11:44 +0300 From: Igor Munkin Message-ID: <20200526121144.GM5455@tarantool.org> References: <20200414123504.48100-1-arkholga@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200414123504.48100-1-arkholga@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH] console: add line carrying backslash List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Olga Arkhangelskaia Cc: tarantool-patches@dev.tarantool.org, alexander.turenko@tarantool.org Olya, Thanks for the patch! Please consider the comments I left below. On 14.04.20, Olga Arkhangelskaia wrote: > When using interactive console(stdin) instead of \set delimiter > with "\", "\" in the end if line can be used. > It looks like the section below doesn't relate to the commit message. > The patch enables "\" only for REPL over stdin. I have troubles to write > tests for stdin input, because in case we attach to the console (remote > or to self) another read (console_read) is used. And in this case I do > not think that we need support backslash, because we stop reading > till "\n" or "\r". > Another problem that I have faced is testing (I have tried remote instance, > console over socket and i little bit of popen. However, all this test take > advantage of console_read and do not touch local_read. > If you have any ideas how to test interactive > console within test-run, please share. I tried the same hack Sasha used here[1]: | $ echo 'int isatty(int fd) { return 1; }' > isatty.c | $ gcc isatty.c -fPIC -shared -o libisatty.so The build without your patch produces the following output: | $ printf 'local a = 0 \\\nfor i = 1, 10 do\na = a + i\nend \\\nprint(a)\n' \ | | LD_PRELOAD=./libisatty.so ./src/tarantool | Tarantool 2.4.0-124-g1f0211b76 | type 'help' for interactive help | tarantool> local a = 0 \ | --- | - error: '[string "local a = 0 \"]:1: unexpected symbol near ''\''' | ... | | tarantool> for i = 1, 10 do | > a = a + i | > end \ | --- | - error: '[string "for i = 1, 10 do..."]:3: unexpected symbol near ''\''' | ... | | tarantool> print(a) | --- | - error: '[string "return print(a)"]:1: variable ''a'' is not declared' | ... | | tarantool>$ After applying your changes no error occurs: | $ printf 'local a = 0 \\\nfor i = 1, 10 do\na = a + i\nend \\\nprint(a)\n' \ | | LD_PRELOAD=./libisatty.so ./src/tarantool | Tarantool 2.4.0-125-g10d7d4b49 | type 'help' for interactive help | tarantool> local a = 0 \ | > for i = 1, 10 do | > a = a + i | > end \ | > print(a) | 55 | --- | ... | | tarantool>$ Thereby, you can make the test the similar way Sasha did for his patch. > > Closes #4317 > --- > Branch: > OKriw/gh-4317-console-support-line-carrying-with-backslash > src/box/lua/console.lua | 18 ++++++++++++------ > 1 file changed, 12 insertions(+), 6 deletions(-) > > diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua > index 17e2c91b2..4c2c7a132 100644 > --- a/src/box/lua/console.lua > +++ b/src/box/lua/console.lua > @@ -573,14 +573,20 @@ local function local_read(self) > break > end > if delim == "" then > - local lang = box.session.language > - if not lang or lang == 'lua' then > - -- stop once a complete Lua statement is entered > - if local_check_lua(buf) then > + -- if no delim is set and line ends with the backslash > + -- continue reading > + if buf:sub(-1, -1) == '\\' then > + buf = buf:sub(0, #buf - 1) > + else > + local lang = box.session.language > + if not lang or lang == 'lua' then > + -- stop once a complete Lua statement is entered > + if local_check_lua(buf) then > + break > + end > + else > break > end > - else > - break > end > elseif #buf >= #delim and buf:sub(#buf - #delim + 1) == delim then > buf = buf:sub(0, #buf - #delim) > -- > 2.20.1 (Apple Git-117) > [1]: https://github.com/tarantool/tarantool/commit/185a7b0175ef264c14e2628ba7f545cb14d81374 -- Best regards, IM