Make action a struct, guard against popping too much

This commit is contained in:
Roberto Alsina 2024-08-15 21:16:17 -03:00
parent a3a7b5bd9a
commit b589726352

View File

@ -8,7 +8,7 @@ require "./tartrazine"
# perform a list of actions. These actions can emit tokens
# or change the state machine.
module Tartrazine
class Action
struct Action
property actions : Array(Action) = [] of Action
property type : String
@ -64,7 +64,7 @@ module Tartrazine
when "push"
to_push = @states_to_push.empty? ? [lexer.state_stack.last] : @states_to_push
to_push.each do |state|
if state == "#pop"
if state == "#pop" && lexer.state_stack.size > 1
# Pop the state
lexer.state_stack.pop
else