aboutsummaryrefslogtreecommitdiff
path: root/libbutl/manifest-parser.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-04-18 20:15:46 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-04-25 19:43:36 +0300
commit276f68ee4d55befa8922378199b4281c82d4fd93 (patch)
treeaf1c1b94fddec588feefe79a86e6463094ba2d8e /libbutl/manifest-parser.cxx
parent7a1c91dbdbde1c4feeaa701592365bb4b7cf2562 (diff)
Add parse_manifest() and serialize_manifest() functions
Diffstat (limited to 'libbutl/manifest-parser.cxx')
-rw-r--r--libbutl/manifest-parser.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/libbutl/manifest-parser.cxx b/libbutl/manifest-parser.cxx
index 697273a..49b9ee0 100644
--- a/libbutl/manifest-parser.cxx
+++ b/libbutl/manifest-parser.cxx
@@ -10,6 +10,7 @@
#ifndef __cpp_lib_modules
#include <string>
+#include <vector>
#include <cstdint>
#include <utility>
#include <stdexcept>
@@ -28,6 +29,7 @@ module butl.manifest_parser;
import std.core;
import std.io;
#endif
+import butl.optional;
import butl.char_scanner;
import butl.manifest_types;
#endif
@@ -481,4 +483,44 @@ namespace butl
line (0), column (0), description (d)
{
}
+
+ // parse_manifest
+ //
+ static bool
+ try_parse_manifest (manifest_parser& p,
+ vector<manifest_name_value>& r,
+ bool allow_eos)
+ {
+ // Read the format version or eos pair. Note that the version is verified
+ // by the parser.
+ //
+ manifest_name_value nv (p.next ());
+
+ // Bail out if eos is reached and is allowed.
+ //
+ if (nv.empty () && allow_eos)
+ return false;
+
+ if (!nv.name.empty () || nv.empty ())
+ throw manifest_parsing (p.name (),
+ nv.value_line, nv.value_column,
+ "start of manifest expected");
+
+ for (nv = p.next (); !nv.empty (); nv = p.next ())
+ r.push_back (move (nv));
+
+ return true;
+ }
+
+ bool
+ try_parse_manifest (manifest_parser& p, vector<manifest_name_value>& r)
+ {
+ return try_parse_manifest (p, r, true /* allow_eos */);
+ }
+
+ void
+ parse_manifest (manifest_parser& p, std::vector<manifest_name_value>& r)
+ {
+ try_parse_manifest (p, r, false /* allow_eos */);
+ }
}