From dd1d5472bf28beba971d2b507fab53dec43939f7 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 10 May 2017 18:46:42 +0300 Subject: Allow multi-line machine manifest options value --- bbot/machine-manifest.cxx | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'bbot/machine-manifest.cxx') diff --git a/bbot/machine-manifest.cxx b/bbot/machine-manifest.cxx index 7f9a030..b7baf7e 100644 --- a/bbot/machine-manifest.cxx +++ b/bbot/machine-manifest.cxx @@ -4,10 +4,14 @@ #include +#include + +#include #include #include #include +using namespace std; using namespace butl; namespace bbot @@ -64,9 +68,16 @@ namespace bbot throw parsing (p.name (), nv.name_line, nv.name_column, d); }; - auto bad_value = [&p, &nv] (const string& d, size_t offset = 0) + // Offsets are used to tie an error to the specific position inside a + // manifest value (possibly a multiline one). + // + auto bad_value = [&p, &nv] ( + const string& d, uint64_t column_offset = 0, uint64_t line_offset = 0) { - throw parsing (p.name (), nv.value_line, nv.value_column + offset, d); + throw parsing (p.name (), + nv.value_line + line_offset, + (line_offset == 0 ? nv.value_column : 1) + column_offset, + d); }; optional type; @@ -106,14 +117,26 @@ namespace bbot strings op; + // Note that when reporting errors we combine the manifest value + // position with the respective error position. + // try { - op = string_parser::parse_quoted (v, false); + istringstream is (v); + tab_parser parser (is, ""); + + tab_fields tl; + while (!(tl = parser.next ()).empty ()) + { + for (auto& tf: tl) + op.emplace_back (move (tf.value)); + } } - catch (const invalid_string& e) + catch (const tab_parsing& e) { - bad_value (string ("invalid machine options: ") + e.what (), - e.position); + bad_value ("invalid machine options: " + e.description, + e.column - 1, + e.line - 1); } if (op.empty ()) -- cgit v1.1