From e3120e20a2115da4211f103e3c96f9e154292e61 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 21 Jan 2024 02:23:19 +0900 Subject: [PATCH] fixed wrong semicolon handling and enhanced eol/semiclon handling --- lib/read.c | 29 ++++++++++++++++++----------- t/Makefile.am | 2 ++ t/Makefile.in | 2 ++ t/feed-02.err | 2 +- t/feed-03.err | 9 +++++++++ t/feed-04.err | 11 +++++++++++ 6 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 t/feed-03.err create mode 100644 t/feed-04.err diff --git a/lib/read.c b/lib/read.c index eed86c1..8306df0 100644 --- a/lib/read.c +++ b/lib/read.c @@ -1283,25 +1283,32 @@ static int feed_process_token (hcl_t* hcl) hcl_rstl_t* rstl; semicolon: - /* the parent list must be inspected instead of the current feed/read status pointed to by frd. */ + /* the parent list(rstl) must be inspected instead of the current + * feed/read status pointed to by frd. */ rstl = hcl->c->r.st; - if (!rstl || !(rstl->flagv & AUTO_FORGED)) - { - #if 0 - hcl_setsynerrbfmt (hcl, HCL_SYNERR_SEMICOLON, TOKEN_LOC(hcl), TOKEN_NAME(hcl), "unexpected semicolon"); - goto oops; - #else - /* allow redundant semicolons without not balanced with preceding expression */ - goto ok; - #endif - } + if (!rstl) goto ok; /* redundant eol/semicolon */ concode = LIST_FLAG_GET_CONCODE(rstl->flagv); + if (!(rstl->flagv & AUTO_FORGED)) + { + if (TOKEN_TYPE(hcl) == HCL_TOK_EOL) goto ok; + if (concode == HCL_CONCODE_BLOCK) goto ok; + + hcl_setsynerr (hcl, HCL_SYNERR_SEMICOLON, TOKEN_LOC(hcl), HCL_NULL); + goto oops; + } + + /* if auto-forged */ +#if 0 +/* TODO: remove this part if the assertion is confirmed true in the #else part... */ if (concode != HCL_CONCODE_XLIST && concode != HCL_CONCODE_MLIST && concode != HCL_CONCODE_ALIST) { hcl_setsynerr (hcl, HCL_SYNERR_UNBALPBB, TOKEN_LOC(hcl), HCL_NULL); goto oops; } +#else + HCL_ASSERT (hcl, concode == HCL_CONCODE_XLIST || concode == HCL_CONCODE_MLIST || concode == HCL_CONCODE_ALIST); +#endif frd->obj = leave_list(hcl, &frd->list_loc, &frd->flagv, &oldflagv); frd->level--; diff --git a/t/Makefile.am b/t/Makefile.am index 75a590f..35f51a3 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -16,6 +16,8 @@ check_ERRORS = \ do-02.err \ feed-01.err \ feed-02.err \ + feed-03.err \ + feed-04.err \ mlist-01.err \ var-01.err \ var-02.err \ diff --git a/t/Makefile.in b/t/Makefile.in index ef0ea0d..bee8873 100644 --- a/t/Makefile.in +++ b/t/Makefile.in @@ -487,6 +487,8 @@ check_ERRORS = \ do-02.err \ feed-01.err \ feed-02.err \ + feed-03.err \ + feed-04.err \ mlist-01.err \ var-01.err \ var-02.err \ diff --git a/t/feed-02.err b/t/feed-02.err index 63bddfc..20f5ca7 100644 --- a/t/feed-02.err +++ b/t/feed-02.err @@ -3,6 +3,6 @@ "hello, world\n" ) -(printf; ##ERROR: synax error - unexpected semicolon +(printf; ##ERROR: syntax error - unexpected semicolon "hello, world\n" ) diff --git a/t/feed-03.err b/t/feed-03.err new file mode 100644 index 0000000..b80eaf3 --- /dev/null +++ b/t/feed-03.err @@ -0,0 +1,9 @@ +## semicolon inside #{} must raise a syntax error + +a := #{ + "k1": + "hello k1\n", + "k2": + "hello k2\n"; ##ERROR: syntax error - unexpected semicolon +}; + diff --git a/t/feed-04.err b/t/feed-04.err new file mode 100644 index 0000000..348825b --- /dev/null +++ b/t/feed-04.err @@ -0,0 +1,11 @@ +{ + ;;; + +(do + (printf "hello\n") + (printf "hello\n") +);; + +k := [10 ; 20 ]; ##ERROR: syntax error - unexpected semicolon + +}