From ed57fac2de48c7a86536ae22c77540f787d49a81 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Sun, 26 Mar 2023 15:27:41 +1300 Subject: Refactoring --- spec/practical/not_xml_spec.cr | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'spec/practical/not_xml_spec.cr') diff --git a/spec/practical/not_xml_spec.cr b/spec/practical/not_xml_spec.cr index c9db2a6..4d87481 100644 --- a/spec/practical/not_xml_spec.cr +++ b/spec/practical/not_xml_spec.cr @@ -40,7 +40,7 @@ def match_literal(s : String) : Parser(Char, String) end def letter - Parser(Char, Char).satisfy { |c| c.letter? } + Parser(Char, Char).satisfy(&.letter?) end def alphanum_dash @@ -62,7 +62,7 @@ def quote end def string_body - Parser(Char, Char).satisfy { |c| c != '"' }.many.map(&.join) + Parser(Char, Char).satisfy(&.!=('"')).many.map(&.join) end def string_literal @@ -70,7 +70,7 @@ def string_literal end def ws_char - Parser(Char, Char).satisfy { |c| c.whitespace? } + Parser(Char, Char).satisfy(&.whitespace?) end def within_ws(p) @@ -78,8 +78,8 @@ def within_ws(p) end def attr_pair - (identifier + (equal >> string_literal)).map do |tup| - Attribute.new(tup.first, tup.last) + (identifier + (equal >> string_literal)).map do |name, value| + Attribute.new(name, value) end end @@ -92,14 +92,14 @@ def element_start end def single_element - (element_start << match_literal("/>")).map do |tup| - Element.new(tup.first, tup.last, [] of Element) + (element_start << match_literal("/>")).map do |name, attributes| + Element.new(name, attributes, [] of Element) end end def open_element - (element_start << match_literal(">")).map do |tup| - Element.new(tup.first, tup.last, [] of Element) + (element_start << match_literal(">")).map do |name, attributes| + Element.new(name, attributes, [] of Element) end end @@ -123,25 +123,6 @@ def parent_element : Parser(Char, Element) end end -#def old_parent_element -# Parser(Char, Element).new("parent element") do |tokens| -# result_open = open_element.parse(tokens) -# tokens = result_open.tokens -# base_element = result_open.value -# closing_name = base_element.name -# -# result_children = (element.many << close_element(closing_name)).parse(tokens) -# Result.new( -# result_children.tokens, -# Element.new( -# base_element.name, -# base_element.attributes, -# result_children.value -# ) -# ) -# end -#end - # Adapted from: https://bodil.lol/parser-combinators/ describe "markup language similar to XML" do -- cgit v1.2.1