diff --git a/lib/read.c b/lib/read.c index 1bd0a75..f2b9afe 100644 --- a/lib/read.c +++ b/lib/read.c @@ -1042,7 +1042,7 @@ static HCL_INLINE int is_at_block_beginning (hcl_t* hcl) return !rstl || (LIST_FLAG_GET_CONCODE(rstl->flagv) == HCL_CONCODE_BLOCK && (hcl->c->feed.rd.flagv & AT_BEGINNING)); } -static int forge_auto_xlist_if_at_block_beginning (hcl_t* hcl, hcl_frd_t* frd) +static int auto_forge_xlist_if_at_block_beginning (hcl_t* hcl, hcl_frd_t* frd) { if (is_at_block_beginning(hcl)) { @@ -1174,14 +1174,14 @@ static int feed_process_token (hcl_t* hcl) /* [] is a data list. so let's treat it like other literal * expressions(e.g. 1, "abc"). when it's placed at the block beginning, * create the outer XLIST. */ - if (forge_auto_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops; + if (auto_forge_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops; frd->flagv = DATA_LIST; LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_ARRAY); goto start_list; case HCL_TOK_BAPAREN: /* #[ */ - if (forge_auto_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops; + if (auto_forge_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops; frd->flagv = DATA_LIST; LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_BYTEARRAY); @@ -1194,13 +1194,13 @@ static int feed_process_token (hcl_t* hcl) goto start_list; case HCL_TOK_DLPAREN: /* #{ */ - if (forge_auto_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops; + if (auto_forge_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops; frd->flagv = DATA_LIST; LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_DIC); goto start_list; case HCL_TOK_QLPAREN: /* #( */ - if (forge_auto_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops; + if (auto_forge_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops; frd->flagv = DATA_LIST; LIST_FLAG_SET_CONCODE (frd->flagv, HCL_CONCODE_QLIST); goto start_list; @@ -1529,7 +1529,7 @@ static int feed_process_token (hcl_t* hcl) frd->flagv &= ~AT_BEGINNING; } #else - if (forge_auto_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops; + if (auto_forge_xlist_if_at_block_beginning(hcl, frd) <= -1) goto oops; #endif break; } diff --git a/t/do-01.err b/t/do-01.err index 5a75315..ec5bd43 100644 --- a/t/do-01.err +++ b/t/do-01.err @@ -1,3 +1,3 @@ ## if `do` is not enclosed in `( )`, variable declaration is prohibited -(do | k | (set k 10)) +do { | k | set k 10 }; do | k | {set k 10;}; ##ERROR: syntax error - variable declaration disallowed diff --git a/t/insta-01.hcl b/t/insta-01.hcl index c05e980..1274916 100644 --- a/t/insta-01.hcl +++ b/t/insta-01.hcl @@ -35,19 +35,17 @@ else { printf "OK %d\n" a; }; set b (B:newInstance 2 3 4); set a (b:get-a); -(if (/= a 4) (printf "ERROR: a must be 4\n") - else (printf "OK %d\n" a)) +if (/= a 4) {printf "ERROR: a must be 4\n" } +else { printf "OK %d\n" a }; set a (b:get-b); -(if (/= a 6) (printf "ERROR: a must be 6\n") - else (printf "OK %d\n" a)) +if (/= a 6) { printf "ERROR: a must be 6\n" } +else { printf "OK %d\n" a }; set a (b:get-c); -(if (/= a 8) (printf "ERROR: a must be 8\n") - else (printf "OK %d\n" a)) +if (/= a 8) { printf "ERROR: a must be 8\n" } +else {printf "OK %d\n" a }; set a (b:sum); -(if (/= a 27) (printf "ERROR: a must be 27\n") - else (printf "OK %d\n" a)) - - +if (/= a 27) { printf "ERROR: a must be 27\n" } +else { printf "OK %d\n" a }; diff --git a/t/ret-01.hcl b/t/ret-01.hcl index b526470..18eeef1 100644 --- a/t/ret-01.hcl +++ b/t/ret-01.hcl @@ -16,7 +16,7 @@ defun test-non-local-ret-1(k) { set a (test-non-local-ret-1 20); if (/= a 28) { printf "ERROR: a must be 28\n" } -else { (printf "OK %d\n" a) }; +else { printf "OK %d\n" a }; set a (test-non-local-ret-1 21); if (/= a 41) { printf "ERROR: a must be 41\n" } diff --git a/t/retvar-01.hcl b/t/retvar-01.hcl index 94b1e1d..03d4a77 100644 --- a/t/retvar-01.hcl +++ b/t/retvar-01.hcl @@ -1,5 +1,5 @@ -((fun() { +(fun() { ## test return variables | v1 v2 v3 i a b c d | @@ -13,17 +13,17 @@ set i (* i 10); }; - (set-r v1 v2 v3 (ff 10 20)) - (if (/= v1 130) (printf "ERROR: v1 must be 130\n")) - (if (/= v2 260) (printf "ERROR: v2 must be 260\n")) - (if (/= v3 1099) (printf "ERROR: v3 must be 1099\n")) - (printf "OK v1=%d v2=%d v3=%d\n" v1 v2 v3) + set-r v1 v2 v3 (ff 10 20); + if (/= v1 130) { printf "ERROR: v1 must be 130\n" }; + if (/= v2 260) { printf "ERROR: v2 must be 260\n" }; + if (/= v3 1099) { printf "ERROR: v3 must be 1099\n" }; + printf "OK v1=%d v2=%d v3=%d\n" v1 v2 v3; - (set-r v1 v2 (ff 1 2)) ## using 2 return variables only. not assigning to v3 - (if (/= v1 1003) (printf "ERROR: v1 must be 1003\n")) - (if (/= v2 2006) (printf "ERROR: v2 must be 2006\n")) - (if (/= v3 1099) (printf "ERROR: v3 must be 1099\n")) - (printf "OK v1=%d v2=%d v3=%d\n" v1 v2 v3) + set-r v1 v2 (ff 1 2); ## using 2 return variables only. not assigning to v3 + if (/= v1 1003) { printf "ERROR: v1 must be 1003\n" }; + if (/= v2 2006) { printf "ERROR: v2 must be 2006\n" }; + if (/= v3 1099) { printf "ERROR: v3 must be 1099\n" }; + printf "OK v1=%d v2=%d v3=%d\n" v1 v2 v3; @@ -35,23 +35,23 @@ set X2 888; defun ::: get ( ::: x y) { - (set x X1) - (set y X2) + set x X1; + set y X2; }; defun ::: get2 (inc ::: x y) { - (set x (+ X1 inc)) - (set y (+ X2 inc)) + set x (+ X1 inc); + set y (+ X2 inc); }; }; - (set-r a b (B:get)) - (set-r c d (B:get2 -100)) + set-r a b (B:get); + set-r c d (B:get2 -100); - (if (/= a 999) (printf "ERROR: a must be 999\n")) - (if (/= b 888) (printf "ERROR: b must be 888\n")) - (if (/= c 899) (printf "ERROR: c must be 899\n")) - (if (/= d 788) (printf "ERROR: d must be 788\n")) + if (/= a 999) { printf "ERROR: a must be 999\n" }; + if (/= b 888) { printf "ERROR: b must be 888\n" }; + if (/= c 899) { printf "ERROR: c must be 899\n" }; + if (/= d 788) { printf "ERROR: d must be 788\n" }; printf "OK a=%d b=%d c=%d d=%d\n" a b c d; -})); +}); diff --git a/t/va-01.hcl b/t/va-01.hcl index 298f20f..85d6539 100644 --- a/t/va-01.hcl +++ b/t/va-01.hcl @@ -1,41 +1,41 @@ defun fn-y (t1 t2 va-ctx) { | i | - set i 0; + i := 0; while (< i (va-count va-ctx)) { - (printf "fn-y=>Y-VA[%d]=>[%d]\n" i (va-get i va-ctx)) - (set i (+ i 1)) + printf "fn-y=>Y-VA[%d]=>[%d]\n" i (va-get i va-ctx); + i := (+ i 1); }; }; defun x(a b ... ::: x y z) { |i| - (set x (va-count)) - (set y (* a b)) - (set z (+ a b)) + set x (va-count); + set y (* a b); + set z (+ a b); set i 0; while (< i (va-count)) { - (printf "VA[%d]=>[%d]\n" i (va-get i)) - (set i (+ i 1)) + printf "VA[%d]=>[%d]\n" i (va-get i); + set i (+ i 1); }; fn-y "hello" "world" (va-context); - (return) + return; }; -(set t (x 10 20 30)) -(if (/= t 1) (printf "ERROR: t is not 1\n") - else (printf "OK: %d\n" t)) +set t (x 10 20 30); +if (/= t 1) { printf "ERROR: t is not 1\n" } +else { printf "OK: %d\n" t }; -(set t (set-r a b c (x 10 20 30 40 50))) -(if (/= t 3) (printf "ERROR: t is not 3\n") - else (printf "OK: %d\n" t)) -(if (/= a 3) (printf "ERROR: a is not 3\n") - else (printf "OK: %d\n" a)) -(if (/= b 200) (printf "ERROR: b is not 200\n") - else (printf "OK: %d\n" b)) -(if (/= c 30) (printf "ERROR: c is not 30\n") - else (printf "OK: %d\n" c)) +set t (set-r a b c (x 10 20 30 40 50)); +if (/= t 3) { printf "ERROR: t is not 3\n" } +else { printf "OK: %d\n" t }; +if (/= a 3) { printf "ERROR: a is not 3\n" } +else { printf "OK: %d\n" a }; +if (/= b 200) { printf "ERROR: b is not 200\n" } +else { printf "OK: %d\n" b }; +if (/= c 30) { printf "ERROR: c is not 30\n" } +else { printf "OK: %d\n" c };