States are a hash

This commit is contained in:
Roberto Alsina 2024-08-02 19:48:58 -03:00
parent b93e60cc89
commit a460d553c4

View File

@ -37,7 +37,7 @@ module Tartrazine
priority: 0, priority: 0,
} }
property states = [] of State property states = {} of String => State
def self.from_xml(xml : String) : Lexer def self.from_xml(xml : String) : Lexer
l = Lexer.new l = Lexer.new
@ -59,8 +59,12 @@ module Tartrazine
# Rules contains states 🤷 # Rules contains states 🤷
rules.children.select { |n| n.name == "state" }.each do |node| rules.children.select { |n| n.name == "state" }.each do |node|
state = State.new state = State.new
l.states << state
state.name = node["name"] state.name = node["name"]
if l.states.has_key?(state.name)
puts "Duplicate state: #{state.name}"
else
l.states[state.name] = state
end
# And states contain rules 🤷 # And states contain rules 🤷
node.children.select { |n| n.name == "rule" }.each do |rule_node| node.children.select { |n| n.name == "rule" }.each do |rule_node|
if rule_node["pattern"]? if rule_node["pattern"]?