Go through all lexers

This commit is contained in:
Roberto Alsina 2024-08-03 05:05:01 -03:00
parent 50d1873c7c
commit 1bcd979cf6

View File

@ -38,7 +38,7 @@ module Tartrazine
aliases: [] of String, aliases: [] of String,
filenames: [] of String, filenames: [] of String,
mime_types: [] of String, mime_types: [] of String,
priority: 0, priority: 0.0,
} }
property states = {} of String => State property states = {} of String => State
@ -54,7 +54,7 @@ module Tartrazine
aliases: xml_to_a(config, _alias) || [] of String, aliases: xml_to_a(config, _alias) || [] of String,
filenames: xml_to_a(config, filename) || [] of String, filenames: xml_to_a(config, filename) || [] of String,
mime_types: xml_to_a(config, mime_type) || [] of String, mime_types: xml_to_a(config, mime_type) || [] of String,
priority: xml_to_i(config, priority) || 0, priority: xml_to_f(config, priority) || 0.0,
} }
end end
@ -74,7 +74,11 @@ module Tartrazine
if rule_node["pattern"]? if rule_node["pattern"]?
# We have patter rules # We have patter rules
rule = Rule.new rule = Rule.new
begin
rule.pattern = /#{rule_node["pattern"]}/ rule.pattern = /#{rule_node["pattern"]}/
rescue ex : Exception
puts "Bad regex: #{rule_node["pattern"]}, #{ex}"
end
else else
# And rules that include a state # And rules that include a state
rule = IncludeStateRule.new rule = IncludeStateRule.new
@ -106,15 +110,17 @@ module Tartrazine
end end
end end
l = Tartrazine::Lexer.from_xml(File.read("lexers/ada.xml")) Dir.glob("lexers/*.xml").each do |fname|
Tartrazine::Lexer.from_xml(File.read(fname))
end
# Convenience macros to parse XML # Convenience macros to parse XML
macro xml_to_s(node, name) macro xml_to_s(node, name)
{{node}}.children.find{|n| n.name == "{{name}}".lstrip("_")}.try &.content.to_s {{node}}.children.find{|n| n.name == "{{name}}".lstrip("_")}.try &.content.to_s
end end
macro xml_to_i(node, name) macro xml_to_f(node, name)
({{node}}.children.find{|n| n.name == "{{name}}".lstrip("_")}.try &.content.to_s.to_i) ({{node}}.children.find{|n| n.name == "{{name}}".lstrip("_")}.try &.content.to_s.to_f)
end end
macro xml_to_a(node, name) macro xml_to_a(node, name)