From caf2c738dba5dcc1351288842754524289235d28 Mon Sep 17 00:00:00 2001 From: David Wells Date: Fri, 22 Jan 2016 17:57:41 -0500 Subject: [PATCH] Ignore surrounding whitespace if continuing lines. 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. --- source/base/parameter_handler.cc | 3 + tests/bits/parameter_handler_backslash_06.cc | 59 +++++++++++++++++++ .../parameter_handler_backslash_06.output | 3 + tests/bits/parameter_handler_backslash_07.cc | 57 ++++++++++++++++++ .../parameter_handler_backslash_07.output | 3 + .../prm/parameter_handler_backslash_06.prm | 7 +++ .../prm/parameter_handler_backslash_07.prm | 7 +++ 7 files changed, 139 insertions(+) create mode 100644 tests/bits/parameter_handler_backslash_06.cc create mode 100644 tests/bits/parameter_handler_backslash_06.output create mode 100644 tests/bits/parameter_handler_backslash_07.cc create mode 100644 tests/bits/parameter_handler_backslash_07.output create mode 100644 tests/bits/prm/parameter_handler_backslash_06.prm create mode 100644 tests/bits/prm/parameter_handler_backslash_07.prm diff --git a/source/base/parameter_handler.cc b/source/base/parameter_handler.cc index f41185d0ca..b8ae2f99dc 100644 --- a/source/base/parameter_handler.cc +++ b/source/base/parameter_handler.cc @@ -1346,6 +1346,9 @@ bool ParameterHandler::read_input (std::istream &input, 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. diff --git a/tests/bits/parameter_handler_backslash_06.cc b/tests/bits/parameter_handler_backslash_06.cc new file mode 100644 index 0000000000..867870464e --- /dev/null +++ b/tests/bits/parameter_handler_backslash_06.cc @@ -0,0 +1,59 @@ +// --------------------------------------------------------------------- +// +// 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 +#include +#include + + +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; +} diff --git a/tests/bits/parameter_handler_backslash_06.output b/tests/bits/parameter_handler_backslash_06.output new file mode 100644 index 0000000000..5c8ecde2ba --- /dev/null +++ b/tests/bits/parameter_handler_backslash_06.output @@ -0,0 +1,3 @@ + +DEAL::a, b, c +DEAL::a, b, c diff --git a/tests/bits/parameter_handler_backslash_07.cc b/tests/bits/parameter_handler_backslash_07.cc new file mode 100644 index 0000000000..765352f587 --- /dev/null +++ b/tests/bits/parameter_handler_backslash_07.cc @@ -0,0 +1,57 @@ +// --------------------------------------------------------------------- +// +// 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 +#include +#include + + +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; +} diff --git a/tests/bits/parameter_handler_backslash_07.output b/tests/bits/parameter_handler_backslash_07.output new file mode 100644 index 0000000000..d56fbce00b --- /dev/null +++ b/tests/bits/parameter_handler_backslash_07.output @@ -0,0 +1,3 @@ + +DEAL::value +DEAL::value diff --git a/tests/bits/prm/parameter_handler_backslash_06.prm b/tests/bits/prm/parameter_handler_backslash_06.prm new file mode 100644 index 0000000000..0e25e84786 --- /dev/null +++ b/tests/bits/prm/parameter_handler_backslash_06.prm @@ -0,0 +1,7 @@ +# 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 diff --git a/tests/bits/prm/parameter_handler_backslash_07.prm b/tests/bits/prm/parameter_handler_backslash_07.prm new file mode 100644 index 0000000000..58f82e99d9 --- /dev/null +++ b/tests/bits/prm/parameter_handler_backslash_07.prm @@ -0,0 +1,7 @@ +# whitespace at the beginning of a line is always ignored. +#--------------------------------------------------------- +subsection Testing + set value = val\ + u\ + e +end -- 2.39.5