Parcourir la source

[4231] Added .exists to option

Francis Dupont il y a 9 ans
Parent
commit
8f6bc1575e

+ 103 - 93
src/lib/eval/lexer.cc

@@ -469,8 +469,8 @@ static void yy_fatal_error (yyconst char msg[]  );
 	(yy_c_buf_p) = yy_cp;
 
 /* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
-#define YY_NUM_RULES 21
-#define YY_END_OF_BUFFER 22
+#define YY_NUM_RULES 22
+#define YY_END_OF_BUFFER 23
 /* This struct is not used in this scanner,
    but its presence is necessary. */
 struct yy_trans_info
@@ -478,29 +478,31 @@ struct yy_trans_info
 	flex_int32_t yy_verify;
 	flex_int32_t yy_nxt;
 	};
-static yyconst flex_int16_t yy_acclist[96] =
+static yyconst flex_int16_t yy_acclist[105] =
     {   0,
-       22,   20,   21,    1,   20,   21,    2,   21,   20,   21,
-       15,   20,   21,   16,   20,   21,   19,   20,   21,   20,
-       21,   14,   20,   21,    5,   20,   21,    5,   20,   21,
-       20,   21,   20,   21,16390,   17,   20,   21,   18,   20,
-       21,   20,   21,16390,   20,   21,16390,   20,   21,16390,
-       20,   21,16390,   20,   21,16390,   20,   21,16390,    1,
-        2,    3,    5,    7,16390, 8198,16390,16390,16390,16390,
-    16390,16390,    4,   13,16390,   10,16390,   12,16390,16390,
-    16390,16390,16390,16390,    9,16390,16390,16390,    8,16390,
-    16390,16390,16390,   11,16390
-
+       23,   21,   22,    1,   21,   22,    2,   22,   21,   22,
+       16,   21,   22,   17,   21,   22,   20,   21,   22,   21,
+       22,   15,   21,   22,    5,   21,   22,    5,   21,   22,
+       21,   22,   21,   22,16390,   18,   21,   22,   19,   21,
+       22,   21,   22,16390,   21,   22,16390,   21,   22,16390,
+       21,   22,16390,   21,   22,16390,   21,   22,16390,   21,
+       22,16390,    1,    2,    3,    5,    7,16390, 8198,16390,
+    16390,16390,16390,16390,16390,16390,    4,   13,16390,16390,
+       10,16390,   14,16390,16390,16390,16390,16390,16390,16390,
+        9,16390,16390,16390,16390,   11,16390,    8,16390,16390,
+
+    16390,16390,   12,16390
     } ;
 
-static yyconst flex_int16_t yy_accept[61] =
+static yyconst flex_int16_t yy_accept[67] =
     {   0,
         1,    1,    1,    2,    4,    7,    9,   11,   14,   17,
        20,   22,   25,   28,   31,   33,   36,   39,   42,   45,
-       48,   51,   54,   57,   60,   61,   62,   62,   63,   64,
-       64,   65,   65,   65,   66,   67,   68,   69,   70,   71,
-       72,   73,   74,   76,   78,   80,   81,   82,   83,   84,
-       85,   87,   88,   89,   91,   92,   93,   94,   96,   96
+       48,   51,   54,   57,   60,   63,   64,   65,   65,   66,
+       67,   67,   68,   68,   68,   69,   70,   71,   72,   73,
+       74,   75,   76,   77,   78,   80,   81,   83,   85,   86,
+       87,   88,   89,   90,   91,   93,   94,   95,   96,   98,
+      100,  101,  102,  103,  105,  105
     } ;
 
 static yyconst flex_int32_t yy_ec[256] =
@@ -543,83 +545,86 @@ static yyconst flex_int32_t yy_meta[34] =
         2,    2,    2
     } ;
 
-static yyconst flex_int16_t yy_base[63] =
+static yyconst flex_int16_t yy_base[69] =
     {   0,
-        0,    0,  124,  125,  121,  119,  117,  125,  125,  125,
-       24,  125,   26,   28,  108,   58,  125,  125,   75,   19,
-       18,   21,   22,   27,  117,  115,  113,  125,   40,    0,
-      125,   53,   55,   91,  125,   86,   38,   37,   42,   44,
-       49,    0,   82,   81,   74,   60,   56,   63,   62,   65,
-       54,   72,   66,   40,   77,   78,   83,   28,  125,  108,
-      111,   38
+        0,    0,  135,  136,  132,  130,  128,  136,  136,  136,
+       24,  136,   26,   28,  119,   58,  136,  136,   75,   15,
+       21,   18,   19,   24,   29,  128,  126,  124,  136,   41,
+        0,  136,   55,   62,  102,  136,  101,   38,   48,   43,
+       55,   64,   57,    0,  100,   66,   99,   98,   45,   69,
+       70,   72,   28,   73,   97,   77,   80,   42,   96,   95,
+       84,   85,   63,   94,  136,  111,  114,  110
     } ;
 
-static yyconst flex_int16_t yy_def[63] =
+static yyconst flex_int16_t yy_def[69] =
     {   0,
-       59,    1,   59,   59,   59,   59,   60,   59,   59,   59,
-       59,   59,   59,   59,   59,   61,   59,   59,   61,   19,
-       19,   19,   19,   19,   59,   59,   60,   59,   59,   62,
-       59,   59,   19,   19,   59,   19,   19,   19,   19,   19,
-       19,   62,   19,   19,   19,   19,   19,   19,   19,   19,
-       19,   19,   19,   19,   19,   19,   19,   19,    0,   59,
-       59,   59
+       65,    1,   65,   65,   65,   65,   66,   65,   65,   65,
+       65,   65,   65,   65,   65,   67,   65,   65,   67,   19,
+       19,   19,   19,   19,   19,   65,   65,   66,   65,   65,
+       68,   65,   65,   19,   19,   65,   19,   19,   19,   19,
+       19,   19,   19,   68,   19,   19,   19,   19,   19,   19,
+       19,   19,   19,   19,   19,   19,   19,   19,   19,   19,
+       19,   19,   19,   19,    0,   65,   65,   65
     } ;
 
-static yyconst flex_int16_t yy_nxt[159] =
+static yyconst flex_int16_t yy_nxt[170] =
     {   0,
         4,    5,    6,    7,    8,    9,   10,   11,   12,   13,
        14,   15,   16,   16,   16,   17,   18,    4,   19,   16,
-       16,   16,   20,   16,   16,   21,   22,   16,   16,   23,
-       24,   16,   16,   29,   29,   29,   29,   29,   29,   37,
-       30,   42,   34,   34,   38,   34,   34,   41,   39,   29,
-       29,   34,   34,   40,   32,   32,   59,   59,   30,   32,
-       32,   34,   34,   47,   34,   33,   34,   45,   34,   35,
-       44,   59,   46,   34,   35,   33,   32,   32,   34,   34,
-       34,   48,   33,   49,   34,   50,   34,   34,   52,   34,
-       34,   35,   33,   51,   55,   53,   34,   54,   34,   36,
-
-       56,   34,   34,   57,   58,   34,   34,   34,   27,   27,
-       43,   27,   34,   34,   34,   34,   28,   26,   25,   31,
-       28,   26,   25,   59,    3,   59,   59,   59,   59,   59,
-       59,   59,   59,   59,   59,   59,   59,   59,   59,   59,
-       59,   59,   59,   59,   59,   59,   59,   59,   59,   59,
-       59,   59,   59,   59,   59,   59,   59,   59
+       20,   16,   21,   16,   16,   22,   23,   16,   16,   24,
+       25,   16,   16,   30,   30,   30,   30,   30,   30,   35,
+       31,   39,   35,   35,   40,   35,   41,   38,   35,   43,
+       30,   30,   35,   35,   57,   42,   33,   33,   31,   33,
+       33,   46,   35,   65,   65,   34,   35,   35,   53,   35,
+       61,   36,   35,   48,   36,   34,   33,   33,   65,   35,
+       47,   35,   34,   50,   64,   49,   35,   35,   35,   51,
+       35,   36,   34,   35,   35,   52,   35,   35,   54,   37,
+
+       55,   35,   56,   58,   35,   60,   59,   62,   35,   35,
+       63,   28,   28,   44,   28,   35,   35,   35,   35,   35,
+       35,   35,   35,   35,   35,   45,   35,   29,   27,   26,
+       32,   29,   27,   26,   65,    3,   65,   65,   65,   65,
+       65,   65,   65,   65,   65,   65,   65,   65,   65,   65,
+       65,   65,   65,   65,   65,   65,   65,   65,   65,   65,
+       65,   65,   65,   65,   65,   65,   65,   65,   65
     } ;
 
-static yyconst flex_int16_t yy_chk[159] =
+static yyconst flex_int16_t yy_chk[170] =
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,   11,   11,   13,   13,   14,   14,   20,
-       13,   62,   21,   20,   21,   22,   23,   24,   22,   29,
-       29,   24,   58,   23,   32,   32,   33,   33,   13,   16,
-       16,   38,   37,   40,   54,   16,   39,   38,   40,   32,
-       37,   33,   39,   41,   16,   16,   19,   19,   51,   33,
-       47,   41,   19,   46,   46,   47,   49,   48,   49,   50,
-       53,   19,   19,   48,   53,   50,   52,   52,   45,   19,
-
-       55,   55,   56,   56,   57,   44,   43,   57,   60,   60,
-       36,   60,   61,   61,   61,   34,   27,   26,   25,   15,
-        7,    6,    5,    3,   59,   59,   59,   59,   59,   59,
-       59,   59,   59,   59,   59,   59,   59,   59,   59,   59,
-       59,   59,   59,   59,   59,   59,   59,   59,   59,   59,
-       59,   59,   59,   59,   59,   59,   59,   59
+       13,   21,   22,   23,   22,   21,   23,   20,   24,   25,
+       30,   30,   53,   25,   53,   24,   33,   33,   13,   16,
+       16,   38,   38,   34,   34,   16,   58,   40,   49,   49,
+       58,   33,   39,   40,   16,   16,   19,   19,   34,   41,
+       39,   43,   19,   42,   63,   41,   34,   63,   42,   43,
+       46,   19,   19,   50,   51,   46,   52,   54,   50,   19,
+
+       51,   56,   52,   54,   57,   57,   56,   61,   61,   62,
+       62,   66,   66,   68,   66,   67,   67,   67,   64,   60,
+       59,   55,   48,   47,   45,   37,   35,   28,   27,   26,
+       15,    7,    6,    5,    3,   65,   65,   65,   65,   65,
+       65,   65,   65,   65,   65,   65,   65,   65,   65,   65,
+       65,   65,   65,   65,   65,   65,   65,   65,   65,   65,
+       65,   65,   65,   65,   65,   65,   65,   65,   65
     } ;
 
 /* Table of booleans, true if rule could match eol. */
-static yyconst flex_int32_t yy_rule_can_match_eol[22] =
+static yyconst flex_int32_t yy_rule_can_match_eol[23] =
     {   0,
 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-    0, 0,     };
+    0, 0, 0,     };
 
 extern int yy_flex_debug;
 int yy_flex_debug = 1;
 
-static yyconst flex_int16_t yy_rule_linenum[21] =
+static yyconst flex_int16_t yy_rule_linenum[22] =
     {   0,
        86,   90,   96,  106,  112,  126,  133,  134,  135,  136,
-      137,  138,  139,  140,  141,  142,  143,  144,  145,  147
+      137,  138,  139,  140,  141,  142,  143,  144,  145,  146,
+      148
     } ;
 
 static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;
@@ -704,7 +709,7 @@ static isc::eval::location loc;
 // by moving it ahead by yyleng bytes. yyleng specifies the length of the
 // currently matched token.
 #define YY_USER_ACTION  loc.columns(yyleng);
-#line 708 "lexer.cc"
+#line 713 "lexer.cc"
 
 #define INITIAL 0
 
@@ -993,7 +998,7 @@ YY_DECL
     loc.step();
 
 
-#line 997 "lexer.cc"
+#line 1002 "lexer.cc"
 
 	while ( 1 )		/* loops until end-of-file is reached */
 		{
@@ -1021,14 +1026,14 @@ yy_match:
 			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 				{
 				yy_current_state = (int) yy_def[yy_current_state];
-				if ( yy_current_state >= 60 )
+				if ( yy_current_state >= 66 )
 					yy_c = yy_meta[(unsigned int) yy_c];
 				}
 			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
 			*(yy_state_ptr)++ = yy_current_state;
 			++yy_cp;
 			}
-		while ( yy_current_state != 59 );
+		while ( yy_current_state != 65 );
 
 yy_find_action:
 /* %% [10.0] code to find the action number goes here */
@@ -1091,13 +1096,13 @@ do_action:	/* This label is used only to access EOF actions. */
 			{
 			if ( yy_act == 0 )
 				fprintf( stderr, "--scanner backing up\n" );
-			else if ( yy_act < 21 )
+			else if ( yy_act < 22 )
 				fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
 				         (long)yy_rule_linenum[yy_act], yytext );
-			else if ( yy_act == 21 )
+			else if ( yy_act == 22 )
 				fprintf( stderr, "--accepting default rule (\"%s\")\n",
 				         yytext );
-			else if ( yy_act == 22 )
+			else if ( yy_act == 23 )
 				fprintf( stderr, "--(end of buffer or a NUL)\n" );
 			else
 				fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
@@ -1197,12 +1202,12 @@ return isc::eval::EvalParser::make_HEX(loc);
 case 11:
 YY_RULE_SETUP
 #line 137 "lexer.ll"
-return isc::eval::EvalParser::make_SUBSTRING(loc);
+return isc::eval::EvalParser::make_EXISTS(loc);
 	YY_BREAK
 case 12:
 YY_RULE_SETUP
 #line 138 "lexer.ll"
-return isc::eval::EvalParser::make_NOT(loc);
+return isc::eval::EvalParser::make_SUBSTRING(loc);
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
@@ -1212,48 +1217,53 @@ return isc::eval::EvalParser::make_ALL(loc);
 case 14:
 YY_RULE_SETUP
 #line 140 "lexer.ll"
-return isc::eval::EvalParser::make_DOT(loc);
+return isc::eval::EvalParser::make_NOT(loc);
 	YY_BREAK
 case 15:
 YY_RULE_SETUP
 #line 141 "lexer.ll"
-return isc::eval::EvalParser::make_LPAREN(loc);
+return isc::eval::EvalParser::make_DOT(loc);
 	YY_BREAK
 case 16:
 YY_RULE_SETUP
 #line 142 "lexer.ll"
-return isc::eval::EvalParser::make_RPAREN(loc);
+return isc::eval::EvalParser::make_LPAREN(loc);
 	YY_BREAK
 case 17:
 YY_RULE_SETUP
 #line 143 "lexer.ll"
-return isc::eval::EvalParser::make_LBRACKET(loc);
+return isc::eval::EvalParser::make_RPAREN(loc);
 	YY_BREAK
 case 18:
 YY_RULE_SETUP
 #line 144 "lexer.ll"
-return isc::eval::EvalParser::make_RBRACKET(loc);
+return isc::eval::EvalParser::make_LBRACKET(loc);
 	YY_BREAK
 case 19:
 YY_RULE_SETUP
 #line 145 "lexer.ll"
-return isc::eval::EvalParser::make_COMA(loc);
+return isc::eval::EvalParser::make_RBRACKET(loc);
 	YY_BREAK
 case 20:
 YY_RULE_SETUP
-#line 147 "lexer.ll"
+#line 146 "lexer.ll"
+return isc::eval::EvalParser::make_COMA(loc);
+	YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 148 "lexer.ll"
 driver.error (loc, "Invalid character: " + std::string(yytext));
 	YY_BREAK
 case YY_STATE_EOF(INITIAL):
-#line 148 "lexer.ll"
+#line 149 "lexer.ll"
 return isc::eval::EvalParser::make_END(loc);
 	YY_BREAK
-case 21:
+case 22:
 YY_RULE_SETUP
-#line 149 "lexer.ll"
+#line 150 "lexer.ll"
 ECHO;
 	YY_BREAK
-#line 1257 "lexer.cc"
+#line 1267 "lexer.cc"
 
 	case YY_END_OF_BUFFER:
 		{
@@ -1534,7 +1544,7 @@ static int yy_get_next_buffer (void)
 		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 			{
 			yy_current_state = (int) yy_def[yy_current_state];
-			if ( yy_current_state >= 60 )
+			if ( yy_current_state >= 66 )
 				yy_c = yy_meta[(unsigned int) yy_c];
 			}
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1562,11 +1572,11 @@ static int yy_get_next_buffer (void)
 	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 		{
 		yy_current_state = (int) yy_def[yy_current_state];
-		if ( yy_current_state >= 60 )
+		if ( yy_current_state >= 66 )
 			yy_c = yy_meta[(unsigned int) yy_c];
 		}
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-	yy_is_jam = (yy_current_state == 59);
+	yy_is_jam = (yy_current_state == 65);
 	if ( ! yy_is_jam )
 		*(yy_state_ptr)++ = yy_current_state;
 
@@ -2314,7 +2324,7 @@ void yyfree (void * ptr )
 
 /* %ok-for-header */
 
-#line 149 "lexer.ll"
+#line 150 "lexer.ll"
 
 
 

+ 2 - 1
src/lib/eval/lexer.ll

@@ -134,9 +134,10 @@ blank [ \t]
 "option"    return isc::eval::EvalParser::make_OPTION(loc);
 "text"      return isc::eval::EvalParser::make_TEXT(loc);
 "hex"       return isc::eval::EvalParser::make_HEX(loc);
+"exists"    return isc::eval::EvalParser::make_EXISTS(loc);
 "substring" return isc::eval::EvalParser::make_SUBSTRING(loc);
-"not"       return isc::eval::EvalParser::make_NOT(loc);
 "all"       return isc::eval::EvalParser::make_ALL(loc);
+"not"       return isc::eval::EvalParser::make_NOT(loc);
 "."         return isc::eval::EvalParser::make_DOT(loc);
 "("         return isc::eval::EvalParser::make_LPAREN(loc);
 ")"         return isc::eval::EvalParser::make_RPAREN(loc);

+ 121 - 106
src/lib/eval/parser.cc

@@ -251,19 +251,19 @@ namespace isc { namespace eval {
   {
       switch (that.type_get ())
     {
-      case 26: // option_repr_type
+      case 27: // option_repr_type
         value.move< TokenOption::RepresentationType > (that.value);
         break;
 
-      case 16: // "constant string"
-      case 17: // "integer"
-      case 18: // "constant hexstring"
-      case 19: // "option name"
-      case 20: // TOKEN
+      case 17: // "constant string"
+      case 18: // "integer"
+      case 19: // "constant hexstring"
+      case 20: // "option name"
+      case 21: // TOKEN
         value.move< std::string > (that.value);
         break;
 
-      case 25: // option_code
+      case 26: // option_code
         value.move< uint16_t > (that.value);
         break;
 
@@ -282,19 +282,19 @@ namespace isc { namespace eval {
     state = that.state;
       switch (that.type_get ())
     {
-      case 26: // option_repr_type
+      case 27: // option_repr_type
         value.copy< TokenOption::RepresentationType > (that.value);
         break;
 
-      case 16: // "constant string"
-      case 17: // "integer"
-      case 18: // "constant hexstring"
-      case 19: // "option name"
-      case 20: // TOKEN
+      case 17: // "constant string"
+      case 18: // "integer"
+      case 19: // "constant hexstring"
+      case 20: // "option name"
+      case 21: // TOKEN
         value.copy< std::string > (that.value);
         break;
 
-      case 25: // option_code
+      case 26: // option_code
         value.copy< uint16_t > (that.value);
         break;
 
@@ -334,51 +334,51 @@ namespace isc { namespace eval {
         << yysym.location << ": ";
     switch (yytype)
     {
-            case 16: // "constant string"
+            case 17: // "constant string"
 
-#line 71 "parser.yy" // lalr1.cc:636
+#line 72 "parser.yy" // lalr1.cc:636
         { yyoutput << yysym.value.template as< std::string > (); }
 #line 342 "parser.cc" // lalr1.cc:636
         break;
 
-      case 17: // "integer"
+      case 18: // "integer"
 
-#line 71 "parser.yy" // lalr1.cc:636
+#line 72 "parser.yy" // lalr1.cc:636
         { yyoutput << yysym.value.template as< std::string > (); }
 #line 349 "parser.cc" // lalr1.cc:636
         break;
 
-      case 18: // "constant hexstring"
+      case 19: // "constant hexstring"
 
-#line 71 "parser.yy" // lalr1.cc:636
+#line 72 "parser.yy" // lalr1.cc:636
         { yyoutput << yysym.value.template as< std::string > (); }
 #line 356 "parser.cc" // lalr1.cc:636
         break;
 
-      case 19: // "option name"
+      case 20: // "option name"
 
-#line 71 "parser.yy" // lalr1.cc:636
+#line 72 "parser.yy" // lalr1.cc:636
         { yyoutput << yysym.value.template as< std::string > (); }
 #line 363 "parser.cc" // lalr1.cc:636
         break;
 
-      case 20: // TOKEN
+      case 21: // TOKEN
 
-#line 71 "parser.yy" // lalr1.cc:636
+#line 72 "parser.yy" // lalr1.cc:636
         { yyoutput << yysym.value.template as< std::string > (); }
 #line 370 "parser.cc" // lalr1.cc:636
         break;
 
-      case 25: // option_code
+      case 26: // option_code
 
-#line 71 "parser.yy" // lalr1.cc:636
+#line 72 "parser.yy" // lalr1.cc:636
         { yyoutput << yysym.value.template as< uint16_t > (); }
 #line 377 "parser.cc" // lalr1.cc:636
         break;
 
-      case 26: // option_repr_type
+      case 27: // option_repr_type
 
-#line 71 "parser.yy" // lalr1.cc:636
+#line 72 "parser.yy" // lalr1.cc:636
         { yyoutput << yysym.value.template as< TokenOption::RepresentationType > (); }
 #line 384 "parser.cc" // lalr1.cc:636
         break;
@@ -580,19 +580,19 @@ namespace isc { namespace eval {
          when using variants.  */
         switch (yyr1_[yyn])
     {
-      case 26: // option_repr_type
+      case 27: // option_repr_type
         yylhs.value.build< TokenOption::RepresentationType > ();
         break;
 
-      case 16: // "constant string"
-      case 17: // "integer"
-      case 18: // "constant hexstring"
-      case 19: // "option name"
-      case 20: // TOKEN
+      case 17: // "constant string"
+      case 18: // "integer"
+      case 19: // "constant hexstring"
+      case 20: // "option name"
+      case 21: // TOKEN
         yylhs.value.build< std::string > ();
         break;
 
-      case 25: // option_code
+      case 26: // option_code
         yylhs.value.build< uint16_t > ();
         break;
 
@@ -614,7 +614,7 @@ namespace isc { namespace eval {
           switch (yyn)
             {
   case 4:
-#line 85 "parser.yy" // lalr1.cc:859
+#line 86 "parser.yy" // lalr1.cc:859
     {
                     TokenPtr neg(new TokenNot());
                     ctx.expression.push_back(neg);
@@ -623,7 +623,7 @@ namespace isc { namespace eval {
     break;
 
   case 5:
-#line 90 "parser.yy" // lalr1.cc:859
+#line 91 "parser.yy" // lalr1.cc:859
     {
                     TokenPtr eq(new TokenEqual());
                     ctx.expression.push_back(eq);
@@ -632,102 +632,111 @@ namespace isc { namespace eval {
     break;
 
   case 6:
-#line 97 "parser.yy" // lalr1.cc:859
+#line 96 "parser.yy" // lalr1.cc:859
+    {
+                    TokenPtr opt(new TokenOption(yystack_[3].value.as< uint16_t > (), TokenOption::EXISTS));
+                    ctx.expression.push_back(opt);
+                }
+#line 641 "parser.cc" // lalr1.cc:859
+    break;
+
+  case 7:
+#line 103 "parser.yy" // lalr1.cc:859
     {
                       TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ()));
                       ctx.expression.push_back(str);
                   }
-#line 641 "parser.cc" // lalr1.cc:859
+#line 650 "parser.cc" // lalr1.cc:859
     break;
 
-  case 7:
-#line 102 "parser.yy" // lalr1.cc:859
+  case 8:
+#line 108 "parser.yy" // lalr1.cc:859
     {
                       TokenPtr hex(new TokenHexString(yystack_[0].value.as< std::string > ()));
                       ctx.expression.push_back(hex);
                   }
-#line 650 "parser.cc" // lalr1.cc:859
+#line 659 "parser.cc" // lalr1.cc:859
     break;
 
-  case 8:
-#line 107 "parser.yy" // lalr1.cc:859
+  case 9:
+#line 113 "parser.yy" // lalr1.cc:859
     {
                       TokenPtr opt(new TokenOption(yystack_[3].value.as< uint16_t > (), yystack_[0].value.as< TokenOption::RepresentationType > ()));
                       ctx.expression.push_back(opt);
                   }
-#line 659 "parser.cc" // lalr1.cc:859
+#line 668 "parser.cc" // lalr1.cc:859
     break;
 
-  case 9:
-#line 112 "parser.yy" // lalr1.cc:859
+  case 10:
+#line 118 "parser.yy" // lalr1.cc:859
     {
                       TokenPtr sub(new TokenSubstring());
                       ctx.expression.push_back(sub);
                   }
-#line 668 "parser.cc" // lalr1.cc:859
+#line 677 "parser.cc" // lalr1.cc:859
     break;
 
-  case 11:
-#line 121 "parser.yy" // lalr1.cc:859
+  case 12:
+#line 127 "parser.yy" // lalr1.cc:859
     {
                      yylhs.value.as< uint16_t > () = ctx.convertOptionCode(yystack_[0].value.as< std::string > (), yystack_[0].location);
                  }
-#line 676 "parser.cc" // lalr1.cc:859
+#line 685 "parser.cc" // lalr1.cc:859
     break;
 
-  case 12:
-#line 125 "parser.yy" // lalr1.cc:859
+  case 13:
+#line 131 "parser.yy" // lalr1.cc:859
     {
                      yylhs.value.as< uint16_t > () = ctx.convertOptionName(yystack_[0].value.as< std::string > (), yystack_[0].location);
                  }
-#line 684 "parser.cc" // lalr1.cc:859
+#line 693 "parser.cc" // lalr1.cc:859
     break;
 
-  case 13:
-#line 131 "parser.yy" // lalr1.cc:859
+  case 14:
+#line 137 "parser.yy" // lalr1.cc:859
     {
                           yylhs.value.as< TokenOption::RepresentationType > () = TokenOption::TEXTUAL;
                       }
-#line 692 "parser.cc" // lalr1.cc:859
+#line 701 "parser.cc" // lalr1.cc:859
     break;
 
-  case 14:
-#line 135 "parser.yy" // lalr1.cc:859
+  case 15:
+#line 141 "parser.yy" // lalr1.cc:859
     {
                           yylhs.value.as< TokenOption::RepresentationType > () = TokenOption::HEXADECIMAL;
                       }
-#line 700 "parser.cc" // lalr1.cc:859
+#line 709 "parser.cc" // lalr1.cc:859
     break;
 
-  case 15:
-#line 141 "parser.yy" // lalr1.cc:859
+  case 16:
+#line 147 "parser.yy" // lalr1.cc:859
     {
                      TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ()));
                      ctx.expression.push_back(str);
                  }
-#line 709 "parser.cc" // lalr1.cc:859
+#line 718 "parser.cc" // lalr1.cc:859
     break;
 
-  case 16:
-#line 148 "parser.yy" // lalr1.cc:859
+  case 17:
+#line 154 "parser.yy" // lalr1.cc:859
     {
                       TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ()));
                       ctx.expression.push_back(str);
                   }
-#line 718 "parser.cc" // lalr1.cc:859
+#line 727 "parser.cc" // lalr1.cc:859
     break;
 
-  case 17:
-#line 153 "parser.yy" // lalr1.cc:859
+  case 18:
+#line 159 "parser.yy" // lalr1.cc:859
     {
                      TokenPtr str(new TokenString("all"));
                      ctx.expression.push_back(str);
                  }
-#line 727 "parser.cc" // lalr1.cc:859
+#line 736 "parser.cc" // lalr1.cc:859
     break;
 
 
-#line 731 "parser.cc" // lalr1.cc:859
+#line 740 "parser.cc" // lalr1.cc:859
             default:
               break;
             }
@@ -982,79 +991,84 @@ namespace isc { namespace eval {
   }
 
 
-  const signed char EvalParser::yypact_ninf_ = -10;
+  const signed char EvalParser::yypact_ninf_ = -14;
 
   const signed char EvalParser::yytable_ninf_ = -1;
 
   const signed char
   EvalParser::yypact_[] =
   {
-      -4,    -1,     3,    -4,    -4,   -10,   -10,   -10,    18,   -10,
-      17,    -8,     1,   -10,    13,   -10,     1,   -10,   -10,    12,
-      19,   -10,   -10,    22,    11,    16,   -10,    20,   -10,   -10,
-     -10,    -7,   -10,   -10,    23,   -10
+      -4,    -7,    15,    -4,    -4,   -14,   -14,   -14,    12,   -14,
+      11,   -13,    -1,   -14,    16,   -14,    -1,   -14,   -14,    13,
+      18,    19,   -14,   -14,    21,   -13,    20,    14,    24,   -14,
+      22,   -14,   -14,   -14,   -14,    25,     1,    17,   -14,   -14,
+      27,   -14
   };
 
   const unsigned char
   EvalParser::yydefact_[] =
   {
-       0,     0,     0,     0,     0,     6,     7,    10,     0,     2,
-       0,     0,     0,     4,     0,     1,     0,    11,    12,     0,
-       0,     3,     5,     0,     0,     0,    15,     0,    13,    14,
-       8,     0,    17,    16,     0,     9
+       0,     0,     0,     0,     0,     7,     8,    11,     0,     2,
+       0,     0,     0,     4,     0,     1,     0,    12,    13,     0,
+       0,     0,     3,     5,     0,     0,     0,     0,     0,    16,
+       0,    14,    15,     6,     9,     0,     0,     0,    18,    17,
+       0,    10
   };
 
   const signed char
   EvalParser::yypgoto_[] =
   {
-     -10,   -10,    21,    -9,   -10,   -10,   -10,   -10
+     -14,   -14,    23,    -6,    10,   -14,   -14,   -14
   };
 
   const signed char
   EvalParser::yydefgoto_[] =
   {
-      -1,     8,     9,    10,    19,    30,    27,    34
+      -1,     8,     9,    10,    19,    34,    30,    40
   };
 
   const unsigned char
   EvalParser::yytable_[] =
   {
-       1,     2,    32,    20,     3,     1,     2,    22,     4,    17,
-      33,    18,     5,    11,     6,    12,     7,     5,    15,     6,
-      16,     7,    28,    29,    13,    14,    21,    23,    26,     0,
-      24,    31,    25,     0,     0,     0,    35
+       1,     2,     3,    20,     2,    17,    21,    18,    11,     4,
+      23,    38,    15,     5,    16,     6,     5,     7,     6,    39,
+       7,    31,    32,    33,    31,    32,    13,    14,    12,    24,
+      22,    26,    27,    25,    36,    28,    37,     0,    29,     0,
+      35,    41
   };
 
   const signed char
   EvalParser::yycheck_[] =
   {
-       4,     5,     9,    12,     8,     4,     5,    16,    12,    17,
-      17,    19,    16,    14,    18,    12,    20,    16,     0,    18,
-       3,    20,     6,     7,     3,     4,    13,    15,    17,    -1,
-      11,    11,    10,    -1,    -1,    -1,    13
+       4,     5,     6,     4,     5,    18,    12,    20,    15,    13,
+      16,    10,     0,    17,     3,    19,    17,    21,    19,    18,
+      21,     7,     8,     9,     7,     8,     3,     4,    13,    16,
+      14,    12,    11,    15,    12,    25,    11,    -1,    18,    -1,
+      16,    14
   };
 
   const unsigned char
   EvalParser::yystos_[] =
   {
-       0,     4,     5,     8,    12,    16,    18,    20,    22,    23,
-      24,    14,    12,    23,    23,     0,     3,    17,    19,    25,
-      24,    13,    24,    15,    11,    10,    17,    27,     6,     7,
-      26,    11,     9,    17,    28,    13
+       0,     4,     5,     6,    13,    17,    19,    21,    23,    24,
+      25,    15,    13,    24,    24,     0,     3,    18,    20,    26,
+       4,    25,    14,    25,    16,    15,    12,    11,    26,    18,
+      28,     7,     8,     9,    27,    16,    12,    11,    10,    18,
+      29,    14
   };
 
   const unsigned char
   EvalParser::yyr1_[] =
   {
-       0,    21,    22,    23,    23,    23,    24,    24,    24,    24,
-      24,    25,    25,    26,    26,    27,    28,    28
+       0,    22,    23,    24,    24,    24,    24,    25,    25,    25,
+      25,    25,    26,    26,    27,    27,    28,    29,    29
   };
 
   const unsigned char
   EvalParser::yyr2_[] =
   {
-       0,     2,     1,     3,     2,     3,     1,     1,     6,     8,
-       1,     1,     1,     1,     1,     1,     1,     1
+       0,     2,     1,     3,     2,     3,     6,     1,     1,     6,
+       8,     1,     1,     1,     1,     1,     1,     1,     1
   };
 
 
@@ -1065,19 +1079,20 @@ namespace isc { namespace eval {
   const EvalParser::yytname_[] =
   {
   "\"end of file\"", "error", "$undefined", "\"==\"", "\"option\"",
-  "\"substring\"", "\"text\"", "\"hex\"", "\"not\"", "\"all\"", "\".\"",
-  "\",\"", "\"(\"", "\")\"", "\"[\"", "\"]\"", "\"constant string\"",
-  "\"integer\"", "\"constant hexstring\"", "\"option name\"", "TOKEN",
-  "$accept", "expression", "bool_expr", "string_expr", "option_code",
-  "option_repr_type", "start_expr", "length_expr", YY_NULLPTR
+  "\"substring\"", "\"not\"", "\"text\"", "\"hex\"", "\"exists\"",
+  "\"all\"", "\".\"", "\",\"", "\"(\"", "\")\"", "\"[\"", "\"]\"",
+  "\"constant string\"", "\"integer\"", "\"constant hexstring\"",
+  "\"option name\"", "TOKEN", "$accept", "expression", "bool_expr",
+  "string_expr", "option_code", "option_repr_type", "start_expr",
+  "length_expr", YY_NULLPTR
   };
 
 #if YYDEBUG
   const unsigned char
   EvalParser::yyrline_[] =
   {
-       0,    80,    80,    83,    84,    89,    96,   101,   106,   111,
-     116,   120,   124,   130,   134,   140,   147,   152
+       0,    81,    81,    84,    85,    90,    95,   102,   107,   112,
+     117,   122,   126,   130,   136,   140,   146,   153,   158
   };
 
   // Print the state stack on the debug stream.
@@ -1112,8 +1127,8 @@ namespace isc { namespace eval {
 
 #line 21 "parser.yy" // lalr1.cc:1167
 } } // isc::eval
-#line 1116 "parser.cc" // lalr1.cc:1167
-#line 159 "parser.yy" // lalr1.cc:1168
+#line 1131 "parser.cc" // lalr1.cc:1167
+#line 165 "parser.yy" // lalr1.cc:1168
 
 void
 isc::eval::EvalParser::error(const location_type& loc,

+ 63 - 52
src/lib/eval/parser.h

@@ -333,21 +333,22 @@ namespace isc { namespace eval {
         TOKEN_EQUAL = 258,
         TOKEN_OPTION = 259,
         TOKEN_SUBSTRING = 260,
-        TOKEN_TEXT = 261,
-        TOKEN_HEX = 262,
-        TOKEN_NOT = 263,
-        TOKEN_ALL = 264,
-        TOKEN_DOT = 265,
-        TOKEN_COMA = 266,
-        TOKEN_LPAREN = 267,
-        TOKEN_RPAREN = 268,
-        TOKEN_LBRACKET = 269,
-        TOKEN_RBRACKET = 270,
-        TOKEN_STRING = 271,
-        TOKEN_INTEGER = 272,
-        TOKEN_HEXSTRING = 273,
-        TOKEN_OPTION_NAME = 274,
-        TOKEN_TOKEN = 275
+        TOKEN_NOT = 261,
+        TOKEN_TEXT = 262,
+        TOKEN_HEX = 263,
+        TOKEN_EXISTS = 264,
+        TOKEN_ALL = 265,
+        TOKEN_DOT = 266,
+        TOKEN_COMA = 267,
+        TOKEN_LPAREN = 268,
+        TOKEN_RPAREN = 269,
+        TOKEN_LBRACKET = 270,
+        TOKEN_RBRACKET = 271,
+        TOKEN_STRING = 272,
+        TOKEN_INTEGER = 273,
+        TOKEN_HEXSTRING = 274,
+        TOKEN_OPTION_NAME = 275,
+        TOKEN_TOKEN = 276
       };
     };
 
@@ -476,6 +477,10 @@ namespace isc { namespace eval {
 
     static inline
     symbol_type
+    make_NOT (const location_type& l);
+
+    static inline
+    symbol_type
     make_TEXT (const location_type& l);
 
     static inline
@@ -484,7 +489,7 @@ namespace isc { namespace eval {
 
     static inline
     symbol_type
-    make_NOT (const location_type& l);
+    make_EXISTS (const location_type& l);
 
     static inline
     symbol_type
@@ -739,12 +744,12 @@ namespace isc { namespace eval {
     enum
     {
       yyeof_ = 0,
-      yylast_ = 36,     ///< Last index in yytable_.
+      yylast_ = 41,     ///< Last index in yytable_.
       yynnts_ = 8,  ///< Number of nonterminal symbols.
       yyfinal_ = 15, ///< Termination state number.
       yyterror_ = 1,
       yyerrcode_ = 256,
-      yyntokens_ = 21  ///< Number of tokens.
+      yyntokens_ = 22  ///< Number of tokens.
     };
 
 
@@ -788,9 +793,9 @@ namespace isc { namespace eval {
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
-      15,    16,    17,    18,    19,    20
+      15,    16,    17,    18,    19,    20,    21
     };
-    const unsigned int user_token_number_max_ = 275;
+    const unsigned int user_token_number_max_ = 276;
     const token_number_type undef_token_ = 2;
 
     if (static_cast<int>(t) <= yyeof_)
@@ -823,19 +828,19 @@ namespace isc { namespace eval {
   {
       switch (other.type_get ())
     {
-      case 26: // option_repr_type
+      case 27: // option_repr_type
         value.copy< TokenOption::RepresentationType > (other.value);
         break;
 
-      case 16: // "constant string"
-      case 17: // "integer"
-      case 18: // "constant hexstring"
-      case 19: // "option name"
-      case 20: // TOKEN
+      case 17: // "constant string"
+      case 18: // "integer"
+      case 19: // "constant hexstring"
+      case 20: // "option name"
+      case 21: // TOKEN
         value.copy< std::string > (other.value);
         break;
 
-      case 25: // option_code
+      case 26: // option_code
         value.copy< uint16_t > (other.value);
         break;
 
@@ -856,19 +861,19 @@ namespace isc { namespace eval {
     (void) v;
       switch (this->type_get ())
     {
-      case 26: // option_repr_type
+      case 27: // option_repr_type
         value.copy< TokenOption::RepresentationType > (v);
         break;
 
-      case 16: // "constant string"
-      case 17: // "integer"
-      case 18: // "constant hexstring"
-      case 19: // "option name"
-      case 20: // TOKEN
+      case 17: // "constant string"
+      case 18: // "integer"
+      case 19: // "constant hexstring"
+      case 20: // "option name"
+      case 21: // TOKEN
         value.copy< std::string > (v);
         break;
 
-      case 25: // option_code
+      case 26: // option_code
         value.copy< uint16_t > (v);
         break;
 
@@ -934,19 +939,19 @@ namespace isc { namespace eval {
     // Type destructor.
     switch (yytype)
     {
-      case 26: // option_repr_type
+      case 27: // option_repr_type
         value.template destroy< TokenOption::RepresentationType > ();
         break;
 
-      case 16: // "constant string"
-      case 17: // "integer"
-      case 18: // "constant hexstring"
-      case 19: // "option name"
-      case 20: // TOKEN
+      case 17: // "constant string"
+      case 18: // "integer"
+      case 19: // "constant hexstring"
+      case 20: // "option name"
+      case 21: // TOKEN
         value.template destroy< std::string > ();
         break;
 
-      case 25: // option_code
+      case 26: // option_code
         value.template destroy< uint16_t > ();
         break;
 
@@ -973,19 +978,19 @@ namespace isc { namespace eval {
     super_type::move(s);
       switch (this->type_get ())
     {
-      case 26: // option_repr_type
+      case 27: // option_repr_type
         value.move< TokenOption::RepresentationType > (s.value);
         break;
 
-      case 16: // "constant string"
-      case 17: // "integer"
-      case 18: // "constant hexstring"
-      case 19: // "option name"
-      case 20: // TOKEN
+      case 17: // "constant string"
+      case 18: // "integer"
+      case 19: // "constant hexstring"
+      case 20: // "option name"
+      case 21: // TOKEN
         value.move< std::string > (s.value);
         break;
 
-      case 25: // option_code
+      case 26: // option_code
         value.move< uint16_t > (s.value);
         break;
 
@@ -1046,7 +1051,7 @@ namespace isc { namespace eval {
     {
        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
-     275
+     275,   276
     };
     return static_cast<token_type> (yytoken_number_[type]);
   }
@@ -1076,6 +1081,12 @@ namespace isc { namespace eval {
   }
 
   EvalParser::symbol_type
+  EvalParser::make_NOT (const location_type& l)
+  {
+    return symbol_type (token::TOKEN_NOT, l);
+  }
+
+  EvalParser::symbol_type
   EvalParser::make_TEXT (const location_type& l)
   {
     return symbol_type (token::TOKEN_TEXT, l);
@@ -1088,9 +1099,9 @@ namespace isc { namespace eval {
   }
 
   EvalParser::symbol_type
-  EvalParser::make_NOT (const location_type& l)
+  EvalParser::make_EXISTS (const location_type& l)
   {
-    return symbol_type (token::TOKEN_NOT, l);
+    return symbol_type (token::TOKEN_EXISTS, l);
   }
 
   EvalParser::symbol_type
@@ -1168,7 +1179,7 @@ namespace isc { namespace eval {
 
 #line 21 "parser.yy" // lalr1.cc:392
 } } // isc::eval
-#line 1172 "parser.h" // lalr1.cc:392
+#line 1183 "parser.h" // lalr1.cc:392
 
 
 

+ 7 - 1
src/lib/eval/parser.yy

@@ -47,9 +47,10 @@ using namespace isc::eval;
   EQUAL "=="
   OPTION "option"
   SUBSTRING "substring"
+  NOT "not"
   TEXT "text"
   HEX "hex"
-  NOT "not"
+  EXISTS "exists"
   ALL "all"
   DOT "."
   COMA ","
@@ -91,6 +92,11 @@ bool_expr : "(" bool_expr ")"
                     TokenPtr eq(new TokenEqual());
                     ctx.expression.push_back(eq);
                 }
+          | OPTION "[" option_code "]" "." EXISTS
+                {
+                    TokenPtr opt(new TokenOption($3, TokenOption::EXISTS));
+                    ctx.expression.push_back(opt);
+                }
           ;
 
 string_expr : STRING

+ 13 - 0
src/lib/eval/tests/context_unittest.cc

@@ -228,6 +228,16 @@ TEST_F(EvalContextTest, optionWithName) {
     checkTokenOption(eval.expression.at(0), 12);
 }
 
+// Test parsing of an option existence
+TEST_F(EvalContextTest, optionExists) {
+    EvalContext eval(Option::V4);
+
+    EXPECT_NO_THROW(parsed_ = eval.parseString("option[100].exists"));
+    EXPECT_TRUE(parsed_);
+    ASSERT_EQ(1, eval.expression.size());
+    checkTokenOption(eval.expression.at(0), 100);
+}
+
 // Test checking that whitespace can surround option name.
 TEST_F(EvalContextTest, optionWithNameAndWhitespace) {
     EvalContext eval(Option::V4);
@@ -373,6 +383,9 @@ TEST_F(EvalContextTest, parseErrors) {
                "expecting integer or option name");
     checkError("option[10].bin", "<string>:1.12: Invalid character: b");
     checkError("option[boot-size].bin", "<string>:1.19: Invalid character: b");
+    checkError("option[10].exists == 'foo'",
+               "<string>:1.19-20: syntax error, unexpected ==, "
+               "expecting end of file");
     checkError("substring('foobar') == 'f'",
                "<string>:1.19: syntax error, "
                "unexpected ), expecting \",\"");

+ 26 - 0
src/lib/eval/tests/evaluate_unittest.cc

@@ -190,6 +190,32 @@ TEST_F(EvaluateTest, compare6) {
     EXPECT_FALSE(result_);
 }
 
+// A test using option existence
+TEST_F(EvaluateTest, exists) {
+    TokenPtr toption;
+
+    ASSERT_NO_THROW(toption.reset(new TokenOption(100, TokenOption::EXISTS)));
+    e_.push_back(toption);
+
+    ASSERT_NO_THROW(result_ = evaluate(e_, *pkt4_));
+    EXPECT_TRUE(result_);
+    ASSERT_NO_THROW(result_ = evaluate(e_, *pkt6_));
+    EXPECT_TRUE(result_);
+}
+
+// A test using option non-existence
+TEST_F(EvaluateTest, dontExists) {
+    TokenPtr toption;
+
+    ASSERT_NO_THROW(toption.reset(new TokenOption(101, TokenOption::EXISTS)));
+    e_.push_back(toption);
+
+    ASSERT_NO_THROW(result_ = evaluate(e_, *pkt4_));
+    EXPECT_FALSE(result_);
+    ASSERT_NO_THROW(result_ = evaluate(e_, *pkt6_));
+    EXPECT_FALSE(result_);
+}
+
 // A test using packets.
 TEST_F(EvaluateTest, packet) {
     TokenPtr toption;

+ 44 - 0
src/lib/eval/tests/token_unittest.cc

@@ -303,6 +303,28 @@ TEST_F(TokenTest, optionHexString4) {
     EXPECT_EQ("hundred4", values_.top());
 }
 
+// This test checks if a token representing an option value is able to check
+// the existence ofthe option from an IPv4 packet.
+TEST_F(TokenTest, optionExistsString4) {
+    TokenPtr found;
+    TokenPtr not_found;
+
+    // The packets we use have option 100 with a string in them.
+    ASSERT_NO_THROW(found.reset(new TokenOption(100, TokenOption::EXISTS)));
+    ASSERT_NO_THROW(not_found.reset(new TokenOption(101, TokenOption::EXISTS)));
+
+    ASSERT_NO_THROW(found->evaluate(*pkt4_, values_));
+    ASSERT_NO_THROW(not_found->evaluate(*pkt4_, values_));
+
+    // There should be 2 values evaluated.
+    ASSERT_EQ(2, values_.size());
+
+    // This is a stack, so the pop order is inversed.
+    EXPECT_EQ("false", values_.top());
+    values_.pop();
+    EXPECT_EQ("true", values_.top());
+}
+
 // This test checks if a token representing an option value is able to extract
 // the option from an IPv6 packet and properly store the option's value.
 TEST_F(TokenTest, optionString6) {
@@ -360,6 +382,28 @@ TEST_F(TokenTest, optionHexString6) {
     EXPECT_EQ("hundred6", values_.top());
 }
 
+// This test checks if a token representing an option value is able to check
+// the existence ofthe option from an IPv6 packet.
+TEST_F(TokenTest, optionExistsString6) {
+    TokenPtr found;
+    TokenPtr not_found;
+
+    // The packets we use have option 100 with a string in them.
+    ASSERT_NO_THROW(found.reset(new TokenOption(100, TokenOption::EXISTS)));
+    ASSERT_NO_THROW(not_found.reset(new TokenOption(101, TokenOption::EXISTS)));
+
+    ASSERT_NO_THROW(found->evaluate(*pkt6_, values_));
+    ASSERT_NO_THROW(not_found->evaluate(*pkt6_, values_));
+
+    // There should be 2 values evaluated.
+    ASSERT_EQ(2, values_.size());
+
+    // This is a stack, so the pop order is inversed.
+    EXPECT_EQ("false", values_.top());
+    values_.pop();
+    EXPECT_EQ("true", values_.top());
+}
+
 // This test checks if a token representing an == operator is able to
 // compare two values (with incorrectly built stack).
 TEST_F(TokenTest, optionEqualInvalid) {

+ 5 - 1
src/lib/eval/token.cc

@@ -69,13 +69,17 @@ TokenOption::evaluate(const Pkt& pkt, ValueStack& values) {
     if (opt) {
         if (representation_type_ == TEXTUAL) {
             opt_str = opt->toString();
-        } else {
+        } else if (representation_type_ == HEXADECIMAL) {
             std::vector<uint8_t> binary = opt->toBinary();
             opt_str.resize(binary.size());
             if (!binary.empty()) {
                 memmove(&opt_str[0], &binary[0], binary.size());
             }
+        } else {
+            opt_str = "true";
         }
+    } else if (representation_type_ == EXISTS) {
+        opt_str = "false";
     }
 
     // Push value of the option or empty string if there was no such option

+ 5 - 3
src/lib/eval/token.h

@@ -144,20 +144,22 @@ protected:
 /// option[vendor-class].text
 ///
 /// During the evaluation it tries to extract the value of the specified
-/// option. If the option is not found, an empty string ("") is returned.
+/// option. If the option is not found, an empty string ("") is returned
+/// (or "false" when the representation is EXISTS).
 class TokenOption : public Token {
 public:
 
     /// @brief Token representation type.
     ///
     /// There are many possible ways in which option can be presented.
-    /// Currently the textual and hexadecimal representations are
+    /// Currently the textual, hexadecimal and exists representations are
     /// supported. The type of representation is specified in the
     /// constructor and it affects the value generated by the
     /// @c TokenOption::evaluate function.
     enum RepresentationType {
         TEXTUAL,
-        HEXADECIMAL
+        HEXADECIMAL,
+        EXISTS
     };
 
     /// @brief Constructor that takes an option code as a parameter