added some code for integrating TRE into awk

This commit is contained in:
2013-04-06 13:39:56 +00:00
parent 75bf46e051
commit bad915cc55
20 changed files with 225 additions and 79 deletions

View File

@ -1690,10 +1690,8 @@ tre_make_trans(qse_mmgr_t* mmgr, tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2,
if (p1->neg_classes != NULL)
{
for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++);
trans->neg_classes =
xmalloc(mmgr,sizeof(*trans->neg_classes) * (i + 1));
if (trans->neg_classes == NULL)
return REG_ESPACE;
trans->neg_classes = xmalloc(mmgr,sizeof(*trans->neg_classes) * (i + 1));
if (trans->neg_classes == NULL) return REG_ESPACE;
for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++)
trans->neg_classes[i] = p1->neg_classes[i];
trans->neg_classes[i] = (tre_ctype_t)0;

View File

@ -400,7 +400,7 @@ retry:
/* Go to the next character in the input string. */
empty_br_match = 0;
trans_i = state;
if (trans_i->state && trans_i->assertions & ASSERT_BACKREF)
if (trans_i->state && (trans_i->assertions & ASSERT_BACKREF))
{
/* This is a back reference state. All transitions leaving from
this state have the same back reference "assertion". Instead
@ -593,8 +593,7 @@ backtrack:
DPRINT((" backtracking\n"));
if (stack->item.state->assertions && ASSERT_BACKREF)
{
DPRINT((" states_seen[%d] = 0\n",
stack->item.state_id));
DPRINT((" states_seen[%d] = 0\n", stack->item.state_id));
states_seen[stack->item.state_id] = 0;
}

View File

@ -1174,14 +1174,16 @@ parse_star:
goto parse_star;
}
}
else break;
break;
/* END QSE */
case CHAR_LBRACE:
/* "{" is literal without REG_EXTENDED */
if (!(ctx->cflags & REG_EXTENDED))
break;
if (!(ctx->cflags & REG_EXTENDED)) break;
/* QSE */
if (ctx->cflags & REG_NOBOUND) break;
/* END QSE */
parse_brace:
DPRINT(("tre_parse: bound: '%.*" STRF "'\n",
@ -1194,6 +1196,7 @@ parse_brace:
STACK_PUSHX(stack, int, PARSE_POSTFIX);
break;
}
break;
case PARSE_ATOM:
@ -1686,7 +1689,10 @@ parse_literal:
|| *ctx->re == CHAR_STAR
|| (ctx->cflags & REG_EXTENDED
&& (*ctx->re == CHAR_PIPE
|| *ctx->re == CHAR_LBRACE
/* QSE */
/*|| *ctx->re == CHAR_LBRACE*/
|| (*ctx->re == CHAR_LBRACE && !(ctx->cflags & REG_NOBOUND))
/* END QSE */
|| *ctx->re == CHAR_PLUS
|| *ctx->re == CHAR_QUESTIONMARK))
/* Test for "\)" in BRE mode. */

View File

@ -202,7 +202,7 @@ static int tre_match(
}
/* Dispatch to the appropriate matcher. */
if (tnfa->have_backrefs || eflags & REG_BACKTRACKING_MATCHER)
if (tnfa->have_backrefs || (eflags & REG_BACKTRACKING_MATCHER))
{
/* The regex has back references, use the backtracking matcher. */
if (type == STR_USER)

View File

@ -208,6 +208,7 @@ typedef qse_cint_t tre_cint_t;
#define REG_LITERAL QSE_TRE_LITERAL
#define REG_RIGHT_ASSOC QSE_TRE_RIGHTASSOC
#define REG_UNGREEDY QSE_TRE_UNGREEDY
#define REG_NOBOUND QSE_TRE_NOBOUND
#define REG_NONSTDEXT QSE_TRE_NONSTDEXT
/* POSIX tre_regexec() flags. */