Done parsing (in a dumb way)

This commit is contained in:
Roberto Alsina 2024-08-03 05:26:32 -03:00
parent 54e7b63c81
commit 270f51a811

View File

@ -3,6 +3,12 @@ require "xml"
module Tartrazine module Tartrazine
VERSION = "0.1.0" VERSION = "0.1.0"
# This implements a lexer for Pygments RegexLexers as expressed
# in Chroma's XML serialization.
#
# For explanations on what emitters, transformers, etc do
# the Pygments documentation is a good place to start.
# https://pygments.org/docs/lexerdevelopment/
class State class State
property name : String = "" property name : String = ""
property rules = [] of Rule property rules = [] of Rule
@ -10,11 +16,11 @@ module Tartrazine
class Rule class Rule
property pattern : Regex? = nil property pattern : Regex? = nil
property emitters : Array(Emitter) = [] of Emitter
property transformers : Array(TRansformer) = [] of TRansformer
end end
# This rule includes another state # This rule includes another state like this:
# I have no idea what thet MEANS yet but in the XML
# it's this:
# <rule> # <rule>
# <include state="interp"/> # <include state="interp"/>
# </rule> # </rule>
@ -30,6 +36,11 @@ module Tartrazine
class Emitter class Emitter
property type : String = "" property type : String = ""
property xml : String = ""
end
class Transformer
property xml: String = ""
end end
class Lexer class Lexer
@ -94,9 +105,13 @@ module Tartrazine
next unless node.element? next unless node.element?
case node.name case node.name
when "pop", "push", "include", "multi", "combine" when "pop", "push", "include", "multi", "combine"
puts "transformer: #{node.to_s}" transformer = Transformer.new
transformer.xml = node.to_s
rule.transformers << transformer
when "bygroups", "combined", "mutators", "token", "using", "usingbygroup", "usingself" when "bygroups", "combined", "mutators", "token", "using", "usingbygroup", "usingself"
puts "emitter: #{node.to_s}" emitter = Emitter.new
emitter.xml = node.to_s
rule.emitters << emitter
end end
end end
end end