aboutsummaryrefslogtreecommitdiff
path: root/mod/types-parsers.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'mod/types-parsers.cxx')
-rw-r--r--mod/types-parsers.cxx114
1 files changed, 114 insertions, 0 deletions
diff --git a/mod/types-parsers.cxx b/mod/types-parsers.cxx
new file mode 100644
index 0000000..279ab58
--- /dev/null
+++ b/mod/types-parsers.cxx
@@ -0,0 +1,114 @@
+// file : mod/types-parsers.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <mod/types-parsers>
+
+#include <mod/options>
+
+using namespace std;
+using namespace web::xhtml;
+
+namespace brep
+{
+ namespace cli
+ {
+ // Parse path.
+ //
+ template <typename T>
+ static void
+ parse_path (T& x, scanner& s)
+ {
+ const char* o (s.next ());
+
+ if (!s.more ())
+ throw missing_value (o);
+
+ const char* v (s.next ());
+
+ try
+ {
+ x = T (v);
+ }
+ catch (const invalid_path&)
+ {
+ throw invalid_value (o, v);
+ }
+ }
+
+ void parser<dir_path>::
+ parse (dir_path& x, scanner& s)
+ {
+ parse_path (x, s);
+ }
+
+ // Parse page_form.
+ //
+ void parser<page_form>::
+ parse (page_form& x, scanner& s)
+ {
+ const char* o (s.next ());
+
+ if (!s.more ())
+ throw missing_value (o);
+
+ const string v (s.next ());
+ if (v == "full")
+ x = page_form::full;
+ else if (v == "brief")
+ x = page_form::brief;
+ else
+ throw invalid_value (o, v);
+ }
+
+ // Parse page_menu.
+ //
+ void parser<page_menu>::
+ parse (page_menu& x, scanner& s)
+ {
+ const char* o (s.next ());
+
+ if (!s.more ())
+ throw missing_value (o);
+
+ const string v (s.next ());
+
+ auto p (v.find ('='));
+ if (p != string::npos)
+ {
+ string label (v, 0, p);
+ string link (v, p + 1);
+
+ if (!label.empty ())
+ {
+ x = page_menu (move (label), move (link));
+ return;
+ }
+ }
+
+ throw invalid_value (o, v);
+ }
+
+ // Parse web::xhtml::fragment.
+ //
+ void parser<fragment>::
+ parse (fragment& x, scanner& s)
+ {
+ const char* o (s.next ());
+
+ if (!s.more ())
+ throw missing_value (o);
+
+ const char* v (s.next ());
+
+ try
+ {
+ x = fragment (v, o);
+ }
+ catch (const xml::parsing&)
+ {
+ throw invalid_value (o, v);
+ }
+ }
+ }
+}