changed the superclass marker from '::' to ':'
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hyung-hwan 2024-10-03 22:54:03 +09:00
parent 0dbaa264f7
commit 6896da6870
5 changed files with 56 additions and 14 deletions

View File

@ -2548,7 +2548,7 @@ static int compile_class (hcl_t* hcl, hcl_cnode_t* src)
} }
tmp = HCL_CNODE_CONS_CAR(obj); tmp = HCL_CNODE_CONS_CAR(obj);
if (/*HCL_CNODE_IS_COLON(tmp) || */HCL_CNODE_IS_DBLCOLONS(tmp)) if (HCL_CNODE_IS_COLON(tmp)) /* check for superclass marker */
{ {
hcl_cnode_t* marker; hcl_cnode_t* marker;

View File

@ -893,6 +893,13 @@ static HCL_INLINE int can_colon_list (hcl_t* hcl)
if (rstl->count <= 0) return 0; /* not allowed at the list beginning */ if (rstl->count <= 0) return 0; /* not allowed at the list beginning */
/* mark the state that a colon has appeared in the list */ /* mark the state that a colon has appeared in the list */
if (HCL_CNODE_IS_TYPED(HCL_CNODE_CONS_CAR(rstl->head), HCL_CNODE_CLASS))
{
/* class :superclassame ...
* class name:superclassname ... */
return 2;
}
if (rstl->count == 1) rstl->flagv |= JSON; /* mark that the first key is colon-delimited */ if (rstl->count == 1) rstl->flagv |= JSON; /* mark that the first key is colon-delimited */
else if (!(rstl->flagv & JSON)) else if (!(rstl->flagv & JSON))
{ {
@ -945,7 +952,14 @@ static HCL_INLINE int can_colon_list (hcl_t* hcl)
/* ugly dual use of a colon sign. switch to MLIST if the first element /* ugly dual use of a colon sign. switch to MLIST if the first element
* is delimited by a colon. e.g. (obj:new 10 20 30) */ * is delimited by a colon. e.g. (obj:new 10 20 30) */
tmp = HCL_CNODE_CONS_CAR(rstl->head); tmp = HCL_CNODE_CONS_CAR(rstl->head);
if (!HCL_CNODE_IS_FOR_DATA(tmp)) return 0; if (!HCL_CNODE_IS_FOR_DATA(tmp))
{
/* check if the first element can refer to or represent an object.
* for example, '#[1 2 3]:at 1' is proper message send.
* while 'class:xxx {}' is not a method call. it is unamed class
* that inherits from xxx */
return 0;
}
LIST_FLAG_SET_CONCODE(rstl->flagv, HCL_CONCODE_MLIST); LIST_FLAG_SET_CONCODE(rstl->flagv, HCL_CONCODE_MLIST);
rstl->flagv &= ~JSON; rstl->flagv &= ~JSON;

View File

@ -36,18 +36,18 @@ class super.a [ a ] { ##ERROR: syntax error - invalid class name 'super.a' for '
--- ---
class a :: 20 { ##ERROR: syntax error - invalid superclass name '20' after '::' for 'class' class a: 20 { ##ERROR: syntax error - invalid superclass name '20' after ':' for 'class'
} }
--- ---
class a :: class { ##ERROR: syntax error - invalid superclass name 'class' after '::' for 'class' class a: class { ##ERROR: syntax error - invalid superclass name 'class' after ':' for 'class'
} }
--- ---
class a :: #(1 2) { ##ERROR: syntax error - no valid superclass name after '::' for 'class' class a: #(1 2) { ##ERROR: syntax error - no valid superclass name after ':' for 'class'
} }
--- ---
@ -81,7 +81,7 @@ class B [ x y ] {
}; };
class X :: B [ a b ] { class X: B [ a b ] {
fun(#ci) new(t) { fun(#ci) new(t) {
| a | | a |
set self.a t; set self.a t;
@ -231,3 +231,16 @@ class a {
fun() { ##ERROR: syntax error - unnamed function defined with 'fun' prohibited in class initialziation context fun() { ##ERROR: syntax error - unnamed function defined with 'fun' prohibited in class initialziation context
} }
} }
---
class X10 [ x ] {
fun(#ci) make() { x := 1234; return self; };
fun get-x() { return x };
}
X11 := (class:X10 {
})
class X11 { ##ERROR: exception not handled - "prohibited redefintion of X11"
}

View File

@ -26,7 +26,7 @@ class A [ a b c ] {
fun get-c() { return self.c; }; fun get-c() { return self.c; };
}; };
class B :: A [ d e f ] { class B: A [ d e f ] {
fun(#ci) newInstance(x y z) { fun(#ci) newInstance(x y z) {
super:newInstance (* x 2) (* y 2) (* z 2); super:newInstance (* x 2) (* y 2) (* z 2);

View File

@ -37,6 +37,7 @@ v := (dic.get j 4512);
if (nqv? v 1234) { printf "ERROR: v is not 1234\n" } \ if (nqv? v 1234) { printf "ERROR: v is not 1234\n" } \
else { printf "OK: value is %d\n" v }; else { printf "OK: value is %d\n" v };
## -------------------------------------------------------------- ## --------------------------------------------------------------
class X0 [ a b c d ] { class X0 [ a b c d ] {
@ -175,3 +176,17 @@ else { printf "OK: value is %d\n" v }
v := { X5:t; (X6:t) + 10 } v := { X5:t; (X6:t) + 10 }
if (nqv? v 50) { printf "ERROR: v is not 50 - %d\n" v } \ if (nqv? v 50) { printf "ERROR: v is not 50 - %d\n" v } \
else { printf "OK: value is %d\n" v } else { printf "OK: value is %d\n" v }
## --------------------------------------------------------------
class X10 [ x ] {
fun(#ci) make() { x := 1234; return self; };
fun get-x() { return x };
}
X11 := (class:X10 {
})
v := (X11:make)
v := (v:get-x)
if (== v 1234) { printf "OK: v is %d\n" v } \
else {printf "ERROR: v is %d, not 1234\n" v }