@@ -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,37 @@ 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
118+ Const === root . parent . value and
119+ root . parent . value . value == "SyntaxTree"
120+ compile_node ( root . constant )
121+ elsif DynaSymbol === root and root . parts . empty?
122122 symbol = :""
123123
124124 -> ( node ) { node == symbol }
125- in DynaSymbol [ parts : [ TStringContent [ value :] ] ]
126- symbol = value . to_sym
125+ elsif DynaSymbol === root and parts = root . parts and parts . size == 1 and
126+ TStringContent === parts [ 0 ]
127+ symbol = parts [ 0 ] . value . to_sym
127128
128- -> ( attribute ) { attribute == value }
129- in HshPtn [ constant : , keywords : , keyword_rest : nil ]
130- compiled_constant = compile_node ( constant )
129+ -> ( node ) { node == symbol }
130+ elsif HshPtn === root and root . keyword_rest . nil?
131+ compiled_constant = compile_node ( root . constant )
131132
132133 preprocessed =
133- keywords . to_h do |keyword , value |
134- raise NoMatchingPatternError unless keyword . is_a? ( Label )
134+ root . keywords . to_h do |keyword , value |
135+ unless keyword . is_a? ( Label )
136+ raise CompilationError , PP . pp ( root , +"" ) . chomp
137+ end
135138 [ keyword . value . chomp ( ":" ) . to_sym , compile_node ( value ) ]
136139 end
137140
@@ -148,25 +151,28 @@ def compile_node(root)
148151 else
149152 compiled_keywords
150153 end
151- in RegexpLiteral [ parts : [ TStringContent [ value :] ] ]
152- regexp = /#{ value } /
154+ elsif RegexpLiteral === root and parts = root . parts and
155+ parts . size == 1 and TStringContent === parts [ 0 ]
156+ regexp = /#{ parts [ 0 ] . value } /
153157
154158 -> ( attribute ) { regexp . match? ( attribute ) }
155- in StringLiteral [ parts : [ ] ]
159+ elsif StringLiteral === root and root . parts . empty?
156160 -> ( attribute ) { attribute == "" }
157- in StringLiteral [ parts : [ TStringContent [ value :] ] ]
161+ elsif StringLiteral === root and parts = root . parts and
162+ parts . size == 1 and TStringContent === parts [ 0 ]
163+ value = parts [ 0 ] . value
158164 -> ( attribute ) { attribute == value }
159- in SymbolLiteral [ value : ]
160- symbol = value . value . to_sym
165+ elsif SymbolLiteral === root
166+ symbol = root . value . value . to_sym
161167
162168 -> ( attribute ) { attribute == symbol }
163- in VarRef [ value : Const => value ]
164- compile_node ( value )
165- in VarRef [ value : Kw [ value : " nil" ] ]
169+ elsif VarRef === root and Const === root . value
170+ compile_node ( root . value )
171+ elsif VarRef === root and Kw === root . value and root . value . value . nil?
166172 -> ( attribute ) { attribute . nil? }
173+ else
174+ raise CompilationError , PP . pp ( root , +"" ) . chomp
167175 end
168- rescue NoMatchingPatternError
169- raise CompilationError , PP . pp ( root , +"" ) . chomp
170176 end
171177 end
172178end
0 commit comments