Skip to content

Commit ec28cc3

Browse files
authored
Merge pull request #59 from ruby-syntax-tree/remove-pattern-matching
Remove pattern matching
2 parents 8a657a9 + 71ccf0f commit ec28cc3

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

lib/syntax_tree/haml.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,26 @@ class Haml::Parser::ParseNode
5959
# accept a visitor in order to walk through the tree.
6060
def accept(visitor)
6161
case type
62-
in :comment
62+
when :comment
6363
visitor.visit_comment(self)
64-
in :doctype
64+
when :doctype
6565
visitor.visit_doctype(self)
66-
in :filter
66+
when :filter
6767
visitor.visit_filter(self)
68-
in :haml_comment
68+
when :haml_comment
6969
visitor.visit_haml_comment(self)
70-
in :plain
70+
when :plain
7171
visitor.visit_plain(self)
72-
in :root
72+
when :root
7373
visitor.visit_root(self)
74-
in :script
74+
when :script
7575
visitor.visit_script(self)
76-
in :silent_script
76+
when :silent_script
7777
visitor.visit_silent_script(self)
78-
in :tag
78+
when :tag
7979
visitor.visit_tag(self)
80+
else
81+
raise "Unknown node type: #{type}"
8082
end
8183
end
8284

lib/syntax_tree/haml/format.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,11 @@ def visit_tag(node)
416416
def continuation?(node, child)
417417
return false if child.type != :silent_script
418418

419-
case [node.value[:keyword], child.value[:keyword]]
420-
in ["case", "in" | "when" | "else"]
421-
true
422-
in ["if" | "unless", "elsif" | "else"]
423-
true
419+
case node.value[:keyword]
420+
when "case"
421+
%w[in when else].include?(child.value[:keyword])
422+
when "if", "unless"
423+
%w[elsif else].include?(child.value[:keyword])
424424
else
425425
false
426426
end
@@ -438,11 +438,12 @@ def escaped?(text)
438438
# Take a source string and attempt to parse it into a set of attributes
439439
# that can be used to format the source.
440440
def parse_attributes(source)
441-
case Ripper.sexp(source)
442-
in [:program, [[:hash, *], *]] if parsed =
443-
::Haml::AttributeParser.parse(source)
441+
program = Ripper.sexp(source)
442+
type = program && program[1][0][0]
443+
444+
if type == :hash && (parsed = ::Haml::AttributeParser.parse(source))
444445
parsed.to_h { |key, value| [key, parse_attributes(value)] }
445-
in [:program, [[:string_literal, *], *]]
446+
elsif type == :string_literal
446447
SyntaxTree.parse(source).statements.body[0]
447448
else
448449
LiteralHashValue.new(source)

0 commit comments

Comments
 (0)