Browse Source

Refactor

master
Dylan Baker 1 year 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,7 +106,9 @@ class Parser
106 106
 
107 107
     class_methods = Array.new
108 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 112
       case @current_token.type
111 113
       when TokenKinds::METHOD
112 114
         instance_methods << method_definition
@@ -117,7 +119,12 @@ class Parser
117 119
 
118 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 128
   end
122 129
 
123 130
   def conditional
@@ -206,8 +213,7 @@ class Parser
206 213
     left = comparison
207 214
 
208 215
     if @current_token.type == TokenKinds::OPERATOR
209
-      operator = @current_token.value
210
-      advance
216
+      operator = eat(TokenKinds::OPERATOR).value
211 217
       right = comparison
212 218
       AST::Binary.new(operator, left, right)
213 219
     else
@@ -216,13 +222,12 @@ class Parser
216 222
   end
217 223
 
218 224
   def comparison
219
-    left = multiplication
225
+    left = addition
220 226
 
221 227
     if @current_token.type == TokenKinds::OPERATOR &&
222 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 231
       AST::Binary.new(operator, left, right)
227 232
     else
228 233
       left
@@ -234,8 +239,7 @@ class Parser
234 239
 
235 240
     if @current_token.type == TokenKinds::OPERATOR &&
236 241
        %i[+ -].include?(@current_token.value)
237
-      operator = @current_token.value
238
-      advance
242
+      operator = eat(TokenKinds::OPERATOR).value
239 243
       right = multiplication
240 244
       AST::Binary.new(operator, left, right)
241 245
     else
@@ -248,8 +252,7 @@ class Parser
248 252
 
249 253
     if @current_token.type == TokenKinds::OPERATOR &&
250 254
        %i[* /].include?(@current_token.value)
251
-      operator = @current_token.value
252
-      advance
255
+      operator = eat(TokenKinds::OPERATOR).value
253 256
       right = unary
254 257
       AST::Binary.new(operator, left, right)
255 258
     else

Loading…
Cancel
Save