@@ -84,11 +84,11 @@ def combine_or(left, right)
8484 end
8585
8686 def compile_node ( root )
87- case root
88- in AryPtn [ constant : , requireds : , rest : nil , posts : [ ] ]
87+ if AryPtn === root and root . rest . nil? and root . posts . empty?
88+ constant = root . constant
8989 compiled_constant = compile_node ( constant ) if constant
9090
91- preprocessed = requireds . map { |required | compile_node ( required ) }
91+ preprocessed = root . requireds . map { |required | compile_node ( required ) }
9292
9393 compiled_requireds = -> ( node ) do
9494 deconstructed = node . deconstruct
@@ -104,34 +104,32 @@ def compile_node(root)
104104 else
105105 compiled_requireds
106106 end
107- in Binary [ left : , operator : :| , right : ]
108- combine_or ( compile_node ( left ) , compile_node ( right ) )
109- in Const [ value : ] if SyntaxTree . const_defined? ( value )
110- clazz = SyntaxTree . const_get ( value )
107+ elsif Binary === root and root . operator == :|
108+ combine_or ( compile_node ( root . left ) , compile_node ( root . right ) )
109+ elsif Const === root and SyntaxTree . const_defined? ( root . value )
110+ clazz = SyntaxTree . const_get ( root . value )
111111
112112 -> ( node ) { node . is_a? ( clazz ) }
113- in Const [ value : ] if Object . const_defined? ( value )
114- clazz = Object . const_get ( value )
113+ elsif Const === root and Object . const_defined? ( root . value )
114+ clazz = Object . const_get ( root . value )
115115
116116 -> ( node ) { node . is_a? ( clazz ) }
117- in ConstPathRef [
118- parent : VarRef [ value : Const [ value : "SyntaxTree" ] ] , constant :
119- ]
120- compile_node ( constant )
121- in DynaSymbol [ parts : [ ] ]
117+ elsif ConstPathRef === root and VarRef === root . parent and Const === root . parent . value and root . parent . value . value == "SyntaxTree"
118+ compile_node ( root . constant )
119+ elsif DynaSymbol === root and root . parts . empty?
122120 symbol = :""
123121
124122 -> ( node ) { node == symbol }
125- in DynaSymbol [ parts : [ TStringContent [ value : ] ] ]
126- symbol = value . to_sym
123+ elsif DynaSymbol === root and parts = root . parts and parts . size == 1 and TStringContent === parts [ 0 ]
124+ symbol = parts [ 0 ] . value . to_sym
127125
128126 -> ( attribute ) { attribute == value }
129- in HshPtn [ constant : , keywords : , keyword_rest : nil ]
130- compiled_constant = compile_node ( constant )
127+ elsif HshPtn === root and root . keyword_rest . nil?
128+ compiled_constant = compile_node ( root . constant )
131129
132130 preprocessed =
133- keywords . to_h do |keyword , value |
134- raise NoMatchingPatternError unless keyword . is_a? ( Label )
131+ root . keywords . to_h do |keyword , value |
132+ raise CompilationError , PP . pp ( root , + "" ) . chomp unless keyword . is_a? ( Label )
135133 [ keyword . value . chomp ( ":" ) . to_sym , compile_node ( value ) ]
136134 end
137135
@@ -148,25 +146,26 @@ def compile_node(root)
148146 else
149147 compiled_keywords
150148 end
151- in RegexpLiteral [ parts : [ TStringContent [ value : ] ] ]
152- regexp = /#{ value } /
149+ elsif RegexpLiteral === root and parts = root . parts and parts . size == 1 and TStringContent === parts [ 0 ]
150+ regexp = /#{ parts [ 0 ] . value } /
153151
154152 -> ( attribute ) { regexp . match? ( attribute ) }
155- in StringLiteral [ parts : [ ] ]
153+ elsif StringLiteral === root and root . parts . empty?
156154 -> ( attribute ) { attribute == "" }
157- in StringLiteral [ parts : [ TStringContent [ value :] ] ]
155+ elsif StringLiteral === root and parts = root . parts and parts . size == 1 and TStringContent === parts [ 0 ]
156+ value = parts [ 0 ] . value
158157 -> ( attribute ) { attribute == value }
159- in SymbolLiteral [ value : ]
160- symbol = value . value . to_sym
158+ elsif SymbolLiteral === root
159+ symbol = root . value . value . to_sym
161160
162161 -> ( attribute ) { attribute == symbol }
163- in VarRef [ value : Const => value ]
164- compile_node ( value )
165- in VarRef [ value : Kw [ value : " nil" ] ]
162+ elsif VarRef === root and Const === root . value
163+ compile_node ( root . value )
164+ elsif VarRef === root and Kw === root . value and root . value . value . nil?
166165 -> ( attribute ) { attribute . nil? }
166+ else
167+ raise CompilationError , PP . pp ( root , +"" ) . chomp
167168 end
168- rescue NoMatchingPatternError
169- raise CompilationError , PP . pp ( root , +"" ) . chomp
170169 end
171170 end
172171end
0 commit comments