mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 05:22:23 +00:00
Reorg
This commit is contained in:
parent
444db0abda
commit
7d7a4294ed
@ -5,21 +5,13 @@ module Tartrazine
|
||||
|
||||
class Lexer
|
||||
property config = {
|
||||
name: "",
|
||||
name: "",
|
||||
aliases: [] of String,
|
||||
filenames: [] of String,
|
||||
mime_types: [] of String,
|
||||
priority: 0,
|
||||
}
|
||||
|
||||
macro xml_to_s(node, name)
|
||||
{{node}}.children.find{|n| n.name == "{{name}}".lstrip("_")}.as(XML::Node).content.to_s
|
||||
end
|
||||
|
||||
macro xml_to_a(node, name)
|
||||
{{node}}.children.select{|n| n.name == "{{name}}".lstrip("_")}.map {|n| n.content.to_s}
|
||||
end
|
||||
|
||||
def self.from_xml(xml : String) : Lexer
|
||||
l = Lexer.new
|
||||
lexer = XML.parse(xml).first_element_child
|
||||
@ -27,8 +19,8 @@ module Tartrazine
|
||||
config = lexer.children.find { |n| n.name == "config" }
|
||||
if config
|
||||
l.config = {
|
||||
name: xml_to_s(config, name),
|
||||
aliases: xml_to_a(config, _alias),
|
||||
name: xml_to_s(config, name),
|
||||
aliases: xml_to_a(config, _alias),
|
||||
filenames: xml_to_a(config, filename),
|
||||
mime_types: xml_to_a(config, mime_type),
|
||||
priority: xml_to_s(config, priority).to_i,
|
||||
@ -40,5 +32,14 @@ module Tartrazine
|
||||
end
|
||||
end
|
||||
|
||||
l = Tartrazine::Lexer.from_xml(File.read("chroma/lexers/embedded/plaintext.xml"))
|
||||
l = Tartrazine::Lexer.from_xml(File.read("lexers/plaintext.xml"))
|
||||
p! l.config
|
||||
|
||||
# Convenience macros to parse XML
|
||||
macro xml_to_s(node, name)
|
||||
{{node}}.children.find{|n| n.name == "{{name}}".lstrip("_")}.as(XML::Node).content.to_s
|
||||
end
|
||||
|
||||
macro xml_to_a(node, name)
|
||||
{{node}}.children.select{|n| n.name == "{{name}}".lstrip("_")}.map {|n| n.content.to_s}
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user