#include <dhcp6/parser_context.h>
#include <asiolink/io_address.h>
#include <boost/lexical_cast.hpp>
+#include <exceptions/exceptions.h>
// Work around an incompatibility in flex (at least versions
// 2.5.31 through 2.5.33): it generates code that does
useful in more complex cases. */
%option yylineno
+%x COMMENT
+
/* These are not token expressions yet, just convenience expressions that
can be used during actual token definitions. Note some can match
incorrect inputs (e.g., IP addresses) which must be checked. */
%{
// Code run each time yylex is called.
loc.step();
+
+ int comment_start_line = 0;
%}
+#.* ;
+
+"//"(.*) ;
+
+"/*" {
+ BEGIN(COMMENT);
+ comment_start_line = yylineno;
+}
+
+<COMMENT>"*/" BEGIN(INITIAL);
+<COMMENT>.|"\n" ;
+<COMMENT><<EOF>> {
+ isc_throw(isc::BadValue, "Comment not closed. (/* in line " << comment_start_line);
+}
+
{blank}+ {
// Ok, we found a with space. Let's ignore it and update loc variable.
loc.step();
namespace {
void compareJSON(ConstElementPtr a, ConstElementPtr b) {
+ ASSERT_TRUE(a);
+ ASSERT_TRUE(b);
std::cout << a->str() << std::endl;
std::cout << b->str() << std::endl;
EXPECT_EQ(a->str(), b->str());
compareJSON(reference_json, test_json);
}
+void testParser2(const std::string& txt) {
+ ConstElementPtr test_json;
+
+ EXPECT_NO_THROW({
+ Parser6Context ctx;
+ test_json = ctx.parseString(txt);
+ });
+ /// @todo: Implement actual validation here. since the original
+ /// Element::fromJSON does not support several comment types, we don't
+ /// have anything to compare with.
+ std::cout << "Original text:" << txt << endl;
+ std::cout << "Parsed text :" << test_json->str() << endl;
+}
+
TEST(ParserTest, mapInMap) {
string txt = "{ \"Dhcp6\": { \"foo\": 123, \"baz\": 456 } }";
testParser(txt);
testParser(txt);
}
+TEST(ParserTest, bashComments) {
+ string txt= "{ \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},\n"
+ "\"preferred-lifetime\": 3000,\n"
+ "# this is a comment\n"
+ "\"rebind-timer\": 2000, \n"
+ "# lots of comments here\n"
+ "# and here\n"
+ "\"renew-timer\": 1000, \n"
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface-id\": \"\","
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"valid-lifetime\": 4000 }";
+ testParser(txt);
+}
+
+TEST(ParserTest, cComments) {
+ string txt= "{ \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},\n"
+ "\"preferred-lifetime\": 3000, // this is a comment \n"
+ "\"rebind-timer\": 2000, // everything after // is ignored\n"
+ "\"renew-timer\": 1000, // this will be ignored, too\n"
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface-id\": \"\","
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"valid-lifetime\": 4000 }";
+ testParser2(txt);
+}
+
+TEST(ParserTest, bashComments2) {
+ string txt= "{ \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},\n"
+ "\"preferred-lifetime\": 3000, # this is a comment \n"
+ "\"rebind-timer\": 2000, # everything after # is ignored\n"
+ "\"renew-timer\": 1000, # this will be ignored, too\n"
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface-id\": \"\","
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"valid-lifetime\": 4000 }";
+ testParser2(txt);
+}
+
+TEST(ParserTest, multilineComments) {
+ string txt= "{ \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},\n"
+ "\"preferred-lifetime\": 3000, /* this is a C style comment\n"
+ "that\n can \n span \n multiple \n lines */ \n"
+ "\"rebind-timer\": 2000,\n"
+ "\"renew-timer\": 1000, \n"
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface-id\": \"\","
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"valid-lifetime\": 4000 }";
+ testParser2(txt);
+}
+
};