changed the unary bitwise negation operator to a single tilde which overlaps with the regex match operator

This commit is contained in:
hyung-hwan 2020-03-04 14:10:35 +00:00
parent 04eb425326
commit 5438c8129c
3 changed files with 27 additions and 21 deletions

View File

@ -183,8 +183,7 @@ static void unset_intr_run (void)
#endif
}
static qse_htb_walk_t print_awk_value (
qse_htb_t* map, qse_htb_pair_t* pair, void* arg)
static qse_htb_walk_t print_awk_value (qse_htb_t* map, qse_htb_pair_t* pair, void* arg)
{
qse_awk_rtx_t* rtx = (qse_awk_rtx_t*)arg;
qse_char_t* str;
@ -848,20 +847,29 @@ static void print_rtxerr (qse_awk_rtx_t* rtx)
);
}
struct add_global_ctx_t
{
qse_awk_t* awk;
int fail;
};
qse_htb_walk_t add_global (qse_htb_t* map, qse_htb_pair_t* pair, void* arg)
{
qse_awk_t* awk = (qse_awk_t*)arg;
struct add_global_ctx_t* ctx = (struct add_global_ctx_t*)arg;
struct gvmv_t* gvmv = (struct gvmv_t*)QSE_HTB_VPTR(pair);
/* the key was inserted to the table with a null at the end
* and the key length was even incremetned for that.
* so i can pass the pointer without other adjustments. */
gvmv->idx = qse_awk_addgbl (awk, QSE_HTB_KPTR(pair));
if (gvmv->idx <= -1) return QSE_HTB_WALK_STOP;
gvmv->idx = qse_awk_addgbl(ctx->awk, QSE_HTB_KPTR(pair));
if (gvmv->idx <= -1)
{
ctx->fail = 1;
return QSE_HTB_WALK_STOP;
}
return QSE_HTB_WALK_FORWARD;
}
static void* xma_alloc (qse_mmgr_t* mmgr, qse_size_t size)
{
return qse_xma_alloc (mmgr->ctx, size);
@ -940,6 +948,7 @@ static int awk_main (int argc, qse_char_t* argv[])
qse_awk_val_t* retv;
int i;
struct arg_t arg;
struct add_global_ctx_t agctx;
int ret = -1;
#if defined(ENABLE_CALLBACK)
@ -1021,16 +1030,16 @@ static int awk_main (int argc, qse_char_t* argv[])
qse_awk_setopt (awk, QSE_AWK_DEPTH_INCLUDE, &tmp);
}
qse_awk_seterrnum (awk, QSE_AWK_ENOERR, QSE_NULL);
qse_htb_walk (arg.gvm, add_global, awk);
if (qse_awk_geterrnum(awk) != QSE_AWK_ENOERR)
agctx.awk = awk;
agctx.fail = 0;
qse_htb_walk (arg.gvm, add_global, &agctx);
if (agctx.fail)
{
print_awkerr (awk);
goto oops;
}
if (qse_awk_parsestd (awk, arg.psin,
((arg.osf == QSE_NULL)? QSE_NULL: &psout)) <= -1)
if (qse_awk_parsestd(awk, arg.psin, ((arg.osf == QSE_NULL)? QSE_NULL: &psout)) <= -1)
{
print_awkerr (awk);
goto oops;

View File

@ -75,7 +75,7 @@ enum tok_t
TOK_LT,
TOK_GE,
TOK_GT,
TOK_MA, /* ~ - match */
TOK_TILDE, /* ~ - match or unary bitwise negation*/
TOK_NM, /* !~ - not match */
TOK_LNOT, /* ! - logical negation */
TOK_PLUS,
@ -91,7 +91,6 @@ enum tok_t
TOK_BOR,
TOK_BXOR, /* ^^ - bitwise-xor */
TOK_BAND,
TOK_BNOT, /* ~~ - used for unary bitwise-not */
TOK_RS,
TOK_LS,
TOK_IN,
@ -3993,7 +3992,7 @@ static qse_awk_nde_t* parse_regex_match (qse_awk_t* awk, const qse_awk_loc_t* xl
{
static binmap_t map[] =
{
{ TOK_MA, QSE_AWK_BINOP_MA },
{ TOK_TILDE, QSE_AWK_BINOP_MA },
{ TOK_NM, QSE_AWK_BINOP_NM },
{ TOK_EOF, 0 },
};
@ -4096,7 +4095,7 @@ static qse_awk_nde_t* parse_concat (qse_awk_t* awk, const qse_awk_loc_t* xloc)
if (MATCH(awk,TOK_LPAREN) || MATCH(awk,TOK_DOLLAR) ||
/* unary operators */
MATCH(awk,TOK_PLUS) || MATCH(awk,TOK_MINUS) ||
MATCH(awk,TOK_LNOT) || MATCH(awk,TOK_BNOT) ||
MATCH(awk,TOK_LNOT) || /*MATCH(awk,TOK_TILDE) ||*/
/* increment operators */
MATCH(awk,TOK_PLUSPLUS) || MATCH(awk,TOK_MINUSMINUS) ||
((awk->opt.trait & QSE_AWK_TOLERANT) &&
@ -4166,7 +4165,7 @@ static qse_awk_nde_t* parse_unary (qse_awk_t* awk, const qse_awk_loc_t* xloc)
opcode = (MATCH(awk,TOK_PLUS))? QSE_AWK_UNROP_PLUS:
(MATCH(awk,TOK_MINUS))? QSE_AWK_UNROP_MINUS:
(MATCH(awk,TOK_LNOT))? QSE_AWK_UNROP_LNOT:
(MATCH(awk,TOK_BNOT))? QSE_AWK_UNROP_BNOT: -1;
(MATCH(awk,TOK_TILDE))? QSE_AWK_UNROP_BNOT: -1;
/*if (opcode <= -1) return parse_increment (awk);*/
if (opcode <= -1) return parse_exponent (awk, xloc);
@ -4313,7 +4312,7 @@ static qse_awk_nde_t* parse_unary_exp (qse_awk_t* awk, const qse_awk_loc_t* xloc
opcode = (MATCH(awk,TOK_PLUS))? QSE_AWK_UNROP_PLUS:
(MATCH(awk,TOK_MINUS))? QSE_AWK_UNROP_MINUS:
(MATCH(awk,TOK_LNOT))? QSE_AWK_UNROP_LNOT:
(MATCH(awk,TOK_BNOT))? QSE_AWK_UNROP_BNOT: -1;
(MATCH(awk,TOK_TILDE))? QSE_AWK_UNROP_BNOT: -1;
if (opcode <= -1) return parse_increment (awk, xloc);
@ -6333,8 +6332,7 @@ static int get_symbols (qse_awk_t* awk, qse_cint_t c, qse_awk_tok_t* tok)
{ QSE_T("%%"), 2, TOK_CONCAT, 0 },
{ QSE_T("%="), 2, TOK_MOD_ASSN, 0 },
{ QSE_T("%"), 1, TOK_MOD, 0 },
{ QSE_T("~~"), 2, TOK_BNOT, 0 },
{ QSE_T("~"), 1, TOK_MA, 0 },
{ QSE_T("~"), 1, TOK_TILDE, 0 },
{ QSE_T("("), 1, TOK_LPAREN, 0 },
{ QSE_T(")"), 1, TOK_RPAREN, 0 },
{ QSE_T("{"), 1, TOK_LBRACE, 0 },

View File

@ -86,8 +86,7 @@ static const qse_char_t* unrop_str[] =
QSE_T("+"),
QSE_T("-"),
QSE_T("!"),
QSE_T("~~"),
QSE_T("`")
QSE_T("~")
};
static const qse_char_t* incop_str[] =