Browse Source

Raise instead of throw

master
Dylan Baker 4 years ago
parent
commit
a9c444a42f
5 changed files with 10 additions and 10 deletions
  1. 1
    1
      lib/ahem/ast/function_call.rb
  2. 4
    4
      lib/ahem/ast/index.rb
  3. 1
    1
      lib/ahem/environment.rb
  4. 1
    1
      lib/ahem/lexer.rb
  5. 3
    3
      lib/ahem/parser.rb

+ 1
- 1
lib/ahem/ast/function_call.rb View File

@@ -16,7 +16,7 @@ class AST::FunctionCall
16 16
 
17 17
     if function.is_a?(AST::FunctionDefinition)
18 18
       if @arguments.size != function.parameters.size
19
-        throw "Arity mismatch in call to function #{function.name}"
19
+        raise "Arity mismatch in call to function #{function.name}"
20 20
       end
21 21
 
22 22
       function.parameters.each_with_index do |param, i|

+ 4
- 4
lib/ahem/ast/index.rb View File

@@ -19,18 +19,18 @@ class AST::Index
19 19
         if key.to_i == key && object.size > key
20 20
           object[key]
21 21
         elsif key.to_i != key
22
-          throw "Array index requires integer key"
22
+          raise "Array index requires integer key"
23 23
         elsif object.size <= key
24
-          throw "Array index out of bounds"
24
+          raise "Array index out of bounds"
25 25
         end
26 26
       else
27
-        throw "Array index requires integer key"
27
+        raise "Array index requires integer key"
28 28
       end
29 29
     elsif object.is_a?(Hash)
30 30
       if object.has_key?(key)
31 31
         object[key]
32 32
       else
33
-        throw "Key #{key} does not exist on object"
33
+        raise "Key #{key} does not exist on object"
34 34
       end
35 35
     end
36 36
   end

+ 1
- 1
lib/ahem/environment.rb View File

@@ -19,7 +19,7 @@ class Environment
19 19
     if @data.has_key?(name)
20 20
       @data[name]
21 21
     else
22
-      throw "Undefined variable #{name}"
22
+      raise "Undefined variable #{name}"
23 23
     end
24 24
   end
25 25
 

+ 1
- 1
lib/ahem/lexer.rb View File

@@ -136,7 +136,7 @@ class Lexer
136 136
       @position += class_name.size
137 137
       Token.new(TokenKinds::CLASS_NAME, class_name)
138 138
     else
139
-      throw "Unrecognized character #{source[0]}"
139
+      raise "Unrecognized character #{source[0]}"
140 140
     end
141 141
   end
142 142
 

+ 3
- 3
lib/ahem/parser.rb View File

@@ -238,7 +238,7 @@ class Parser
238 238
     when TokenKinds::LBRACE
239 239
       hash
240 240
     else
241
-      throw "Unexpected token #{token.type}"
241
+      raise "Unexpected token #{token.type}"
242 242
     end
243 243
 
244 244
     if @current_token.type == TokenKinds::LPAREN
@@ -327,9 +327,9 @@ class Parser
327 327
       token
328 328
     else
329 329
       if token.nil?
330
-        throw "Unexpected #{token.type} - expected #{type}"
330
+        raise "Unexpected #{token.type} - expected #{type}"
331 331
       else
332
-        throw "Unexpected #{token.type} - expected #{type}"
332
+        raise "Unexpected #{token.type} - expected #{type}"
333 333
       end
334 334
     end
335 335
   end

Loading…
Cancel
Save