added interrupt class for continue/break statements

When a continue or break statement is executed it pushes an interrupt to a
stack in context. If any non-handled interrupts are present blocks will cease
to execute. The for loop can handle the most recent interrupt in the stack.
This commit is contained in:
Jon Daniel
2012-08-21 13:14:27 -04:00
parent 484fd18612
commit 9c183bea83
11 changed files with 171 additions and 37 deletions
+17
View File
@@ -0,0 +1,17 @@
module Liquid
# An interrupt is any command that breaks processing of a block (ex: a for loop).
class Interrupt
attr_reader :message
def initialize(message=nil)
@message = message || "interrupt"
end
end
# Interrupt that is thrown whenever a {% break %} is called.
class BreakInterrupt < Interrupt; end
# Interrupt that is thrown whenever a {% continue %} is called.
class ContinueInterrupt < Interrupt; end
end