mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-12 22:42:23 +00:00
step
This commit is contained in:
parent
572a04bc12
commit
b93e60cc89
@ -9,7 +9,23 @@ module Tartrazine
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Rule
|
class Rule
|
||||||
property pattern : Regex = /.*/
|
property pattern : Regex? = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# This rule includes another state
|
||||||
|
# I have no idea what thet MEANS yet but in the XML
|
||||||
|
# it's this:
|
||||||
|
# <rule>
|
||||||
|
# <include state="interp"/>
|
||||||
|
# </rule>
|
||||||
|
# </state>
|
||||||
|
# <state name="interp">
|
||||||
|
# <rule pattern="\$\(\(">
|
||||||
|
# <token type="Keyword"/>
|
||||||
|
# ...
|
||||||
|
|
||||||
|
class IncludeState < Rule
|
||||||
|
property include : String = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
class Lexer
|
class Lexer
|
||||||
@ -47,9 +63,9 @@ module Tartrazine
|
|||||||
state.name = node["name"]
|
state.name = node["name"]
|
||||||
# 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"]?
|
||||||
rule = Rule.new
|
rule = Rule.new
|
||||||
state.rules << rule
|
state.rules << rule
|
||||||
if rule_node["pattern"]?
|
|
||||||
rule.pattern = /#{rule_node["pattern"]}/
|
rule.pattern = /#{rule_node["pattern"]}/
|
||||||
else
|
else
|
||||||
puts "Unknown rule type: #{rule_node}"
|
puts "Unknown rule type: #{rule_node}"
|
||||||
@ -63,8 +79,8 @@ module Tartrazine
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
l = Tartrazine::Lexer.from_xml(File.read("lexers/ada.xml"))
|
l = Tartrazine::Lexer.from_xml(File.read("lexers/solidity.xml"))
|
||||||
p! l.config, l.states
|
# p! l.config, l.states
|
||||||
|
|
||||||
# Convenience macros to parse XML
|
# Convenience macros to parse XML
|
||||||
macro xml_to_s(node, name)
|
macro xml_to_s(node, name)
|
||||||
|
Loading…
Reference in New Issue
Block a user