diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/practical/bf_spec.cr | 4 | ||||
| -rw-r--r-- | spec/practical/not_xml_spec.cr | 37 | ||||
| -rw-r--r-- | spec/practical/words_spec.cr | 4 |
3 files changed, 13 insertions, 32 deletions
diff --git a/spec/practical/bf_spec.cr b/spec/practical/bf_spec.cr index cd14c59..d1ad488 100644 --- a/spec/practical/bf_spec.cr +++ b/spec/practical/bf_spec.cr @@ -122,13 +122,13 @@ describe "brainfuck parser" do end shift_block = (Parser.token('<') | Parser.token('>')).some.map do |cs| - left_count = cs.count { |c| c == '<' } + left_count = cs.count(&.==('<')) right_count = cs.size - left_count {type: BFOpType::Shift, amount: right_count - left_count} end add_block = (Parser.token('+') | Parser.token('-')).some.map do |cs| - minus_count = cs.count { |c| c == '-' } + minus_count = cs.count(&.==('-')) plus_count = cs.size - minus_count {type: BFOpType::Add, amount: plus_count - minus_count} end 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 diff --git a/spec/practical/words_spec.cr b/spec/practical/words_spec.cr index 5155881..35a4113 100644 --- a/spec/practical/words_spec.cr +++ b/spec/practical/words_spec.cr @@ -3,10 +3,10 @@ require "../spec_helper" include Parcom describe "Text surrounded by whitespace" do - ws_char = Parser(Char, Char).satisfy { |c| c.whitespace? } + ws_char = Parser(Char, Char).satisfy(&.whitespace?) normal_char = Parser(Char, Char).satisfy { |c| !c.whitespace? } - word = normal_char.some.map { |cs| cs.join } + word = normal_char.some.map(&.join) ws = ws_char.some words = ws.optional >> word.sep_by(ws) << ws.optional |
