You have rules for{nonspace}+ [...] {continuation} Remember that flex always takes the rule that produces the longest match starting at the current point. {space}+ and {newline} don't conflict with continuations, but {nonspace}+ does:
Indeed, I totally overlooked "{nonspace}+".
[...] I think this is surprising and inconsistent.
Sure.
Probably the easiest fix is to add a rule that explicitly matches this
situation:
{nonspace}+{continuation} { ... throw back 2 chars and return the rest ... }
Well, as the continuation characters must be ignored, so there is no need to throw them back, just adding the special case is enough?
Attached a patch which adds the rule and just sends the found word, plus a test script which also exercises this particular case.
Note anyway that it is not necessarily what people may intend when using a continuation:
foo\
bla
might mean "foobla" rather than "foo" then "bla". For instance with bash:
sh>ec\
> ho 1
1
But the same trick in python gives a syntax error:
py> print\
... (1)
1 # ok...
py> pri\
... nt(1)
File "<stdin>", line 2
nt(1)
^
SyntaxError: invalid syntax
I think it fine if pgbench behaves as python.
--
Fabien.diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index 3fb29f8..eb0e8ac 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -810,6 +810,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
<para>
Script file meta commands begin with a backslash (<literal>\</>) and
extend to the end of the line.
+ They can spread over several lines with backslash-return continuations.
Arguments to a meta command are separated by white space.
These meta commands are supported:
</para>
@@ -838,7 +839,8 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
Examples:
<programlisting>
\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>
</listitem>
</varlistentry>
diff --git a/src/bin/pgbench/exprscan.l b/src/bin/pgbench/exprscan.l
index 9a3be3d..ec58ae3 100644
--- a/src/bin/pgbench/exprscan.l
+++ b/src/bin/pgbench/exprscan.l
@@ -65,6 +65,7 @@ alnum [a-zA-Z0-9_]
space [ \t\r\f\v]
nonspace [^ \t\r\f\v\n]
newline [\n]
+continuation \\{newline}
/* Exclusive states */
%x EXPR
@@ -90,6 +91,11 @@ newline [\n]
/* INITIAL state */
+{nonspace}+{continuation} {
+ /* Found "word\\\n", just emit word and return it */
+ psqlscan_emit(cur_state, yytext, yyleng-2);
+ return 1;
+ }
{nonspace}+ {
/* Found a word, emit and return it */
psqlscan_emit(cur_state, yytext, yyleng);
@@ -104,6 +110,8 @@ newline [\n]
return 0;
}
+{continuation} { /* ignore */ }
+
/* EXPR state */
<EXPR>{
@@ -138,6 +146,8 @@ newline [\n]
return FUNCTION;
}
+{continuation} { /* ignore */ }
+
{newline} {
/* report end of command */
last_was_newline = true;
cont.sql
Description: application/sql
-- Sent via pgsql-hackers mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
