From: Francis Dupont Date: Wed, 9 Dec 2015 12:41:28 +0000 (+0100) Subject: [4231] Added ( bool_expr ) X-Git-Tag: trac4232_base~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ce332093aaef9bf2e29d9f47c309728d8478360e;p=thirdparty%2Fkea.git [4231] Added ( bool_expr ) --- diff --git a/src/lib/eval/lexer.cc b/src/lib/eval/lexer.cc index 2122b1d39a..245922c83b 100644 --- a/src/lib/eval/lexer.cc +++ b/src/lib/eval/lexer.cc @@ -18,7 +18,7 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 +#define YY_FLEX_SUBMINOR_VERSION 39 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -72,7 +72,6 @@ typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; -typedef uint64_t flex_uint64_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; @@ -80,7 +79,6 @@ typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN @@ -111,6 +109,8 @@ typedef unsigned int flex_uint32_t; #define UINT32_MAX (4294967295U) #endif +#endif /* ! C99 */ + #endif /* ! FLEXINT_H */ /* %endif */ @@ -225,11 +225,18 @@ extern FILE *yyin, *yyout; */ #define YY_LESS_LINENO(n) \ do { \ - yy_size_t yyl;\ + int yyl;\ for ( yyl = n; yyl < yyleng; ++yyl )\ if ( yytext[yyl] == '\n' )\ --yylineno;\ }while(0) + #define YY_LINENO_REWIND_TO(dst) \ + do {\ + const char *p;\ + for ( p = yy_cp-1; p >= (dst); --p)\ + if ( *p == '\n' )\ + --yylineno;\ + }while(0) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ @@ -420,7 +427,7 @@ void yyfree (void * ); /* %% [1.0] yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here */ /* Begin user sect3 */ -#define yywrap(n) 1 +#define yywrap() 1 #define YY_SKIP_YYWRAP #define FLEX_DEBUG @@ -438,6 +445,8 @@ int yylineno = 1; extern char *yytext; #define yytext_ptr yytext +/* %% [1.5] DFA */ + /* %if-c-only Standard (non-C++) definition */ static yy_state_type yy_get_previous_state (void ); @@ -453,7 +462,7 @@ static void yy_fatal_error (yyconst char msg[] ); #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ /* %% [2.0] code to fiddle yytext and yyleng for yymore() goes here \ */\ - yyleng = (yy_size_t) (yy_cp - yy_bp); \ + yyleng = (size_t) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ /* %% [3.0] code to copy yytext_ptr to yytext[] goes here, if %array \ */\ @@ -691,7 +700,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 695 "lexer.cc" +#line 704 "lexer.cc" #define INITIAL 0 @@ -809,7 +818,7 @@ static int input (void ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO fwrite( yytext, yyleng, 1, yyout ) +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) /* %endif */ /* %if-c++-only C++ definition */ /* %endif */ @@ -824,7 +833,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - yy_size_t n; \ + size_t n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -930,17 +939,6 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -/* %% [7.0] user's declarations go here */ -#line 79 "lexer.ll" - - - - // Code run each time yylex is called. - loc.step(); - - -#line 943 "lexer.cc" - if ( !(yy_init) ) { (yy_init) = 1; @@ -981,6 +979,18 @@ YY_DECL yy_load_buffer_state( ); } + { +/* %% [7.0] user's declarations go here */ +#line 79 "lexer.ll" + + + + // Code run each time yylex is called. + loc.step(); + + +#line 993 "lexer.cc" + while ( 1 ) /* loops until end-of-file is reached */ { /* %% [8.0] yymore()-related code goes here */ @@ -1003,7 +1013,7 @@ YY_DECL yy_match: do { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; @@ -1020,7 +1030,6 @@ yy_find_action: /* %% [10.0] code to find the action number goes here */ yy_current_state = *--(yy_state_ptr); (yy_lp) = yy_accept[yy_current_state]; -goto find_rule; /* Shut up GCC warning -Wall */ find_rule: /* we branch to this label when backing up */ for ( ; ; ) /* until we find what rule we matched */ { @@ -1235,7 +1244,7 @@ YY_RULE_SETUP #line 148 "lexer.ll" ECHO; YY_BREAK -#line 1239 "lexer.cc" +#line 1248 "lexer.cc" case YY_END_OF_BUFFER: { @@ -1365,6 +1374,7 @@ ECHO; "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ + } /* end of user's declarations */ } /* end of yylex */ /* %ok-for-header */ @@ -1551,7 +1561,7 @@ static int yy_get_next_buffer (void) if ( ! yy_is_jam ) *(yy_state_ptr)++ = yy_current_state; - return yy_is_jam ? 0 : yy_current_state; + return yy_is_jam ? 0 : yy_current_state; } /* %if-c-only */ @@ -1610,7 +1620,7 @@ static int yy_get_next_buffer (void) case EOB_ACT_END_OF_FILE: { if ( yywrap( ) ) - return 0; + return EOF; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; @@ -1774,17 +1784,6 @@ static void yy_load_buffer_state (void) yyfree((void *) b ); } -/* %if-c-only */ - -#ifndef __cplusplus -extern int isatty (int ); -#endif /* __cplusplus */ - -/* %endif */ - -/* %if-c++-only */ -/* %endif */ - /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. @@ -2025,8 +2024,8 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) /* %if-c-only */ /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. - * @param bytes the byte buffer to scan - * @param len the number of bytes in the buffer pointed to by @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */ @@ -2034,7 +2033,8 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len { YY_BUFFER_STATE b; char *buf; - yy_size_t n, i; + yy_size_t n; + yy_size_t i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; @@ -2320,7 +2320,7 @@ EvalContext::scanStringBegin() buffer = yy_scan_bytes(string_.c_str(),string_.size()); if (!buffer) { fatal("cannot scan string"); - // fatal() throws an exception so this can't be reached + // fatal() throws an exception so this can't be reached } } diff --git a/src/lib/eval/lexer.ll b/src/lib/eval/lexer.ll index f8297139fa..61207ef2e0 100644 --- a/src/lib/eval/lexer.ll +++ b/src/lib/eval/lexer.ll @@ -158,7 +158,7 @@ EvalContext::scanStringBegin() buffer = yy_scan_bytes(string_.c_str(), string_.size()); if (!buffer) { fatal("cannot scan string"); - // fatal() throws an exception so this can't be reached + // fatal() throws an exception so this can't be reached } } diff --git a/src/lib/eval/parser.cc b/src/lib/eval/parser.cc index 34bd22a8e2..ff2cdc1d6f 100644 --- a/src/lib/eval/parser.cc +++ b/src/lib/eval/parser.cc @@ -613,8 +613,8 @@ namespace isc { namespace eval { { switch (yyn) { - case 3: -#line 83 "parser.yy" // lalr1.cc:859 + case 4: +#line 84 "parser.yy" // lalr1.cc:859 { TokenPtr eq(new TokenEqual()); ctx.expression.push_back(eq); @@ -622,8 +622,8 @@ namespace isc { namespace eval { #line 623 "parser.cc" // lalr1.cc:859 break; - case 4: -#line 90 "parser.yy" // lalr1.cc:859 + case 5: +#line 91 "parser.yy" // lalr1.cc:859 { TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ())); ctx.expression.push_back(str); @@ -631,8 +631,8 @@ namespace isc { namespace eval { #line 632 "parser.cc" // lalr1.cc:859 break; - case 5: -#line 95 "parser.yy" // lalr1.cc:859 + case 6: +#line 96 "parser.yy" // lalr1.cc:859 { TokenPtr hex(new TokenHexString(yystack_[0].value.as< std::string > ())); ctx.expression.push_back(hex); @@ -640,8 +640,8 @@ namespace isc { namespace eval { #line 641 "parser.cc" // lalr1.cc:859 break; - case 6: -#line 100 "parser.yy" // lalr1.cc:859 + case 7: +#line 101 "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); @@ -649,8 +649,8 @@ namespace isc { namespace eval { #line 650 "parser.cc" // lalr1.cc:859 break; - case 7: -#line 105 "parser.yy" // lalr1.cc:859 + case 8: +#line 106 "parser.yy" // lalr1.cc:859 { TokenPtr sub(new TokenSubstring()); ctx.expression.push_back(sub); @@ -658,40 +658,40 @@ namespace isc { namespace eval { #line 659 "parser.cc" // lalr1.cc:859 break; - case 9: -#line 114 "parser.yy" // lalr1.cc:859 + case 10: +#line 115 "parser.yy" // lalr1.cc:859 { yylhs.value.as< uint16_t > () = ctx.convertOptionCode(yystack_[0].value.as< std::string > (), yystack_[0].location); } #line 667 "parser.cc" // lalr1.cc:859 break; - case 10: -#line 118 "parser.yy" // lalr1.cc:859 + case 11: +#line 119 "parser.yy" // lalr1.cc:859 { yylhs.value.as< uint16_t > () = ctx.convertOptionName(yystack_[0].value.as< std::string > (), yystack_[0].location); } #line 675 "parser.cc" // lalr1.cc:859 break; - case 11: -#line 124 "parser.yy" // lalr1.cc:859 + case 12: +#line 125 "parser.yy" // lalr1.cc:859 { yylhs.value.as< TokenOption::RepresentationType > () = TokenOption::TEXTUAL; } #line 683 "parser.cc" // lalr1.cc:859 break; - case 12: -#line 128 "parser.yy" // lalr1.cc:859 + case 13: +#line 129 "parser.yy" // lalr1.cc:859 { yylhs.value.as< TokenOption::RepresentationType > () = TokenOption::HEXADECIMAL; } #line 691 "parser.cc" // lalr1.cc:859 break; - case 13: -#line 134 "parser.yy" // lalr1.cc:859 + case 14: +#line 135 "parser.yy" // lalr1.cc:859 { TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ())); ctx.expression.push_back(str); @@ -699,8 +699,8 @@ namespace isc { namespace eval { #line 700 "parser.cc" // lalr1.cc:859 break; - case 14: -#line 141 "parser.yy" // lalr1.cc:859 + case 15: +#line 142 "parser.yy" // lalr1.cc:859 { TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ())); ctx.expression.push_back(str); @@ -708,8 +708,8 @@ namespace isc { namespace eval { #line 709 "parser.cc" // lalr1.cc:859 break; - case 15: -#line 146 "parser.yy" // lalr1.cc:859 + case 16: +#line 147 "parser.yy" // lalr1.cc:859 { TokenPtr str(new TokenString("all")); ctx.expression.push_back(str); @@ -973,77 +973,79 @@ namespace isc { namespace eval { } - const signed char EvalParser::yypact_ninf_ = -14; + const signed char EvalParser::yypact_ninf_ = -9; const signed char EvalParser::yytable_ninf_ = -1; const signed char EvalParser::yypact_[] = { - -4, -9, -5, -14, -14, -14, 8, -14, 9, -13, - -4, -14, -4, -14, -14, 0, 11, -14, 13, 2, - 10, -14, 14, -14, -14, -14, -6, -14, -14, 7, - -14 + -4, -8, -3, -4, -9, -9, -9, 12, -9, 19, + 1, -1, 11, -9, -1, -9, -9, 10, 15, -9, + -9, 17, 13, 14, -9, 18, -9, -9, -9, -6, + -9, -9, 20, -9 }; const unsigned char EvalParser::yydefact_[] = { - 0, 0, 0, 4, 5, 8, 0, 2, 0, 0, - 0, 1, 0, 9, 10, 0, 0, 3, 0, 0, - 0, 13, 0, 11, 12, 6, 0, 15, 14, 0, - 7 + 0, 0, 0, 0, 5, 6, 9, 0, 2, 0, + 0, 0, 0, 1, 0, 10, 11, 0, 0, 3, + 4, 0, 0, 0, 14, 0, 12, 13, 7, 0, + 16, 15, 0, 8 }; const signed char EvalParser::yypgoto_[] = { - -14, -14, -14, -3, -14, -14, -14, -14 + -9, -9, 24, -5, -9, -9, -9, -9 }; const signed char EvalParser::yydefgoto_[] = { - -1, 6, 7, 8, 15, 25, 22, 29 + -1, 7, 8, 9, 17, 28, 25, 32 }; const unsigned char EvalParser::yytable_[] = { - 1, 2, 27, 13, 9, 14, 10, 16, 11, 17, - 28, 3, 12, 4, 18, 5, 23, 24, 21, 30, - 0, 19, 20, 0, 26 + 1, 2, 30, 1, 2, 10, 18, 3, 11, 20, + 31, 4, 13, 5, 4, 6, 5, 15, 6, 16, + 26, 27, 14, 19, 21, 22, 23, 12, 29, 24, + 0, 0, 33 }; const signed char EvalParser::yycheck_[] = { - 4, 5, 8, 16, 13, 18, 11, 10, 0, 12, - 16, 15, 3, 17, 14, 19, 6, 7, 16, 12, - -1, 10, 9, -1, 10 + 4, 5, 8, 4, 5, 13, 11, 11, 11, 14, + 16, 15, 0, 17, 15, 19, 17, 16, 19, 18, + 6, 7, 3, 12, 14, 10, 9, 3, 10, 16, + -1, -1, 12 }; const unsigned char EvalParser::yystos_[] = { - 0, 4, 5, 15, 17, 19, 21, 22, 23, 13, - 11, 0, 3, 16, 18, 24, 23, 23, 14, 10, - 9, 16, 26, 6, 7, 25, 10, 8, 16, 27, - 12 + 0, 4, 5, 11, 15, 17, 19, 21, 22, 23, + 13, 11, 22, 0, 3, 16, 18, 24, 23, 12, + 23, 14, 10, 9, 16, 26, 6, 7, 25, 10, + 8, 16, 27, 12 }; const unsigned char EvalParser::yyr1_[] = { - 0, 20, 21, 22, 23, 23, 23, 23, 23, 24, - 24, 25, 25, 26, 27, 27 + 0, 20, 21, 22, 22, 23, 23, 23, 23, 23, + 24, 24, 25, 25, 26, 27, 27 }; const unsigned char EvalParser::yyr2_[] = { - 0, 2, 1, 3, 1, 1, 6, 8, 1, 1, - 1, 1, 1, 1, 1, 1 + 0, 2, 1, 3, 3, 1, 1, 6, 8, 1, + 1, 1, 1, 1, 1, 1, 1 }; @@ -1065,8 +1067,8 @@ namespace isc { namespace eval { const unsigned char EvalParser::yyrline_[] = { - 0, 79, 79, 82, 89, 94, 99, 104, 109, 113, - 117, 123, 127, 133, 140, 145 + 0, 79, 79, 82, 83, 90, 95, 100, 105, 110, + 114, 118, 124, 128, 134, 141, 146 }; // Print the state stack on the debug stream. @@ -1101,8 +1103,8 @@ namespace isc { namespace eval { #line 21 "parser.yy" // lalr1.cc:1167 } } // isc::eval -#line 1105 "parser.cc" // lalr1.cc:1167 -#line 152 "parser.yy" // lalr1.cc:1168 +#line 1107 "parser.cc" // lalr1.cc:1167 +#line 153 "parser.yy" // lalr1.cc:1168 void isc::eval::EvalParser::error(const location_type& loc, diff --git a/src/lib/eval/parser.h b/src/lib/eval/parser.h index 85718716cf..b5a1d9d0cc 100644 --- a/src/lib/eval/parser.h +++ b/src/lib/eval/parser.h @@ -734,9 +734,9 @@ namespace isc { namespace eval { enum { yyeof_ = 0, - yylast_ = 24, ///< Last index in yytable_. + yylast_ = 32, ///< Last index in yytable_. yynnts_ = 8, ///< Number of nonterminal symbols. - yyfinal_ = 11, ///< Termination state number. + yyfinal_ = 13, ///< Termination state number. yyterror_ = 1, yyerrcode_ = 256, yyntokens_ = 20 ///< Number of tokens. diff --git a/src/lib/eval/parser.yy b/src/lib/eval/parser.yy index de4a96136c..961889929e 100644 --- a/src/lib/eval/parser.yy +++ b/src/lib/eval/parser.yy @@ -79,7 +79,8 @@ using namespace isc::eval; expression : bool_expr ; -bool_expr : string_expr EQUAL string_expr +bool_expr : "(" bool_expr ")" + | string_expr EQUAL string_expr { TokenPtr eq(new TokenEqual()); ctx.expression.push_back(eq); diff --git a/src/lib/eval/tests/context_unittest.cc b/src/lib/eval/tests/context_unittest.cc index 25985b3c08..030cacbff6 100644 --- a/src/lib/eval/tests/context_unittest.cc +++ b/src/lib/eval/tests/context_unittest.cc @@ -341,6 +341,12 @@ TEST_F(EvalContextTest, parseErrors) { checkError("== 'ab'", ":1.1-2: syntax error, unexpected =="); checkError("'foo' ==", ":1.9: syntax error, unexpected end of file"); + checkError("('foo' == 'bar'", + ":1.16: syntax error, unexpected end of file, " + "expecting )"); + checkError("('foo' == 'bar') ''", + ":1.18-19: syntax error, unexpected constant string, " + "expecting end of file"); checkError("option 'ab'", ":1.8-11: syntax error, unexpected " "constant string, expecting ["); @@ -382,6 +388,9 @@ TEST_F(EvalContextTest, typeErrors) { checkError("substring('foobar',0x32,1) == 'foo'", ":1.20-23: syntax error, unexpected constant " "hexstring, expecting integer"); + checkError("('foo' == 'bar') == 'false'", + ":1.18-19: syntax error, unexpected ==, " + "expecting end of file"); } };