| 2230 | /* Otherwise exp == NULL, we don't need to create new tree. */ |
| 2231 | } |
| 2232 | return tree; |
| 2233 | } |
| 2234 | |
| 2235 | /* This function build the following tree, from regular expression a*: |
| 2236 | * |
| 2237 | | |
| 2238 | a |
| 2239 | */ |
| 2240 | |
| 2241 | static bin_tree_t * |
| 2242 | parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, |
| 2243 | reg_syntax_t syntax, int nest, reg_errcode_t *err) |
| 2244 | { |
| 2245 | re_dfa_t *dfa = (re_dfa_t *) preg->buffer; |
| 2246 | bin_tree_t *tree; |
| 2247 | switch (token->type) |
| 2248 | { |
| 2249 | case CHARACTER: |
| 2250 | tree = create_token_tree (dfa, NULL, NULL, token); |
| 2251 | if (BE (tree == NULL, 0)) |
| 2252 | { |
| 2253 | *err = REG_ESPACE; |
| 2254 | return NULL; |
| 2255 | } |
| 2256 | #ifdef RE_ENABLE_I18N |
| 2257 | if (dfa->mb_cur_max > 1) |
| 2258 | { |
| 2259 | while (!re_string_eoi (regexp) |
| 2260 | && !re_string_first_byte (regexp, re_string_cur_idx (regexp))) |
| 2261 | { |
| 2262 | bin_tree_t *mbc_remain; |
| 2263 | fetch_token (token, regexp, syntax); |
| 2264 | mbc_remain = create_token_tree (dfa, NULL, NULL, token); |
| 2265 | tree = create_tree (dfa, tree, mbc_remain, CONCAT); |
| 2266 | if (BE (mbc_remain == NULL || tree == NULL, 0)) |
| 2267 | { |
| 2268 | *err = REG_ESPACE; |
| 2269 | return NULL; |
| 2270 | } |
| 2271 | } |
| 2272 | } |
| 2273 | #endif |
| 2274 | break; |
| 2275 | case OP_OPEN_SUBEXP: |
| 2276 | tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err); |
| 2277 | if (BE (*err != REG_NOERROR && tree == NULL, 0)) |
| 2278 | return NULL; |
| 2279 | break; |
| 2280 | case OP_OPEN_BRACKET: |
| 2281 | tree = parse_bracket_exp (regexp, dfa, token, syntax, err); |
| 2282 | if (BE (*err != REG_NOERROR && tree == NULL, 0)) |
| 2283 | return NULL; |
| 2284 | break; |
| 2285 | case OP_BACK_REF: |
| 2286 | if (!BE (dfa->completed_bkref_map & (1 << token->opr.idx), 1)) |
| 2287 | { |
| 2288 | *err = REG_ESUBREG; |
| 2289 | return NULL; |
no test coverage detected