spicy icon indicating copy to clipboard operation
spicy copied to clipboard

Stop seems to be broken

Open bbannier opened this issue 3 years ago • 1 comments

I cannot seem to get to stop work as expected, e.g.,

# foo.spicy
module foo;

public type X = unit {
	xs: uint8[] foreach {
		print self.xs, $$;

		if ($$==0) {
			print "Stopping";
			stop;
		}
	}
};
$ printf '\x01\x02\x00\x01\x02' | spicy-driver -d %
[], 1
[1], 2
[1, 2], 0
Stopping
[1, 2], 1
[1, 2, 1], 2

In this example I would have expected self.xs == vector(1, 2), and no further output after Stopping.

bbannier avatar Jul 20 '22 09:07 bbannier

A workaround seems to be to use vector parsing &until to track whether to stop parsing,

module foo;

public type X = unit {
	var xs_done: bool = False;
	xs: uint8[] &until=self.xs_done foreach {
		print self.xs, $$;

		if ($$==0) {
			print "Stopping";
			self.xs_done = True;
		}
	}
};
$ printf '\x01\x02\x00\x01\x02' | spicy-driver -d %
[], 1
[1], 2
[1, 2], 0
Stopping

bbannier avatar Jul 20 '22 10:07 bbannier