aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-19 13:59:43 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-19 13:59:43 +0000
commitbde811c776eee1b37d9bcaee8aa9074df8c34ebd (patch)
tree519fa1279f85b3d6e6a43e669cb028e43731a978
parentc29150b36547140e3e7121fec994f781b9d6e46f (diff)
downloadpaludis-bde811c776eee1b37d9bcaee8aa9074df8c34ebd.tar.gz
paludis-bde811c776eee1b37d9bcaee8aa9074df8c34ebd.tar.xz
Support comments
-rw-r--r--paludis/elike_dep_parser.cc22
-rw-r--r--paludis/elike_dep_parser_TEST.cc29
2 files changed, 44 insertions, 7 deletions
diff --git a/paludis/elike_dep_parser.cc b/paludis/elike_dep_parser.cc
index f99b6ba..7418ce6 100644
--- a/paludis/elike_dep_parser.cc
+++ b/paludis/elike_dep_parser.cc
@@ -23,6 +23,7 @@
#include <paludis/util/stringify.hh>
#include <paludis/util/map.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/options.hh>
#include <paludis/name.hh>
using namespace paludis;
@@ -132,7 +133,9 @@ namespace
}
void
- parse(SimpleParser & parser, const ELikeDepParserCallbacks & callbacks, const bool end_with_close_paren,
+ parse(SimpleParser & parser, const ELikeDepParserCallbacks & callbacks,
+ const ELikeDepParserOptions & options,
+ const bool end_with_close_paren,
const bool child_of_any)
{
while (true)
@@ -153,7 +156,12 @@ namespace
error(parser, callbacks, "Expected space after '('");
callbacks.on_all()();
- parse(parser, callbacks, true, false);
+ parse(parser, callbacks, options, true, false);
+ }
+ else if (options[edpo_allow_embedded_comments] && parser.consume(
+ simple_parser::exact("#") & *simple_parser::any_except("\n")))
+ {
+ /* discard comment */
}
else if (parser.consume(+simple_parser::any_of(" \t\r\n")))
{
@@ -189,7 +197,7 @@ namespace
error(parser, callbacks, "Expected space after '|| ('");
callbacks.on_any()();
- parse(parser, callbacks, true, true);
+ parse(parser, callbacks, options, true, true);
}
else if (parser.consume(simple_parser::exact("^^")))
{
@@ -203,7 +211,7 @@ namespace
error(parser, callbacks, "Expected space after '^^ ('");
callbacks.on_exactly_one()();
- parse(parser, callbacks, true, true);
+ parse(parser, callbacks, options, true, true);
}
else if (parser.consume(+simple_parser::any_except(" \t\r\n") >> word))
{
@@ -222,7 +230,7 @@ namespace
callbacks.on_use_under_any()();
callbacks.on_use()(word);
- parse(parser, callbacks, true, false);
+ parse(parser, callbacks, options, true, false);
}
else if (':' == word.at(word.length() - 1))
{
@@ -257,12 +265,12 @@ namespace
}
void
-paludis::parse_elike_dependencies(const std::string & s, const ELikeDepParserCallbacks & callbacks, const ELikeDepParserOptions &)
+paludis::parse_elike_dependencies(const std::string & s, const ELikeDepParserCallbacks & callbacks, const ELikeDepParserOptions & options)
{
Context context("When parsing '" + s + "':");
SimpleParser parser(s);
- parse(parser, callbacks, false, false);
+ parse(parser, callbacks, options, false, false);
callbacks.on_should_be_empty()();
}
diff --git a/paludis/elike_dep_parser_TEST.cc b/paludis/elike_dep_parser_TEST.cc
index e1158ad..e517a73 100644
--- a/paludis/elike_dep_parser_TEST.cc
+++ b/paludis/elike_dep_parser_TEST.cc
@@ -142,5 +142,34 @@ namespace test_cases
TEST_CHECK_EQUAL(out, "s<a>[first:foo;second:bar baz;]EMPTY");
}
} elike_dep_parser_annotations_test;
+
+ struct ELikeDepParserCommentsTest : TestCase
+ {
+ ELikeDepParserCommentsTest() : TestCase("comments") { }
+
+ void run()
+ {
+ using namespace std::placeholders;
+
+ std::string in("# comment\na [[ first = foo second = [ bar baz ] ]] # comment"), out;
+ ELikeDepParserCallbacks callbacks(make_named_values<ELikeDepParserCallbacks>(
+ n::on_all() = std::bind(&handler, std::ref(out), "all<", "", "", "", ""),
+ n::on_annotations() = std::bind(&handle_annotations, std::ref(out), _1),
+ n::on_any() = std::bind(&handler, std::ref(out), "any<", "", "", "", ""),
+ n::on_arrow() = std::bind(&handler, std::ref(out), "a<", _1, ", ", _2, ">"),
+ n::on_error() = std::bind(&handler, std::ref(out), "error<", _1, ">", "", ""),
+ n::on_exactly_one() = std::bind(&handler, std::ref(out), "x<", "", "", "", ""),
+ n::on_label() = std::bind(&handler, std::ref(out), "label<", _1, "", "", ""),
+ n::on_no_annotations() = &do_nothing,
+ n::on_pop() = std::bind(&handler, std::ref(out), ">", "", "", "", ""),
+ n::on_should_be_empty() = std::bind(&handler, std::ref(out), "EMPTY", "", "", "", ""),
+ n::on_string() = std::bind(&handler, std::ref(out), "s<", _1, ">", "", ""),
+ n::on_use() = std::bind(&handler, std::ref(out), "use<", _1, ", ", "", ""),
+ n::on_use_under_any() = &do_nothing
+ ));
+ parse_elike_dependencies(in, callbacks, { edpo_allow_embedded_comments });
+ TEST_CHECK_EQUAL(out, "s<a>[first:foo;second:bar baz;]EMPTY");
+ }
+ } elike_dep_parser_comments_test;
}