diff --git a/clyx-go/clyx.go b/clyx-go/clyx.go index 85b6c00..04f047b 100644 --- a/clyx-go/clyx.go +++ b/clyx-go/clyx.go @@ -268,7 +268,11 @@ func (c *Clyx) popCallerToken() any { } } if stream == nil { - stream = &c.tokens + if len(c.tokenStreams) == 0 { + stream = &c.tokens + } else { + return nil + } } if len(*stream) == 0 { return nil } t := (*stream)[0] @@ -292,15 +296,17 @@ func (c *Clyx) cmdDefw() { break } } - if stream == nil { + if stream == nil && len(c.tokenStreams) == 0 { stream = &c.tokens } var val any - if len(*stream) > 0 { + if stream != nil && len(*stream) > 0 { t0 := (*stream)[0] isQForm := false if s, ok := t0.(string); ok && s == "[" { isQForm = true } else if _, ok := t0.([]any); ok { isQForm = true } - if isQForm { val = c.popCallerToken() } + if isQForm { + val = c.popCallerToken() + } } if val == nil { val = c.pop() } if s, ok := val.(string); ok { diff --git a/clyx-python/clyx/clyx.py b/clyx-python/clyx/clyx.py index a8df406..81d32df 100755 --- a/clyx-python/clyx/clyx.py +++ b/clyx-python/clyx/clyx.py @@ -108,7 +108,10 @@ class Clyx: t = stream break if t is None: - t = self._tokens + if not self._token_streams: + t = self._tokens + else: + return None if not t: return None val = t.pop(0) if val == '[': return self._parse_qform(t) @@ -120,7 +123,7 @@ class Clyx: if stream: t = stream break - if t is None: + if t is None and not self._token_streams: t = self._tokens val = self._pop_caller_token() if (t and (t[0] == '[' or isinstance(t[0], list))) else self._stack.pop() if isinstance(val, str): val = self._norm_token(val) diff --git a/test.clx b/test.clx index 0b2d7ae..0937a13 100644 --- a/test.clx +++ b/test.clx @@ -21,6 +21,7 @@ _start [ 0 if [ " if false FAIL" ] [ " if false PASS" ] puts cr # Test if false 10 20 [ 5 - ] dip [] cons cons [ 5 20 ] streq if [ " dip PASS" puts cr ] [ " dip FAIL" puts cr ] # Test dip 5 dup while [ 1 - dup ] 0 = if [ " while loop PASS" puts cr ] [ " while loop FAIL" puts cr ] # Test while +:: test_while_word [ 5 dup while [ 1 - dup ] ] test_while_word 0 = if [ " while in word PASS" puts cr ] [ " while in word FAIL" puts cr ] # Test while in word 0 [ + ] [ 1 2 3 ] qfor 6 = 0 [ + ] [] qfor 0 = and if [ " qfor PASS" puts cr ] [ " qfor FAIL" puts cr ] # Test qfor 0 for [ 1 4 range ] [ + ] 6 = 0 for [ [] ] [ + ] 0 = and if [ " for PASS" puts cr ] [ " for FAIL" puts cr ] # Test for