@@ -84,11 +84,11 @@ def combine_or(left, right)
84
84
end
85
85
86
86
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
89
89
compiled_constant = compile_node ( constant ) if constant
90
90
91
- preprocessed = requireds . map { |required | compile_node ( required ) }
91
+ preprocessed = root . requireds . map { |required | compile_node ( required ) }
92
92
93
93
compiled_requireds = -> ( node ) do
94
94
deconstructed = node . deconstruct
@@ -104,34 +104,37 @@ def compile_node(root)
104
104
else
105
105
compiled_requireds
106
106
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 )
111
111
112
112
-> ( 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 )
115
115
116
116
-> ( 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?
122
122
symbol = :""
123
123
124
124
-> ( 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
127
128
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 )
131
132
132
133
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
135
138
[ keyword . value . chomp ( ":" ) . to_sym , compile_node ( value ) ]
136
139
end
137
140
@@ -148,25 +151,28 @@ def compile_node(root)
148
151
else
149
152
compiled_keywords
150
153
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 } /
153
157
154
158
-> ( attribute ) { regexp . match? ( attribute ) }
155
- in StringLiteral [ parts : [ ] ]
159
+ elsif StringLiteral === root and root . parts . empty?
156
160
-> ( 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
158
164
-> ( attribute ) { attribute == value }
159
- in SymbolLiteral [ value : ]
160
- symbol = value . value . to_sym
165
+ elsif SymbolLiteral === root
166
+ symbol = root . value . value . to_sym
161
167
162
168
-> ( 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?
166
172
-> ( attribute ) { attribute . nil? }
173
+ else
174
+ raise CompilationError , PP . pp ( root , +"" ) . chomp
167
175
end
168
- rescue NoMatchingPatternError
169
- raise CompilationError , PP . pp ( root , +"" ) . chomp
170
176
end
171
177
end
172
178
end
0 commit comments