aboutsummaryrefslogtreecommitdiff
path: root/libbpkg
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2022-06-23 12:25:45 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2022-06-23 12:28:13 +0300
commit6cb0dc0ffbf6fe4b7fc41256101bd71b1e8c56be (patch)
treec728b4765a2ba290798f4fe20afa927075e4c81f /libbpkg
parent3de5120d299a5e17c9c17dfd2bfc4bb4e6340941 (diff)
Add support for comments in dependency clauses block
Diffstat (limited to 'libbpkg')
-rw-r--r--libbpkg/manifest.cxx68
-rw-r--r--libbpkg/manifest.hxx6
2 files changed, 74 insertions, 0 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx
index 4555bbc..a5aa728 100644
--- a/libbpkg/manifest.cxx
+++ b/libbpkg/manifest.cxx
@@ -1280,6 +1280,11 @@ namespace bpkg
string (bool diag = true) const;
};
+ // If true, then comments are allowed and are treated as whitespace
+ // characters.
+ //
+ bool comments = false;
+
public:
// Note that name is stored by shallow reference.
//
@@ -1549,6 +1554,60 @@ namespace bpkg
case ' ':
case '\t': break;
+ case '#':
+ {
+ if (!comments)
+ return;
+
+ get (c);
+
+ // See if this is a multi-line comment in the form:
+ //
+ /*
+ #\
+ ...
+ #\
+ */
+ auto ml = [&c, this] () -> bool
+ {
+ if ((c = peek ()) == '\\')
+ {
+ get (c);
+ if ((c = peek ()) == '\n' || eos (c))
+ return true;
+ }
+
+ return false;
+ };
+
+ if (ml ())
+ {
+ // Scan until we see the closing one.
+ //
+ for (;;)
+ {
+ if (c == '#' && ml ())
+ break;
+
+ if (eos (c = peek ()))
+ throw parsing (name_,
+ c.line, c.column,
+ "unterminated multi-line comment");
+
+ get (c);
+ }
+ }
+ else
+ {
+ // Read until newline or eos.
+ //
+ for (; !eos (c) && c != '\n'; c = peek ())
+ get (c);
+ }
+
+ continue;
+ }
+
case '\n':
{
// Skip empty lines.
@@ -2112,6 +2171,10 @@ namespace bpkg
t.column,
"multi-line " + what + " form with inline reflect clause");
+ // Allow comments.
+ //
+ lexer_->comments = true;
+
next (t, tt);
expect_token (type::newline);
@@ -2260,6 +2323,11 @@ namespace bpkg
}
expect_token (type::rcbrace);
+
+ // Disallow comments.
+ //
+ lexer_->comments = false;
+
next (t, tt);
}
}
diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx
index a3415cc..2faf104 100644
--- a/libbpkg/manifest.hxx
+++ b/libbpkg/manifest.hxx
@@ -516,6 +516,12 @@ namespace bpkg
// <reflect-config> - buildfile fragment containing dependent package
// configuration variables assignments
//
+ // In the multi-line form the block may contain comments besides the
+ // clauses. The '#' character starts a single-line comment which spans
+ // until the end of the line. Unless it is followed with '\' followed by
+ // the newline in which case this is a multi-line comment which spans
+ // until the closing '#\' is encountered.
+ //
// The dependency alternative is only considered by bpkg if the enable
// condition evaluates to true. If the enable clause is not specified, then
// it is always considered.