Commit 69f7cfdc authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[4204] Specification of option name doesn't require quotes.

parent 749b1261
......@@ -178,7 +178,7 @@ TEST_F(ExpressionParserTest, validExpression4) {
// Verifies that the option name can be used in the evaluated expression.
TEST_F(ExpressionParserTest, validExpressionWithOptionName4) {
testValidExpression<Pkt4>(Option::V4,
"\"option['host-name'].text == 'hundred4'\"",
"\"option[host-name].text == 'hundred4'\"",
"hundred4");
}
......@@ -194,7 +194,7 @@ TEST_F(ExpressionParserTest, validExpressionWithHex4) {
// the evaluated expression.
TEST_F(ExpressionParserTest, validExpressionWithOptionNameAndHex4) {
testValidExpression<Pkt6>(Option::V4,
"\"option['host-name'].text == 0x68756E6472656434\"",
"\"option[host-name].text == 0x68756E6472656434\"",
"hundred4");
}
......@@ -208,7 +208,7 @@ TEST_F(ExpressionParserTest, validExpression6) {
// Verifies that the option name can be used in the evaluated expression.
TEST_F(ExpressionParserTest, validExpressionWithOptionName6) {
testValidExpression<Pkt6>(Option::V6,
"\"option['bootfile-url'].text == 'hundred6'\"",
"\"option[bootfile-url].text == 'hundred6'\"",
"hundred6");
}
......@@ -224,7 +224,7 @@ TEST_F(ExpressionParserTest, validExpressionWithHex6) {
// the evaluated expression.
TEST_F(ExpressionParserTest, validExpressionWithOptionNameAndHex6) {
testValidExpression<Pkt6>(Option::V6,
"\"option['bootfile-url'].text == 0x68756E6472656436\"",
"\"option[bootfile-url].text == 0x68756E6472656436\"",
"hundred6");
}
......
......@@ -133,6 +133,13 @@ blank [ \t]
"]" return isc::eval::EvalParser::make_RBRACKET(loc);
"," return isc::eval::EvalParser::make_COMA(loc);
[A-Za-z][A-Za-z0-9_\-]+/] {
// This string specifies option name starting with a letter
// and further containing letters, digits, hyphens and
// underscores.
return isc::eval::EvalParser::make_OPTION_NAME(yytext, loc);
}
. driver.error (loc, "Invalid character: " + std::string(yytext));
<<EOF>> return isc::eval::EvalParser::make_END(loc);
%%
......
......@@ -64,6 +64,7 @@ using namespace isc::eval;
%token <std::string> STRING "constant string"
%token <std::string> INTEGER "integer"
%token <std::string> HEXSTRING "constant hexstring"
%token <std::string> OPTION_NAME "option name"
%token <std::string> TOKEN
%printer { yyoutput << $$; } <*>;
......@@ -135,7 +136,7 @@ string_expr : STRING
TokenPtr opt(new TokenOption(numeric_code, TokenOption::HEXADECIMAL));
ctx.expression.push_back(opt);
}
| OPTION "[" STRING "]" DOT TEXT
| OPTION "[" OPTION_NAME "]" DOT TEXT
{
try {
// This may result in exception if the specified
......@@ -148,7 +149,7 @@ string_expr : STRING
ctx.error(@3, ex.what());
}
}
| OPTION "[" STRING "]" DOT HEX
| OPTION "[" OPTION_NAME "]" DOT HEX
{
try {
// This may result in exception if the specified
......
......@@ -210,7 +210,7 @@ TEST_F(EvalContextTest, optionWithName) {
EvalContext eval(Option::V4);
// Option 'host-name' is a standard DHCPv4 option defined in the libdhcp++.
EXPECT_NO_THROW(parsed_ = eval.parseString("option['host-name'].text == 'foo'"));
EXPECT_NO_THROW(parsed_ = eval.parseString("option[host-name].text == 'foo'"));
EXPECT_TRUE(parsed_);
ASSERT_EQ(3, eval.expression.size());
checkTokenOption(eval.expression.at(0), 12);
......@@ -300,12 +300,12 @@ TEST_F(EvalContextTest, parseErrors) {
checkError("option(10) == 'ab'",
"<string>:1.7: syntax error, "
"unexpected (, expecting [");
checkError("option['ab'].text == 'foo'",
"<string>:1.8-11: option 'ab' is not defined");
checkError("option[ab].text == 'foo'",
"<string>:1.8-9: option 'ab' is not defined");
checkError("option[0xa].text == 'ab'",
"<string>:1.8-10: syntax error, "
"unexpected constant hexstring, "
"expecting constant string or integer");
"expecting integer or option name");
checkError("substring('foobar') == 'f'",
"<string>:1.19: syntax error, "
"unexpected ), expecting \",\"");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment