updated parse.c with new way to setting error information partially

This commit is contained in:
hyung-hwan 2020-01-03 07:35:59 +00:00
parent f4650746bb
commit c64364ecb1
6 changed files with 152 additions and 90 deletions

View File

@ -60,16 +60,16 @@ const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum)
HAWK_T("timed out"),
HAWK_T("in bad state"),
HAWK_T("cannot open '${0}'"),
HAWK_T("cannot read '${0}'"),
HAWK_T("cannot write '${0}'"),
HAWK_T("cannot close '${0}'"),
HAWK_T("cannot open"),
HAWK_T("cannot read"),
HAWK_T("cannot write"),
HAWK_T("cannot close"),
HAWK_T("block nested too deeply"),
HAWK_T("expression nested too deeply"),
HAWK_T("invalid character '${0}'"),
HAWK_T("invalid digit '${0}'"),
HAWK_T("invalid character"),
HAWK_T("invalid digit"),
HAWK_T("unexpected end of input"),
HAWK_T("comment not closed properly"),
@ -86,7 +86,7 @@ const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum)
HAWK_T("statement not ending with a semicolon"),
HAWK_T("keyword 'in' expected in place of '${0}'"),
HAWK_T("right-hand side of 'in' not a variable"),
HAWK_T("expression not recognized around '${0}'"),
HAWK_T("expression not recognized around"),
HAWK_T("keyword 'function' expected in place of '${0}'"),
HAWK_T("keyword 'while' expected in place of '${0}'"),

View File

@ -790,16 +790,16 @@ enum hawk_errnum_t
HAWK_ESTATE, /**< in bad state */
/* mostly parse errors */
HAWK_EOPEN, /**< cannot open '${0}' */
HAWK_EREAD, /**< cannot read '${0}' */
HAWK_EWRITE, /**< cannot write '${0}' */
HAWK_ECLOSE, /**< cannot close '${0}' */
HAWK_EOPEN, /**< cannot open */
HAWK_EREAD, /**< cannot read */
HAWK_EWRITE, /**< cannot write */
HAWK_ECLOSE, /**< cannot close */
HAWK_EBLKNST, /**< block nested too deeply */
HAWK_EEXPRNST,/**< expression nested too deeply */
HAWK_ELXCHR, /**< invalid character '${0}' */
HAWK_ELXDIG, /**< invalid digit '${0}' */
HAWK_ELXCHR, /**< invalid character */
HAWK_ELXDIG, /**< invalid digit */
HAWK_EEOF, /**< unexpected end of source */
HAWK_ECMTNC, /**< comment not closed properly */
@ -816,7 +816,7 @@ enum hawk_errnum_t
HAWK_ESTMEND, /**< statement not ending with a semicolon */
HAWK_EKWIN, /**< keyword 'in' expected in place of '${0}' */
HAWK_ENOTVAR, /**< right-hand side of 'in' not a variable */
HAWK_EEXPRNR, /**< expression not recognized around '${0}' */
HAWK_EEXPRNR, /**< expression not recognized */
HAWK_EKWFNC, /**< keyword 'function' expected in place of '${0}' */
HAWK_EKWWHL, /**< keyword 'while' expected in place of '${0}' */

View File

@ -1599,7 +1599,7 @@ HAWK_EXPORT void hawk_geterrinf (
* error message.
*/
#if defined(HAWK_HAVE_INLINE)
static HAWK_INLINE void hawk_seterrnum (hawk_t* hawk, hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_getgem(hawk), errloc, errnum); }
static HAWK_INLINE void hawk_seterrnum (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_getgem(hawk), errloc, errnum); }
#else
#define hawk_seterrnum(hawk, errloc, errnum) hawk_gem_seterrnum(hawk_getgem(hawk), errloc, errnum)
#endif
@ -2444,7 +2444,7 @@ HAWK_EXPORT void hawk_rtx_geterror (
);
#if defined(HAWK_HAVE_INLINE)
static HAWK_INLINE void hawk_rtx_seterrnum (hawk_rtx_t* rtx, hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_rtx_getgem(rtx), errloc, errnum); }
static HAWK_INLINE void hawk_rtx_seterrnum (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_rtx_getgem(rtx), errloc, errnum); }
#else
#define hawk_rtx_seterrnum(rtx, errloc, errnum) hawk_gem_seterrnum(hawk_rtx_getgem(rtx), errloc, errnum)
#endif

View File

@ -413,12 +413,6 @@ static global_t gtab[] =
#define SETERR_TOK(awk,code) \
hawk_seterror (awk, code, HAWK_OOECS_OOCS((awk)->tok.name), &(awk)->tok.loc)
#define SETERR_COD(awk,code) \
hawk_seterror (awk, code, HAWK_NULL, HAWK_NULL)
#define SETERR_LOC(awk,code,loc) \
hawk_seterror (awk, code, HAWK_NULL, loc)
#define SETERR_ARG_LOC(awk,code,ep,el,loc) \
do { \
hawk_oocs_t __ea; \
@ -701,7 +695,7 @@ int hawk_parse (hawk_t* awk, hawk_sio_cbs_t* sio)
if (!sio || !sio->in)
{
SETERR_COD (awk, HAWK_EINVAL);
hawk_seterrnum (awk, HAWK_NULL, HAWK_EINVAL);
return -1;
}
@ -937,7 +931,7 @@ static int parse_progunit (hawk_t* awk)
if (awk->opt.depth.s.incl > 0 &&
awk->parse.depth.incl >= awk->opt.depth.s.incl)
{
SETERR_LOC (awk, HAWK_EINCLTD, &awk->ptok.loc);
hawk_seterrnum (awk, &awk->ptok.loc, HAWK_EINCLTD);
return -1;
}
@ -946,7 +940,7 @@ static int parse_progunit (hawk_t* awk)
if (!MATCH(awk, TOK_STR))
{
SETERR_LOC (awk, HAWK_EINCLSTR, &awk->ptok.loc);
hawk_seterrnum (awk, &awk->ptok.loc, HAWK_EINCLSTR);
return -1;
}
@ -1046,7 +1040,7 @@ static int parse_progunit (hawk_t* awk)
{
/* when HAWK_NEWLINE is set,
* BEGIN and { should be located on the same line */
SETERR_LOC (awk, HAWK_EBLKBEG, &awk->ptok.loc);
hawk_seterrnum (awk, &awk->ptok.loc, HAWK_EBLKBEG);
return -1;
}
@ -1077,7 +1071,7 @@ static int parse_progunit (hawk_t* awk)
{
/* when HAWK_NEWLINE is set,
* END and { should be located on the same line */
SETERR_LOC (awk, HAWK_EBLKEND, &awk->ptok.loc);
hawk_seterrnum (awk, &awk->ptok.loc, HAWK_EBLKEND);
return -1;
}
@ -1188,7 +1182,7 @@ static int parse_progunit (hawk_t* awk)
/* blockless pattern requires HAWK_RIO
* to be ON because the implicit block is
* "print $0" */
SETERR_LOC (awk, HAWK_ENOSUP, &ploc);
hawk_seterrnum (awk, &ploc, HAWK_ENOSUP);
return -1;
}
}
@ -1343,7 +1337,7 @@ static hawk_nde_t* parse_function (hawk_t* awk)
/* push the parameter to the parameter list */
if (HAWK_ARR_SIZE(awk->parse.params) >= HAWK_MAX_PARAMS)
{
SETERR_LOC (awk, HAWK_EPARTM, &awk->tok.loc);
hawk_seterrnum (awk, &awk->tok.loc, HAWK_EPARTM);
goto oops;
}
@ -1575,7 +1569,7 @@ static hawk_nde_t* parse_block (hawk_t* awk, const hawk_loc_t* xloc, int istop)
if (awk->opt.depth.s.incl > 0 &&
awk->parse.depth.incl >= awk->opt.depth.s.incl)
{
SETERR_LOC (awk, HAWK_EINCLTD, &awk->ptok.loc);
hawk_seterrnum (awk, &awk->ptok.loc, HAWK_EINCLTD);
return HAWK_NULL;
}
@ -1584,7 +1578,7 @@ static hawk_nde_t* parse_block (hawk_t* awk, const hawk_loc_t* xloc, int istop)
if (!MATCH(awk,TOK_STR))
{
SETERR_LOC (awk, HAWK_EINCLSTR, &awk->ptok.loc);
hawk_seterrnum (awk, &awk->ptok.loc, HAWK_EINCLSTR);
return HAWK_NULL;
}
@ -1626,7 +1620,7 @@ static hawk_nde_t* parse_block (hawk_t* awk, const hawk_loc_t* xloc, int istop)
awk->parse.lcls, nlcls,
HAWK_ARR_SIZE(awk->parse.lcls) - nlcls);
if (head != HAWK_NULL) hawk_clrpt (awk, head);
SETERR_LOC (awk, HAWK_EEOF, &awk->tok.loc);
hawk_seterrnum (awk, &awk->tok.loc, HAWK_EEOF);
return HAWK_NULL;
}
@ -1652,7 +1646,7 @@ static hawk_nde_t* parse_block (hawk_t* awk, const hawk_loc_t* xloc, int istop)
if (awk->opt.depth.s.incl > 0 &&
awk->parse.depth.incl >= awk->opt.depth.s.incl)
{
SETERR_LOC (awk, HAWK_EINCLTD, &awk->ptok.loc);
hawk_seterrnum (awk, &awk->ptok.loc, HAWK_EINCLTD);
return HAWK_NULL;
}
@ -1661,7 +1655,7 @@ static hawk_nde_t* parse_block (hawk_t* awk, const hawk_loc_t* xloc, int istop)
if (!MATCH(awk,TOK_STR))
{
SETERR_LOC (awk, HAWK_EINCLSTR, &awk->ptok.loc);
hawk_seterrnum (awk, &awk->ptok.loc, HAWK_EINCLSTR);
return HAWK_NULL;
}
@ -1753,7 +1747,7 @@ static hawk_nde_t* parse_block_dc (hawk_t* awk, const hawk_loc_t* xloc, int isto
if (awk->opt.depth.s.block_parse > 0 &&
awk->parse.depth.block >= awk->opt.depth.s.block_parse)
{
SETERR_LOC (awk, HAWK_EBLKNST, xloc);
hawk_seterrnum (awk, xloc, HAWK_EBLKNST);
return HAWK_NULL;
}
@ -1895,7 +1889,7 @@ static int add_global (hawk_t* awk, const hawk_oocs_t* name, hawk_loc_t* xloc, i
ngbls = HAWK_ARR_SIZE(awk->parse.gbls);
if (ngbls >= HAWK_MAX_GBLS)
{
SETERR_LOC (awk, HAWK_EGBLTM, xloc);
hawk_seterrnum (awk, xloc, HAWK_EGBLTM);
return -1;
}
@ -1926,7 +1920,7 @@ int hawk_addgblwithbcstr (hawk_t* awk, const hawk_bch_t* name)
if (awk->tree.ngbls > awk->tree.ngbls_base)
{
/* this function is not allowed after hawk_parse is called */
SETERR_COD (awk, HAWK_EPERM);
hawk_seterrnum (awk, HAWK_NULL, HAWK_EPERM);
return -1;
}
@ -1934,7 +1928,7 @@ int hawk_addgblwithbcstr (hawk_t* awk, const hawk_bch_t* name)
ncs.len = hawk_count_bcstr(name);;
if (ncs.len <= 0)
{
SETERR_COD (awk, HAWK_EINVAL);
hawk_seterrnum (awk, HAWK_NULL, HAWK_EINVAL);
return -1;
}
@ -1965,7 +1959,7 @@ int hawk_addgblwithucstr (hawk_t* awk, const hawk_uch_t* name)
if (awk->tree.ngbls > awk->tree.ngbls_base)
{
/* this function is not allowed after hawk_parse is called */
SETERR_COD (awk, HAWK_EPERM);
hawk_seterrnum (awk, HAWK_NULL, HAWK_EPERM);
return -1;
}
@ -1973,7 +1967,7 @@ int hawk_addgblwithucstr (hawk_t* awk, const hawk_uch_t* name)
ncs.len = hawk_count_ucstr(name);;
if (ncs.len <= 0)
{
SETERR_COD (awk, HAWK_EINVAL);
hawk_seterrnum (awk, HAWK_NULL, HAWK_EINVAL);
return -1;
}
@ -2172,7 +2166,7 @@ static hawk_t* collect_globals (hawk_t* awk)
{
/* special check if the first name is on the
* same line when HAWK_NEWLINE is on */
SETERR_COD (awk, HAWK_EVARMS);
hawk_seterrnum (awk, HAWK_NULL, HAWK_EVARMS);
return HAWK_NULL;
}
@ -2224,7 +2218,7 @@ static hawk_t* collect_locals (hawk_t* awk, hawk_oow_t nlcls, int istop)
{
/* special check if the first name is on the
* same line when HAWK_NEWLINE is on */
SETERR_COD (awk, HAWK_EVARMS);
hawk_seterrnum (awk, HAWK_NULL, HAWK_EVARMS);
return HAWK_NULL;
}
@ -2679,7 +2673,7 @@ static hawk_nde_t* parse_break (hawk_t* awk, const hawk_loc_t* xloc)
HAWK_ASSERT (awk->ptok.type == TOK_BREAK);
if (awk->parse.depth.loop <= 0)
{
SETERR_LOC (awk, HAWK_EBREAK, xloc);
hawk_seterrnum (awk, xloc, HAWK_EBREAK);
return HAWK_NULL;
}
@ -2703,7 +2697,7 @@ static hawk_nde_t* parse_continue (hawk_t* awk, const hawk_loc_t* xloc)
HAWK_ASSERT (awk->ptok.type == TOK_CONTINUE);
if (awk->parse.depth.loop <= 0)
{
SETERR_LOC (awk, HAWK_ECONTINUE, xloc);
hawk_seterrnum (awk, xloc, HAWK_ECONTINUE);
return HAWK_NULL;
}
@ -2807,12 +2801,12 @@ static hawk_nde_t* parse_next (hawk_t* awk, const hawk_loc_t* xloc)
if (awk->parse.id.block == PARSE_BEGIN_BLOCK)
{
SETERR_LOC (awk, HAWK_ENEXTBEG, xloc);
hawk_seterrnum (awk, xloc, HAWK_ENEXTBEG);
return HAWK_NULL;
}
if (awk->parse.id.block == PARSE_END_BLOCK)
{
SETERR_LOC (awk, HAWK_ENEXTEND, xloc);
hawk_seterrnum (awk, xloc, HAWK_ENEXTEND);
return HAWK_NULL;
}
@ -2835,12 +2829,12 @@ static hawk_nde_t* parse_nextfile (
if (!out && awk->parse.id.block == PARSE_BEGIN_BLOCK)
{
SETERR_LOC (awk, HAWK_ENEXTFBEG, xloc);
hawk_seterrnum (awk, xloc, HAWK_ENEXTFBEG);
return HAWK_NULL;
}
if (!out && awk->parse.id.block == PARSE_END_BLOCK)
{
SETERR_LOC (awk, HAWK_ENEXTFEND, xloc);
hawk_seterrnum (awk, xloc, HAWK_ENEXTFEND);
return HAWK_NULL;
}
@ -2891,7 +2885,7 @@ static hawk_nde_t* parse_delete (hawk_t* awk, const hawk_loc_t* xloc)
if ((type == HAWK_NDE_DELETE && !is_var (var)) ||
(type == HAWK_NDE_RESET && !is_plain_var (var)))
{
SETERR_LOC (awk, HAWK_EBADARG, &dloc);
hawk_seterrnum (awk, &dloc, HAWK_EBADARG);
goto oops;
}
@ -3123,7 +3117,7 @@ static hawk_nde_t* parse_print (hawk_t* awk, const hawk_loc_t* xloc)
if (type == HAWK_NDE_PRINTF && !args)
{
SETERR_LOC (awk, HAWK_ENOARG, xloc);
hawk_seterrnum (awk, xloc, HAWK_ENOARG);
goto oops;
}
@ -3267,7 +3261,7 @@ static hawk_nde_t* parse_statement_nb (
else
{
if (nde != HAWK_NULL) hawk_clrpt (awk, nde);
SETERR_LOC (awk, HAWK_ESTMEND, &awk->ptok.loc);
hawk_seterrnum (awk, &awk->ptok.loc, HAWK_ESTMEND);
return HAWK_NULL;
}
@ -3463,7 +3457,7 @@ static hawk_nde_t* parse_expr (hawk_t* awk, const hawk_loc_t* xloc)
if (!is_var(x) && x->type != HAWK_NDE_POS)
{
hawk_clrpt (awk, x);
SETERR_LOC (awk, HAWK_EASSIGN, xloc);
hawk_seterrnum (awk, xloc, HAWK_EASSIGN);
return HAWK_NULL;
}
@ -3512,7 +3506,7 @@ static hawk_nde_t* parse_expr_withdc (hawk_t* awk, const hawk_loc_t* xloc)
if (awk->opt.depth.s.expr_parse > 0 &&
awk->parse.depth.expr >= awk->opt.depth.s.expr_parse)
{
SETERR_LOC (awk, HAWK_EEXPRNST, xloc);
hawk_seterrnum (awk, xloc, HAWK_EEXPRNST);
return HAWK_NULL;
}
@ -3987,7 +3981,7 @@ static hawk_nde_t* parse_in (hawk_t* awk, const hawk_loc_t* xloc)
if (!is_plain_var(right))
{
SETERR_LOC (awk, HAWK_ENOTVAR, &rloc);
hawk_seterrnum (awk, &rloc, HAWK_ENOTVAR);
goto oops;
}
@ -4193,7 +4187,7 @@ static hawk_nde_t* parse_unary (hawk_t* awk, const hawk_loc_t* xloc)
if (awk->opt.depth.s.expr_parse > 0 &&
awk->parse.depth.expr >= awk->opt.depth.s.expr_parse)
{
SETERR_LOC (awk, HAWK_EEXPRNST, xloc);
hawk_seterrnum (awk, xloc, HAWK_EEXPRNST);
return HAWK_NULL;
}
@ -4339,7 +4333,7 @@ static hawk_nde_t* parse_unary_exp (hawk_t* awk, const hawk_loc_t* xloc)
if (awk->opt.depth.s.expr_parse > 0 &&
awk->parse.depth.expr >= awk->opt.depth.s.expr_parse)
{
SETERR_LOC (awk, HAWK_EEXPRNST, xloc);
hawk_seterrnum (awk, xloc, HAWK_EEXPRNST);
return HAWK_NULL;
}
@ -4400,7 +4394,7 @@ static hawk_nde_t* parse_increment (hawk_t* awk, const hawk_loc_t* xloc)
/* both prefix and postfix increment operator.
* not allowed */
hawk_clrpt (awk, left);
SETERR_LOC (awk, HAWK_EPREPST, xloc);
hawk_seterrnum (awk, xloc, HAWK_EPREPST);
return HAWK_NULL;
}
}
@ -4446,7 +4440,7 @@ static hawk_nde_t* parse_increment (hawk_t* awk, const hawk_loc_t* xloc)
else
{
hawk_clrpt (awk, left);
SETERR_LOC (awk, HAWK_EINCDECOPR, xloc);
hawk_seterrnum (awk, xloc, HAWK_EINCDECOPR);
return HAWK_NULL;
}
}
@ -4897,7 +4891,7 @@ static hawk_nde_t* parse_primary_getline (hawk_t* awk, const hawk_loc_t* xloc)
* getline a()
* getline sys::WNOHANG
*/
SETERR_LOC (awk, HAWK_EBADARG, &ploc);
hawk_seterrnum (awk, &ploc, HAWK_EBADARG);
goto oops;
}
}
@ -4962,6 +4956,9 @@ static hawk_nde_t* parse_primary_nopipe (hawk_t* awk, const hawk_loc_t* xloc)
return parse_primary_getline(awk, xloc);
default:
{
hawk_tok_t* xtok;
/* in the tolerant mode, we treat print and printf
* as a function like getline */
if ((awk->opt.trait & HAWK_TOLERANT) &&
@ -4972,22 +4969,11 @@ static hawk_nde_t* parse_primary_nopipe (hawk_t* awk, const hawk_loc_t* xloc)
}
/* valid expression introducer is expected */
if (MATCH(awk,TOK_NEWLINE))
{
SETERR_ARG_LOC (
awk, HAWK_EEXPRNR,
HAWK_OOECS_PTR(awk->ptok.name),
HAWK_OOECS_LEN(awk->ptok.name),
&awk->ptok.loc
);
}
else
{
SETERR_TOK (awk, HAWK_EEXPRNR);
}
xtok = MATCH(awk,TOK_NEWLINE)? &awk->ptok: &awk->tok;
hawk_seterrfmt (awk, &xtok->loc, HAWK_EEXPRNR, HAWK_T("expression not recognized around '%.*js'"), HAWK_OOECS_LEN(xtok->name), HAWK_OOECS_PTR(xtok->name));
return HAWK_NULL;
}
}
}
static hawk_nde_t* parse_primary (hawk_t* awk, const hawk_loc_t* xloc)
@ -5064,7 +5050,7 @@ static hawk_nde_t* parse_primary (hawk_t* awk, const hawk_loc_t* xloc)
{
/* fucntion a() {}
* print ("ls -laF" | getline a()) */
SETERR_LOC (awk, HAWK_EBADARG, &ploc);
hawk_seterrnum (awk, &ploc, HAWK_EBADARG);
goto oops;
}
}
@ -5193,7 +5179,7 @@ static int dup_ident_and_get_next (hawk_t* awk, const hawk_loc_t* xloc, hawk_ooc
if (nsegs >= max)
{
SETERR_LOC (awk, HAWK_ESEGTM, xloc);
hawk_seterrnum (awk, xloc, HAWK_ESEGTM);
goto oops;
}
}
@ -5760,12 +5746,12 @@ make_node:
if (nargs > call->u.fnc.spec.arg.max)
{
SETERR_LOC (awk, HAWK_EARGTM, xloc);
hawk_seterrnum (awk, xloc, HAWK_EARGTM);
goto oops;
}
else if (nargs < call->u.fnc.spec.arg.min)
{
SETERR_LOC (awk, HAWK_EARGTF, xloc);
hawk_seterrnum (awk, xloc, HAWK_EARGTF);
goto oops;
}
}
@ -5843,8 +5829,7 @@ static int get_number (hawk_t* awk, hawk_tok_t* tok)
if (c == HAWK_T('8') || c == HAWK_T('9'))
{
hawk_ooch_t cc = (hawk_ooch_t)c;
SETERR_ARG_LOC (awk, HAWK_ELXDIG, &cc, 1, &awk->tok.loc);
hawk_seterrfmt (awk, &awk->tok.loc, HAWK_ELXCHR, HAWK_T("invalid digit '%jc'"), (hawk_ooch_t)c);
return -1;
}
@ -5918,7 +5903,7 @@ static int get_string (
if (c == HAWK_OOCI_EOF)
{
SETERR_LOC (awk, HAWK_ESTRNC, &awk->tok.loc);
hawk_seterrnum (awk, &awk->tok.loc, HAWK_ESTRNC);
return -1;
}
@ -6134,7 +6119,7 @@ static int get_single_quoted_string (hawk_t* awk, int byte_only, hawk_tok_t* tok
if (c == HAWK_OOCI_EOF)
{
SETERR_LOC (awk, HAWK_ESTRNC, &awk->tok.loc);
hawk_seterrnum (awk, &awk->tok.loc, HAWK_ESTRNC);
return -1;
}
@ -6250,7 +6235,7 @@ static int skip_comment (hawk_t* awk)
loc.line = awk->sio.inp->line;
loc.colm = awk->sio.inp->colm;
loc.file = awk->sio.inp->path;
SETERR_LOC (awk, HAWK_ECMTNC, &loc);
hawk_seterrnum (awk, &loc, HAWK_ECMTNC);
return -1;
}
@ -6263,7 +6248,7 @@ static int skip_comment (hawk_t* awk)
loc.line = awk->sio.inp->line;
loc.colm = awk->sio.inp->colm;
loc.file = awk->sio.inp->path;
SETERR_LOC (awk, HAWK_ECMTNC, &loc);
hawk_seterrnum (awk, &loc, HAWK_ECMTNC);
return -1;
}
@ -6481,7 +6466,7 @@ retry:
{
/* this extended keyword is empty,
* not followed by a valid word */
SETERR_LOC (awk, HAWK_EXKWEM, &(awk)->tok.loc);
hawk_seterrnum (awk, &(awk)->tok.loc, HAWK_EXKWEM);
return -1;
}
else
@ -6561,14 +6546,11 @@ retry:
/* not handled yet */
if (c == HAWK_T('\0'))
{
SETERR_ARG_LOC (
awk, HAWK_ELXCHR,
HAWK_T("<NUL>"), 5, &tok->loc);
hawk_seterrfmt (awk, &tok->loc, HAWK_ELXCHR, HAWK_T("invalid character '\\0'"));
}
else
{
hawk_ooch_t cc = (hawk_ooch_t)c;
SETERR_ARG_LOC (awk, HAWK_ELXCHR, &cc, 1, &tok->loc);
hawk_seterrfmt (awk, &tok->loc, HAWK_ELXCHR, HAWK_T("invalid character '%jc'"), (hawk_ooch_t)c);
}
return -1;
}

View File

@ -1525,7 +1525,7 @@ static hawk_ooi_t sf_out (hawk_t* awk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg,
const hawk_ooch_t* bem = hawk_backuperrmsg(awk);
ioname = xtn->s.out.x->u.file.path;
if (!ioname) ioname = sio_std_names[HAWK_SIO_STDOUT].ptr;
hawk_seterrfmt (awk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to write to %js - %js"), ioname, bem);
hawk_seterrfmt (awk, HAWK_NULL, HAWK_EWRITE, HAWK_T("unable to write to %js - %js"), ioname, bem);
}
return n;
}

80
hawk/t/test.txt Normal file
View File

@ -0,0 +1,80 @@
#### TODO: create test cases using the following data
BEGIN { @local abc; abc(); }'
HAWK_ENOTFUN -> ERROR: CODE 97 LINE 1 COLUMN 21 - non-function value in abc
BEGIN { @local x; abc(); }
HAWK_EFUNNF -> ERROR: CODE 96 LINE 1 COLUMN 19 - function 'abc' not found
hawk --implicit=off 'BEGIN { @local x; abc(); }'
HAWK_EFUNNF -> ERROR: CODE 96 LINE 1 COLUMN 19 - function 'abc' not defined ===> same as the above. but it's a parse-time error.
BEGIN { @local x; x=sys::getpid(); delete x;}
HAWK_ENOTDEL -> ERROR: CODE 98 LINE 1 COLUMN 43 - 'x' not deletable
hawk --flexmap=off 'BEGIN { ARGV = 30; }'
HAWK_ENMAPTOSCALAR -> ERROR: CODE 110 LINE 1 COLUMN 10 - not allowed to change a map 'ARGV' to a scalar
hawk --flexmap=off 'BEGIN { @local x; x = 10; x[1] = "hello"; }'
HAWK_ESCALARTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 28 - not allowed to change a scalar 'x' to a map
hawk --flexmap=off 'BEGIN { @local x, y; x[1]=20; ARGC = x; }'
HAWK_ESCALARTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 32 - not allowed to achange a scalar 'ARGC' to a map
hawk --flexmap=off 'BEGIN { ARGC[1] = "hello"; }'
HAWK_ESCALARTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 10 - not allowed to change a scalar 'ARGC' to a map
hawk --flexmap=off 'BEGIN { @local x, y; x[1]=20; CONVFMT = x; }'
HAWK_ESCALARTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 32 - not allowed to change a scalar 'CONVFMT' to a map
hawk --flexmap=on 'BEGIN { @local x, y; x[1]=20; CONVFMT = x; }'
HAWK_ESCALARTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 32 - not allowed to change a scalar 'CONVFMT' to a map
$ hawk --flexmap=off 'BEGIN { @local x, y; x[1] = 10; y[1] = 20; x = y; }'
HAWK_EMAPTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 45 - not allowed to change a map 'x' to another map => x is a local variable
$ hawk --flexmap=off 'BEGIN { @local y; x[1] = 10; y[1] = 20; x = y; }'
HAWK_EMAPTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 42 - jnot allowed to change a map 'x' to another map => x is a global variable
$ hawk --flexmap=off 'function abc(x) { @local j; j[1] = 20; x = j; } BEGIN { @local q; q[1]=20; abc(q); }'
HAWK_EMAPTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 40 - not allowed to change a map 'x' to another map => x is an argument
$ hawk --flexmap=off 'function abc(x) { x = 20; } BEGIN { @local q; q[1]=20; abc(q); }'
HAWK_EMAPTOSCALAR -> ERROR: CODE 107 LINE 1 COLUMN 19 - not allowed to change a map 'x' to a scalar
$ hawk --flexmap=off 'BEGIN { @local y; x[1] = 10; x = 20; }'
HAWK_EMAPTOSCALAR -> ERROR: CODE 107 LINE 1 COLUMN 32 - not allowed to change a map 'x' to a scalar
$ hawk --flexmap=off 'BEGIN { x[1] = 10; x = 20; }'
HAWK_EMAPTOSCALAR -> ERROR: CODE 107 LINE 1 COLUMN 22 - not allowed to change a map 'x' to a scalar
$ hawk --flexmap=off 'BEGIN { x[1] = 10; jx=x; }'
HAWK_EMAPTOMAP -> ERROR: CODE 106 LINE 1 COLUMN 22 - not allowed to assign a map to a variable 'jx'
$ hawk --flexmap=off 'BEGIN { @local x, jx; x[1] = 10; jx=x; }'
HAWK_EMAPTOMAP -> ERROR: CODE 106 LINE 1 COLUMN 36 - not allowed to assign a map to a variable 'jx'
$ hawk --flexmap=off 'function abc(jx) { @local x; x[1]= 20; jx = x; } BEGIN { abc(10); }'
HAWK_EMAPTOMAP -> ERROR: CODE 106 LINE 1 COLUMN 40 - not allowed to assign a map to a variable 'jx'
$ hawk 'BEGIN { print 0192; }'
HAWK_ELXDIG -> ERROR: CODE 32 LINE 1 COLUMN 15 - invalid digit '9'
$ hawk 'BEGIN { +
> }'
HAWK_EEXPRNR -> ERROR: CODE 49 LINE 1 COLUMN 9 - expression not recognized around '+'