From 75ef3a949a80a1e6fa6527600522582546f7d1b2 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 9 Mar 2020 15:29:31 +0000 Subject: [PATCH] changed the tre parser to treat a backslash as an escaper inside [] --- hawk/lib/hawk-prv.h | 4 ++-- hawk/lib/run.c | 2 +- hawk/lib/tre-parse.c | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/hawk/lib/hawk-prv.h b/hawk/lib/hawk-prv.h index 834af95c..2a5e42ee 100644 --- a/hawk/lib/hawk-prv.h +++ b/hawk/lib/hawk-prv.h @@ -174,8 +174,8 @@ typedef struct hawk_tok_t hawk_tok_t; struct hawk_tok_t { int type; - hawk_ooecs_t* name; - hawk_loc_t loc; + hawk_ooecs_t* name; + hawk_loc_t loc; }; struct hawk_t diff --git a/hawk/lib/run.c b/hawk/lib/run.c index 8011737f..0dec6085 100644 --- a/hawk/lib/run.c +++ b/hawk/lib/run.c @@ -8821,5 +8821,5 @@ hawk_oow_t hawk_rtx_fmttobcstr_ (hawk_rtx_t* rtx, hawk_bch_t* buf, hawk_oow_t bu int hawk_rtx_buildrex (hawk_rtx_t* rtx, const hawk_ooch_t* ptn, hawk_oow_t len, hawk_tre_t** code, hawk_tre_t** icode) { - return hawk_gem_buildrex(hawk_rtx_getgem(rtx), ptn, len, !(hawk_rtx_gethawk(rtx)->opt.trait & HAWK_REXBOUND), code, icode); + return hawk_gem_buildrex(hawk_rtx_getgem(rtx), ptn, len, !(rtx->hawk->opt.trait & HAWK_REXBOUND), code, icode); } diff --git a/hawk/lib/tre-parse.c b/hawk/lib/tre-parse.c index f5a3e4c0..daff4efd 100644 --- a/hawk/lib/tre-parse.c +++ b/hawk/lib/tre-parse.c @@ -277,6 +277,14 @@ tre_parse_bracket_items(tre_parse_ctx_t *ctx, int negate, if (min > max) status = REG_ERANGE; } + /* BACON */ + else if (re + 1 < ctx->re_end && *re == CHAR_BACKSLASH) + { + /* escaped character inside [] */ + min = max = *(re + 1); + re += 2; + } + /* END BACON */ else if (re + 1 < ctx->re_end && *re == CHAR_LBRACKET && *(re + 1) == CHAR_PERIOD) status = REG_ECOLLATE; @@ -308,7 +316,7 @@ tre_parse_bracket_items(tre_parse_ctx_t *ctx, int negate, * or per-context character encoding using hawk_cmgr_t */ /* if (status == REG_OK && TRE_MB_CUR_MAX == 1) */ /* END HAWK */ - if (status == REG_OK) + if (status == REG_OK) { status = tre_expand_ctype(ctx->mem, class, items, &i, &max_i, ctx->cflags); class = (tre_ctype_t)0;