Browse Source

Refactor

master
Dylan Baker 4 years ago
parent
commit
bdade75ceb
1 changed files with 15 additions and 12 deletions
  1. 15
    12
      lib/ahem/parser.rb

+ 15
- 12
lib/ahem/parser.rb View File

106
 
106
 
107
     class_methods = Array.new
107
     class_methods = Array.new
108
     instance_methods = Array.new
108
     instance_methods = Array.new
109
-    while [TokenKinds::METHOD, TokenKinds::CLASSMETHOD].include?(@current_token.type)
109
+    while [TokenKinds::METHOD, TokenKinds::CLASSMETHOD].include?(
110
+      @current_token.type
111
+    )
110
       case @current_token.type
112
       case @current_token.type
111
       when TokenKinds::METHOD
113
       when TokenKinds::METHOD
112
         instance_methods << method_definition
114
         instance_methods << method_definition
117
 
119
 
118
     eat(TokenKinds::RBRACE)
120
     eat(TokenKinds::RBRACE)
119
 
121
 
120
-    AST::ClassDefinition.new(class_name, property_declarations, instance_methods, class_methods)
122
+    AST::ClassDefinition.new(
123
+      class_name,
124
+      property_declarations,
125
+      instance_methods,
126
+      class_methods
127
+    )
121
   end
128
   end
122
 
129
 
123
   def conditional
130
   def conditional
206
     left = comparison
213
     left = comparison
207
 
214
 
208
     if @current_token.type == TokenKinds::OPERATOR
215
     if @current_token.type == TokenKinds::OPERATOR
209
-      operator = @current_token.value
210
-      advance
216
+      operator = eat(TokenKinds::OPERATOR).value
211
       right = comparison
217
       right = comparison
212
       AST::Binary.new(operator, left, right)
218
       AST::Binary.new(operator, left, right)
213
     else
219
     else
216
   end
222
   end
217
 
223
 
218
   def comparison
224
   def comparison
219
-    left = multiplication
225
+    left = addition
220
 
226
 
221
     if @current_token.type == TokenKinds::OPERATOR &&
227
     if @current_token.type == TokenKinds::OPERATOR &&
222
        %i[< > <= >=].include?(@current_token.type)
228
        %i[< > <= >=].include?(@current_token.type)
223
-      operator = @current_token.value
224
-      advance
225
-      right = multiplication
229
+      operator = eat(TokenKinds::OPERATOR).value
230
+      right = addition
226
       AST::Binary.new(operator, left, right)
231
       AST::Binary.new(operator, left, right)
227
     else
232
     else
228
       left
233
       left
234
 
239
 
235
     if @current_token.type == TokenKinds::OPERATOR &&
240
     if @current_token.type == TokenKinds::OPERATOR &&
236
        %i[+ -].include?(@current_token.value)
241
        %i[+ -].include?(@current_token.value)
237
-      operator = @current_token.value
238
-      advance
242
+      operator = eat(TokenKinds::OPERATOR).value
239
       right = multiplication
243
       right = multiplication
240
       AST::Binary.new(operator, left, right)
244
       AST::Binary.new(operator, left, right)
241
     else
245
     else
248
 
252
 
249
     if @current_token.type == TokenKinds::OPERATOR &&
253
     if @current_token.type == TokenKinds::OPERATOR &&
250
        %i[* /].include?(@current_token.value)
254
        %i[* /].include?(@current_token.value)
251
-      operator = @current_token.value
252
-      advance
255
+      operator = eat(TokenKinds::OPERATOR).value
253
       right = unary
256
       right = unary
254
       AST::Binary.new(operator, left, right)
257
       AST::Binary.new(operator, left, right)
255
     else
258
     else

Loading…
Cancel
Save