Process all 425 tests without crashing

This commit is contained in:
Roberto Alsina 2024-08-03 17:15:12 -03:00
parent db66777a8b
commit e625d6604a

View File

@ -87,13 +87,15 @@ module Tartrazine
[Token.new(type: xml["type"], value: match[0])] [Token.new(type: xml["type"], value: match[0])]
# TODO handle #push #push:n #pop and multiple states # TODO handle #push #push:n #pop and multiple states
when "push" when "push"
puts "Pushing state #{xml["state"]}" # Push without a state means push the current state
lexer.state_stack << xml["state"] state = xml["state"]? || lexer.state_stack.last
puts "Pushing state #{state}"
lexer.state_stack << state
[] of Token [] of Token
when "pop" when "pop"
depth = xml["depth"].to_i depth = xml["depth"].to_i
puts "Popping #{depth} states" puts "Popping #{depth} states"
if lexer.state_stack.size < depth if lexer.state_stack.size <= depth
puts "Can't pop #{depth} states, only have #{lexer.state_stack.size}" puts "Can't pop #{depth} states, only have #{lexer.state_stack.size}"
else else
lexer.state_stack.pop(depth) lexer.state_stack.pop(depth)