aboutsummaryrefslogtreecommitdiff
path: root/bpkg
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-06-11 18:12:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-06-11 18:12:09 +0200
commitc552070230c4ad9c92b516c28658b5c74c57e46b (patch)
treebc78a4c9c5c9bfb21539e3e65f713a7f0daa766b /bpkg
parent294f8e8d3abebaaa976c7d21248a1a205c869b02 (diff)
Outline of parsing and serialization for manifest object model
Diffstat (limited to 'bpkg')
-rw-r--r--bpkg/manifest23
-rw-r--r--bpkg/manifest-parser38
-rw-r--r--bpkg/manifest-parser.cxx2
-rw-r--r--bpkg/manifest.cxx79
4 files changed, 120 insertions, 22 deletions
diff --git a/bpkg/manifest b/bpkg/manifest
index bf17a64..a02a4a0 100644
--- a/bpkg/manifest
+++ b/bpkg/manifest
@@ -12,6 +12,10 @@
namespace bpkg
{
+ class manifest_parser;
+ class manifest_serializer;
+ class manifest_name_value;
+
using strings = std::vector<std::string>;
// priority
@@ -101,8 +105,9 @@ namespace bpkg
std::string comment;
};
- struct manifest
+ class manifest
{
+ public:
using priority_type = bpkg::priority;
using url_type = bpkg::url;
using email_type = bpkg::email;
@@ -121,9 +126,23 @@ namespace bpkg
butl::optional<email_type> package_email;
std::vector<dependency_alternatives> dependencies;
std::vector<requirement_alternatives> requirements;
+
+ public:
+ manifest (manifest_parser&);
+ manifest (manifest_parser&, const manifest_name_value& start);
+
+ void
+ serialize (manifest_serializer&) const;
};
- using manifests = std::vector<manifest>;
+ class manifests: public std::vector<manifest>
+ {
+ public:
+ manifests (manifest_parser&);
+
+ void
+ serialize (manifest_serializer&) const;
+ };
}
#endif // BPKG_MANIFEST
diff --git a/bpkg/manifest-parser b/bpkg/manifest-parser
index 070cb77..6dc3ee3 100644
--- a/bpkg/manifest-parser
+++ b/bpkg/manifest-parser
@@ -26,6 +26,22 @@ namespace bpkg
std::string description;
};
+ class manifest_name_value
+ {
+ public:
+ std::string name;
+ std::string value;
+
+ std::uint64_t name_line;
+ std::uint64_t name_column;
+
+ std::uint64_t value_line;
+ std::uint64_t value_column;
+
+ bool
+ empty () const {return name.empty () && value.empty ();}
+ };
+
class manifest_parser
{
public:
@@ -35,22 +51,6 @@ namespace bpkg
const std::string&
name () const {return name_;}
- class name_value_type
- {
- public:
- std::string name;
- std::string value;
-
- std::uint64_t name_line;
- std::uint64_t name_column;
-
- std::uint64_t value_line;
- std::uint64_t value_column;
-
- bool
- empty () const {return name.empty () && value.empty ();}
- };
-
// The first returned pair is special "start-of-manifest" with
// empty name and value being the format version: {"", "<ver>"}.
// After that we have a sequence of ordinary pairs which are
@@ -64,7 +64,7 @@ namespace bpkg
//
// ({"", "<ver>"} {"<name>", "<value>"}* {"", ""})* {"", ""}
//
- name_value_type
+ manifest_name_value
next ();
private:
@@ -94,10 +94,10 @@ namespace bpkg
private:
void
- parse_name (name_value_type&);
+ parse_name (manifest_name_value&);
void
- parse_value (name_value_type&);
+ parse_value (manifest_name_value&);
// Skip spaces and return the first peeked non-space character.
//
diff --git a/bpkg/manifest-parser.cxx b/bpkg/manifest-parser.cxx
index 037b874..f8a2e36 100644
--- a/bpkg/manifest-parser.cxx
+++ b/bpkg/manifest-parser.cxx
@@ -12,7 +12,7 @@ using namespace std;
namespace bpkg
{
using parsing = manifest_parsing;
- using name_value = manifest_parser::name_value_type;
+ using name_value = manifest_name_value;
name_value manifest_parser::
next ()
diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx
index 40c7a32..befd3c0 100644
--- a/bpkg/manifest.cxx
+++ b/bpkg/manifest.cxx
@@ -4,8 +4,87 @@
#include <bpkg/manifest>
+#include <utility> // move()
+
+#include <bpkg/manifest-parser>
+#include <bpkg/manifest-serializer>
+
using namespace std;
namespace bpkg
{
+ using parser = manifest_parser;
+ using parsing = manifest_parsing;
+ using serializer = manifest_serializer;
+ using name_value = manifest_name_value;
+
+ // manifest
+ //
+ manifest::
+ manifest (parser& p): manifest (p, p.next ()) // Delegate.
+ {
+ // Make sure this is the end.
+ //
+ name_value nv (p.next ());
+ if (!nv.empty ())
+ throw parsing (p.name (), nv.name_line, nv.name_column,
+ "single manifest expected");
+ }
+
+ manifest::
+ manifest (parser& p, const name_value& s)
+ {
+ // Make sure this is the start and we support the version.
+ //
+ if (!s.name.empty ())
+ throw parsing (p.name (), s.name_line, s.name_column,
+ "start of manifest expected");
+
+ if (s.value != "1")
+ throw parsing (p.name (), s.value_line, s.value_column,
+ "unsupported format version");
+
+ for (name_value nv (p.next ()); !nv.empty (); nv = p.next ())
+ {
+ string& n (nv.name);
+ string& v (nv.value);
+
+ if (n == "name")
+ name = move (v);
+ // ...
+ else
+ throw parsing (p.name (), nv.value_line, nv.value_column,
+ "unknown name " + n);
+ }
+
+ // Verify all non-optional values were specified.
+ //
+ }
+
+ void manifest::
+ serialize (serializer& s) const
+ {
+ s.next ("", "1"); // Start of manifest.
+ s.next ("name", name);
+ // ...
+ s.next ("", ""); // End of manifest.
+ }
+
+ // manifests
+ //
+ manifests::
+ manifests (parser& p)
+ {
+ for (name_value nv (p.next ()); !nv.empty (); nv = p.next ())
+ push_back (manifest (p, nv));
+ }
+
+ void manifests::
+ serialize (serializer& s) const
+ {
+ for (const manifest& m: *this)
+ m.serialize (s);
+
+ s.next ("", ""); // End of stream.
+ }
}