]> granicus.if.org Git - apache/blobdiff - server/util_expr_parse.y
Move two variable assignments off the fast path.
[apache] / server / util_expr_parse.y
index 568597f7cab75f407fefd625736dd335e4104679..a389410b7fdaebf819c7b7adfb55b3dfdab3ffab 100644 (file)
 %error-verbose
 %defines
 %lex-param   { void *yyscanner }
-%parse-param { ap_expr_parse_ctx *ctx }
+%parse-param { ap_expr_parse_ctx_t *ctx }
 
 %{
 #include "util_expr_private.h"
 %}
 
 %union {
-    char    *cpVal;
-    ap_expr *exVal;
-    int      num;
+    char      *cpVal;
+    ap_expr_t *exVal;
+    int        num;
 }
 
-%token  T_TRUE
-%token  T_FALSE
-
-%token  <cpVal> ERROR
-
-%token  <cpVal> T_DIGIT
-%token  <cpVal> T_ID
-%token  <cpVal> T_STRING
-%token  <cpVal> T_REGEX
-%token  <cpVal> T_REGEX_I
-%token  <num>   T_REGEX_BACKREF
-%token  <cpVal> T_OP_UNARY
-%token  <cpVal> T_OP_BINARY
-
-%token  T_STR_BEGIN
-%token  T_STR_END
-%token  T_VAR_BEGIN
-%token  T_VAR_END
-
-%token  T_OP_EQ
-%token  T_OP_NE
-%token  T_OP_LT
-%token  T_OP_LE
-%token  T_OP_GT
-%token  T_OP_GE
-%token  T_OP_REG
-%token  T_OP_NRE
-%token  T_OP_IN
-%token  T_OP_STR_EQ
-%token  T_OP_STR_NE
-%token  T_OP_STR_LT
-%token  T_OP_STR_LE
-%token  T_OP_STR_GT
-%token  T_OP_STR_GE
-%token  T_OP_CONCAT
-
-%token  T_OP_OR
-%token  T_OP_AND
-%token  T_OP_NOT
-
-%left   T_OP_OR
-%left   T_OP_AND
-%left   T_OP_NOT
-%left   T_OP_CONCAT
+%token  T_TRUE                      "true"
+%token  T_FALSE                     "false"
+
+%token  T_EXPR_BOOL                 "boolean expression"
+%token  T_EXPR_STRING               "string expression"
+
+%token  <cpVal> T_ERROR             "error token"
+
+%token  <cpVal> T_DIGIT             "number"
+%token  <cpVal> T_ID                "identifier"
+%token  <cpVal> T_STRING            "cstring"
+%token  <cpVal> T_REGEX             "regex"
+%token  <cpVal> T_REGEX_I           "case-indendent regex"
+%token  <num>   T_REGEX_BACKREF     "regex back reference"
+%token  <cpVal> T_OP_UNARY          "unary operator"
+%token  <cpVal> T_OP_BINARY         "binary operator"
+
+%token  T_STR_BEGIN                 "start of string"
+%token  T_STR_END                   "end of string"
+%token  T_VAR_BEGIN                 "start of variable name"
+%token  T_VAR_END                   "end of variable name"
+
+%token  T_OP_EQ                     "integer equal"
+%token  T_OP_NE                     "integer not equal"
+%token  T_OP_LT                     "integer less than"
+%token  T_OP_LE                     "integer less or equal"
+%token  T_OP_GT                     "integer greater than"
+%token  T_OP_GE                     "integer greater or equal"
+%token  T_OP_REG                    "regex match"
+%token  T_OP_NRE                    "regex non-match"
+%token  T_OP_IN                     "contained in"
+%token  T_OP_STR_EQ                 "string equal"
+%token  T_OP_STR_NE                 "string not equal"
+%token  T_OP_STR_LT                 "string less than"
+%token  T_OP_STR_LE                 "string less or equal"
+%token  T_OP_STR_GT                 "string greater than"
+%token  T_OP_STR_GE                 "string greater or equal"
+%token  T_OP_CONCAT                 "string concatenation"
+
+%token  T_OP_OR                     "logical or"
+%token  T_OP_AND                    "logical and"
+%token  T_OP_NOT                    "logical not"
+
+%right  T_OP_OR
+%right  T_OP_AND
+%right  T_OP_NOT
+%right  T_OP_CONCAT
 
 %type   <exVal>   expr
 %type   <exVal>   comparison
-%type   <exVal>   strfunccall
-%type   <exVal>   lstfunccall
+%type   <exVal>   strfunccall   "function"
+%type   <exVal>   lstfunccall   "listfunction"
 %type   <exVal>   regex
 %type   <exVal>   words
 %type   <exVal>   wordlist
 %type   <exVal>   word
 %type   <exVal>   string
-%type   <exVal>   strpart
-%type   <exVal>   var
-%type   <exVal>   backref
+%type   <exVal>   strpart       "stringpart"
+%type   <exVal>   var           "variable"
+%type   <exVal>   backref       "rebackref"
 
 %{
 #include "util_expr_private.h"
@@ -106,8 +109,9 @@ int ap_expr_yylex(YYSTYPE *lvalp, void *scanner);
 
 %%
 
-root      : expr                         { ctx->expr = $1; }
-          | ERROR                        { YYABORT; }
+root      : T_EXPR_BOOL   expr           { ctx->expr = $2; }
+          | T_EXPR_STRING string         { ctx->expr = $2; }
+          | T_ERROR                      { YYABORT; }
           ;
 
 expr      : T_TRUE                       { $$ = ap_expr_make(op_True,        NULL, NULL, ctx); }
@@ -117,7 +121,9 @@ expr      : T_TRUE                       { $$ = ap_expr_make(op_True,        NUL
           | expr T_OP_AND expr           { $$ = ap_expr_make(op_And,         $1,   $3,   ctx); }
           | comparison                   { $$ = ap_expr_make(op_Comp,        $1,   NULL, ctx); }
           | T_OP_UNARY word              { $$ = ap_expr_unary_op_make(       $1,   $2,   ctx); }
+          | word T_OP_BINARY word        { $$ = ap_expr_binary_op_make($2,   $1,   $3,   ctx); }
           | '(' expr ')'                 { $$ = $2; }
+          | T_ERROR                      { YYABORT; }
           ;
 
 comparison: word T_OP_EQ word            { $$ = ap_expr_make(op_EQ,      $1, $3, ctx); }
@@ -135,7 +141,6 @@ comparison: word T_OP_EQ word            { $$ = ap_expr_make(op_EQ,      $1, $3,
           | word T_OP_IN wordlist        { $$ = ap_expr_make(op_IN,      $1, $3, ctx); }
           | word T_OP_REG regex          { $$ = ap_expr_make(op_REG,     $1, $3, ctx); }
           | word T_OP_NRE regex          { $$ = ap_expr_make(op_NRE,     $1, $3, ctx); }
-          | word T_OP_BINARY word        { $$ = ap_expr_binary_op_make($2, $1, $3, ctx); }
           ;
 
 wordlist  : lstfunccall                  { $$ = $1; }
@@ -148,6 +153,7 @@ words     : word                         { $$ = ap_expr_make(op_ListElement, $1,
 
 string    : string strpart               { $$ = ap_expr_make(op_Concat, $1, $2, ctx); }
           | strpart                      { $$ = $1; }
+          | T_ERROR                      { YYABORT; }
           ;
 
 strpart   : T_STRING                     { $$ = ap_expr_make(op_String, $1, NULL, ctx); }
@@ -203,8 +209,9 @@ strfunccall : T_ID '(' word ')' { $$ = ap_expr_str_func_make($1, $3, ctx); }
 
 %%
 
-void yyerror(ap_expr_parse_ctx *ctx, char *s)
+void yyerror(ap_expr_parse_ctx_t *ctx, const char *s)
 {
-    ctx->error = s;
+    /* s is allocated on the stack */
+    ctx->error = apr_pstrdup(ctx->ptemp, s);
 }