1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __AP_EXPR_PRIVATE_H__
18 #define __AP_EXPR_PRIVATE_H__
21 #include "apr_strings.h"
22 #include "apr_tables.h"
30 #define MIN(a,b) (((a)<(b))?(a):(b))
33 #if !APR_HAVE_UNISTD_H
34 #define YY_NO_UNISTD_H
38 /* Avoid some warnings with Visual Studio (likely due to a bug in bison) */
39 #define YYMALLOC malloc
47 /** The operations in a parse tree node */
51 op_Not, op_Or, op_And,
53 op_EQ, op_NE, op_LT, op_LE, op_GT, op_GE, op_IN,
55 op_STR_EQ, op_STR_NE, op_STR_LT, op_STR_LE, op_STR_GT, op_STR_GE,
58 op_Digit, op_Var, op_Bool, op_ListElement,
59 op_Sub, op_Split, op_Join,
62 * call external functions/operators.
63 * The info node contains the function pointer and some function specific
65 * For Binary operators, the Call node links to the Info node and the
66 * Args node, which in turn links to the left and right operand.
67 * For all other variants, the Call node links to the Info node and the
70 op_UnaryOpCall, op_UnaryOpInfo,
71 op_BinaryOpCall, op_BinaryOpInfo, op_BinaryOpArgs,
72 op_StringFuncCall, op_StringFuncInfo,
73 op_ListFuncCall, op_ListFuncInfo
76 /** The basic parse tree node */
78 ap_expr_node_op_e node_op;
79 const void *node_arg1;
80 const void *node_arg2;
83 /** The stack used by scanner and parser */
84 typedef struct ap_expr_parser_stack {
86 char scan_buf[MAX_STRING_LEN];
89 struct ap_expr_parser_stack *next;
90 } ap_expr_parser_stack_t;
92 /** The context used by scanner and parser */
94 /* internal state of the scanner */
99 ap_expr_parser_stack_t *current,
103 /* pools for result and temporary usage */
107 /* The created parse tree */
115 * The function to use to lookup provider functions for variables
118 ap_expr_lookup_fn_t *lookup_fn;
119 } ap_expr_parse_ctx_t;
121 /* flex/bison functions */
122 int ap_expr_yyparse(ap_expr_parse_ctx_t *context);
123 void ap_expr_yyerror(ap_expr_parse_ctx_t *context, const char *err);
124 int ap_expr_yylex_init(void **scanner);
125 int ap_expr_yylex_destroy(void *scanner);
126 void ap_expr_yyset_extra(ap_expr_parse_ctx_t *context, void *scanner);
128 /* create a parse tree node */
129 ap_expr_t *ap_expr_make(ap_expr_node_op_e op, const void *arg1,
130 const void *arg2, ap_expr_parse_ctx_t *ctx);
131 ap_expr_t *ap_expr_concat_make(const void *a1, const void *a2,
132 ap_expr_parse_ctx_t *ctx);
133 ap_expr_t *ap_expr_regex_make(const char *pattern, const ap_expr_t *subst,
134 const char *flags, ap_expr_parse_ctx_t *ctx);
135 /* create parse tree node for the string-returning function 'name' */
136 ap_expr_t *ap_expr_str_func_make(const char *name, const ap_expr_t *arg,
137 ap_expr_parse_ctx_t *ctx);
138 /* create parse tree node for the list-returning function 'name' */
139 ap_expr_t *ap_expr_list_func_make(const char *name, const ap_expr_t *arg,
140 ap_expr_parse_ctx_t *ctx);
141 /* create parse tree node for the variable 'name' */
142 ap_expr_t *ap_expr_var_make(const char *name, ap_expr_parse_ctx_t *ctx);
143 /* create parse tree node for the back reference 'num' */
144 ap_expr_t *ap_expr_backref_make(int num, ap_expr_parse_ctx_t *ctx);
145 /* create parse tree node for the unary operator 'name' */
146 ap_expr_t *ap_expr_unary_op_make(const char *name, const ap_expr_t *arg,
147 ap_expr_parse_ctx_t *ctx);
148 /* create parse tree node for the binary operator 'name' */
149 ap_expr_t *ap_expr_binary_op_make(const char *name, const ap_expr_t *arg1,
150 const ap_expr_t *arg2,
151 ap_expr_parse_ctx_t *ctx);
154 #endif /* __AP_EXPR_PRIVATE_H__ */