This commit modifies the behavior present in both
23f306dfc5 (which did
not join lines if there was whitespace following a '\') and
0b962b1103 (which did not trim whitespace at the beginning of continued
lines).
We decided to remove whitespace at the beginning of a continued line
both because it was implemented that way in
23f306dfc5 (i.e., the 'fix'
in
0b962b1103 was wrong) and because it makes writing things
like (example provided by Alberto Sartori)
set Finite element space = FESystem[FE_Q(1)^d-\
FE_DGPMonomial(0)-\
FE_DGPMonomial(0)]
possible.
For the sake of posterity, here is part of the discussion (PR #2101)
which lead to the decision to remove trailing whitespace:
drwells:
I agree with @asartori86 that trailing whitespace is a mistake. I
suppose that I ultimately disagree because I think it is one that we
should 'forgive'. I think we are in agreement that we should join lines
if the last non-whitespace character is a `\`, then.
bangerth:
I agree, too, that trailing whitespace is a mistake. But there are two
options:
* Enforce it. In those cases you'll get an error about the next line not
being what the parser expects, while the file looks completely correct
visually. People will probably spend a long time rubbing their eyes
before they realize the problem.
* Forgive it, at the cost of not being able to support valid cases where
the user wants to have a backslash within the text, followed by only
spaces. That seems like a rare case to happen in practice, and also a
poor choice of syntax for whatever the user wanted to achieve.
From a usability standpoint, option 1 seems more appealing.
while (std::getline (input, input_line))
{
++current_line_n;
+ // Trim the whitespace at the ends of the line here instead of in
+ // scan_line. This makes the continuation line logic a lot simpler.
+ input_line = Utilities::trim (input_line);
// check whether or not the current line should be joined with the next
// line before calling scan_line.
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+
+
+int main ()
+{
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.threshold_double(1.e-10);
+
+ for (unsigned int i = 0; i < 2; ++i)
+ {
+ ParameterHandler prm;
+ prm.enter_subsection ("Testing");
+ prm.declare_entry ("Function",
+ "a",
+ Patterns::List(Patterns::Selection("a|b|c|d|e|f|g|h")));
+ prm.leave_subsection ();
+
+ // test both relevant read_input functions
+ if (i == 0)
+ {
+ prm.read_input(SOURCE_DIR "/prm/parameter_handler_backslash_06.prm");
+ }
+ else
+ {
+ std::ifstream input_stream
+ (SOURCE_DIR "/prm/parameter_handler_backslash_06.prm");
+ prm.read_input(input_stream);
+ }
+
+ std::string list;
+ prm.enter_subsection ("Testing");
+ list = prm.get ("Function");
+ prm.leave_subsection ();
+
+ deallog << list << std::endl;
+ }
+
+ return 0;
+}
--- /dev/null
+
+DEAL::a, b, c
+DEAL::a, b, c
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+
+
+int main ()
+{
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.threshold_double(1.e-10);
+
+ for (unsigned int i = 0; i < 2; ++i)
+ {
+ ParameterHandler prm;
+ prm.enter_subsection ("Testing");
+ prm.declare_entry ("value", "value", Patterns::Anything());
+ prm.leave_subsection ();
+
+ // test both relevant read_input functions
+ if (i == 0)
+ {
+ prm.read_input(SOURCE_DIR "/prm/parameter_handler_backslash_07.prm");
+ }
+ else
+ {
+ std::ifstream input_stream
+ (SOURCE_DIR "/prm/parameter_handler_backslash_07.prm");
+ prm.read_input(input_stream);
+ }
+
+ std::string list;
+ prm.enter_subsection ("Testing");
+ list = prm.get ("value");
+ prm.leave_subsection ();
+
+ deallog << list << std::endl;
+ }
+
+ return 0;
+}
--- /dev/null
+
+DEAL::value
+DEAL::value
--- /dev/null
+# Whitespace characters after '\'s are ignored.
+#----------------------------------------------
+subsection Testing # note the spaces and tab at the end of the next line.
+ set Function = a,\
+ b,\
+ c
+end
--- /dev/null
+# whitespace at the beginning of a line is always ignored.
+#---------------------------------------------------------
+subsection Testing
+ set value = val\
+ u\
+ e
+end