Commit cdc2a704 authored by Tom Lane's avatar Tom Lane

Allow backslash line continuations in pgbench's meta commands.

A pgbench meta command can now be continued onto additional line(s) of a
script file by writing backslash-return.  The continuation marker is
equivalent to white space in that it separates tokens.

Eventually it'd be nice to have the same thing in psql, but that will
be a much larger project.

Fabien Coelho, reviewed by Rafia Sabih

Discussion: https://postgr.es/m/alpine.DEB.2.20.1610031049310.19411@lancre
parent 95473709
...@@ -809,7 +809,8 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</> ...@@ -809,7 +809,8 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
<para> <para>
Script file meta commands begin with a backslash (<literal>\</>) and Script file meta commands begin with a backslash (<literal>\</>) and
extend to the end of the line. normally extend to the end of the line, although they can be continued
to additional lines by writing backslash-return.
Arguments to a meta command are separated by white space. Arguments to a meta command are separated by white space.
These meta commands are supported: These meta commands are supported:
</para> </para>
...@@ -838,7 +839,8 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</> ...@@ -838,7 +839,8 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
Examples: Examples:
<programlisting> <programlisting>
\set ntellers 10 * :scale \set ntellers 10 * :scale
\set aid (1021 * random(1, 100000 * :scale)) % (100000 * :scale) + 1 \set aid (1021 * random(1, 100000 * :scale)) % \
(100000 * :scale) + 1
</programlisting></para> </programlisting></para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -66,6 +66,9 @@ space [ \t\r\f\v] ...@@ -66,6 +66,9 @@ space [ \t\r\f\v]
nonspace [^ \t\r\f\v\n] nonspace [^ \t\r\f\v\n]
newline [\n] newline [\n]
/* Line continuation marker */
continuation \\{newline}
/* Exclusive states */ /* Exclusive states */
%x EXPR %x EXPR
...@@ -96,8 +99,20 @@ newline [\n] ...@@ -96,8 +99,20 @@ newline [\n]
return 1; return 1;
} }
/*
* We need this rule to avoid returning "word\" instead of recognizing
* a continuation marker just after a word:
*/
{nonspace}+{continuation} {
/* Found "word\\\n", emit and return just "word" */
psqlscan_emit(cur_state, yytext, yyleng - 2);
return 1;
}
{space}+ { /* ignore */ } {space}+ { /* ignore */ }
{continuation} { /* ignore */ }
{newline} { {newline} {
/* report end of command */ /* report end of command */
last_was_newline = true; last_was_newline = true;
...@@ -138,14 +153,16 @@ newline [\n] ...@@ -138,14 +153,16 @@ newline [\n]
return FUNCTION; return FUNCTION;
} }
{space}+ { /* ignore */ }
{continuation} { /* ignore */ }
{newline} { {newline} {
/* report end of command */ /* report end of command */
last_was_newline = true; last_was_newline = true;
return 0; return 0;
} }
{space}+ { /* ignore */ }
. { . {
/* /*
* must strdup yytext so that expr_yyerror_more doesn't * must strdup yytext so that expr_yyerror_more doesn't
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment