gobstones 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +133 -0
  3. data/.rubocop_todo.yml +75 -0
  4. data/.simplecov +1 -3
  5. data/.tool-versions +1 -0
  6. data/.travis.yml +9 -2
  7. data/Gemfile +11 -5
  8. data/Gemfile.lock +65 -39
  9. data/README.md +8 -1
  10. data/Rakefile +1 -1
  11. data/bin/gobstones +1 -1
  12. data/gobstones.gemspec +12 -11
  13. data/lib/gobstones/cli/printer.rb +41 -28
  14. data/lib/gobstones/cli/runner.rb +50 -15
  15. data/lib/gobstones/extensions/all.rb +1 -1
  16. data/lib/gobstones/extensions/boolean.rb +1 -5
  17. data/lib/gobstones/extensions/{fixnum.rb → integer.rb} +2 -4
  18. data/lib/gobstones/extensions/string.rb +1 -3
  19. data/lib/gobstones/lang/all.rb +3 -3
  20. data/lib/gobstones/lang/commands/all.rb +11 -10
  21. data/lib/gobstones/lang/commands/boom.rb +26 -0
  22. data/lib/gobstones/lang/commands/command_block.rb +23 -23
  23. data/lib/gobstones/lang/commands/conditional.rb +26 -0
  24. data/lib/gobstones/lang/commands/if.rb +13 -0
  25. data/lib/gobstones/lang/commands/if_then_else.rb +26 -0
  26. data/lib/gobstones/lang/commands/ir_al_origen.rb +15 -0
  27. data/lib/gobstones/lang/commands/mover.rb +23 -0
  28. data/lib/gobstones/lang/commands/multiple_assignment.rb +34 -21
  29. data/lib/gobstones/lang/commands/poner.rb +31 -0
  30. data/lib/gobstones/lang/commands/procedure_call.rb +8 -8
  31. data/lib/gobstones/lang/commands/repeat_with.rb +69 -0
  32. data/lib/gobstones/lang/commands/sacar.rb +29 -0
  33. data/lib/gobstones/lang/commands/single_assignment.rb +15 -20
  34. data/lib/gobstones/lang/commands/skip.rb +15 -0
  35. data/lib/gobstones/lang/commands/vaciar_tablero.rb +15 -0
  36. data/lib/gobstones/lang/commands/while.rb +20 -0
  37. data/lib/gobstones/lang/definitions/definition.rb +16 -23
  38. data/lib/gobstones/lang/definitions/definition_call.rb +7 -15
  39. data/lib/gobstones/lang/definitions/function.rb +1 -7
  40. data/lib/gobstones/lang/definitions/main.rb +1 -8
  41. data/lib/gobstones/lang/definitions/no_return_statement.rb +2 -8
  42. data/lib/gobstones/lang/definitions/procedure.rb +1 -7
  43. data/lib/gobstones/lang/definitions/return_from_function.rb +6 -13
  44. data/lib/gobstones/lang/definitions/return_from_main.rb +15 -10
  45. data/lib/gobstones/lang/definitions/var_tuple.rb +10 -12
  46. data/lib/gobstones/lang/expressions/arithmetic_expressions.rb +17 -27
  47. data/lib/gobstones/lang/expressions/boolean_expressions.rb +4 -10
  48. data/lib/gobstones/lang/expressions/comparison_expressions.rb +0 -16
  49. data/lib/gobstones/lang/expressions/enclosed_by_parens_expression.rb +3 -5
  50. data/lib/gobstones/lang/expressions/expression.rb +18 -0
  51. data/lib/gobstones/lang/expressions/function_call.rb +9 -6
  52. data/lib/gobstones/lang/expressions/one_arg_expression.rb +8 -16
  53. data/lib/gobstones/lang/expressions/primitive_functions.rb +24 -16
  54. data/lib/gobstones/lang/expressions/two_arg_expression.rb +9 -16
  55. data/lib/gobstones/lang/expressions/type_bound_functions.rb +30 -25
  56. data/lib/gobstones/lang/expressions/var_name.rb +9 -13
  57. data/lib/gobstones/lang/literals/all.rb +3 -3
  58. data/lib/gobstones/lang/literals/{booleans.rb → boolean.rb} +24 -22
  59. data/lib/gobstones/lang/literals/{colors.rb → color.rb} +4 -14
  60. data/lib/gobstones/lang/literals/{directions.rb → direction.rb} +3 -13
  61. data/lib/gobstones/lang/literals/literal.rb +35 -27
  62. data/lib/gobstones/lang/literals/number.rb +6 -8
  63. data/lib/gobstones/lang/program.rb +9 -16
  64. data/lib/gobstones/modules/equality_definition.rb +23 -0
  65. data/lib/gobstones/parser/ast/ast.rb +48 -70
  66. data/lib/gobstones/parser/parse_error.rb +2 -7
  67. data/lib/gobstones/parser/treetop_parser.rb +9 -14
  68. data/lib/gobstones/runner/board.rb +12 -15
  69. data/lib/gobstones/runner/cell.rb +14 -20
  70. data/lib/gobstones/runner/errors/all.rb +1 -1
  71. data/lib/gobstones/runner/errors/boom_error.rb +0 -5
  72. data/lib/gobstones/runner/errors/definition_not_found_error.rb +7 -7
  73. data/lib/gobstones/runner/errors/empty_cell_error.rb +0 -5
  74. data/lib/gobstones/runner/errors/gobstones_runtime_error.rb +0 -5
  75. data/lib/gobstones/runner/errors/gobstones_type_error.rb +2 -7
  76. data/lib/gobstones/runner/errors/out_of_board_error.rb +0 -5
  77. data/lib/gobstones/runner/errors/undefined_variable_error.rb +6 -4
  78. data/lib/gobstones/runner/errors/wrong_arguments_error.rb +0 -5
  79. data/lib/gobstones/runner/execution_context.rb +16 -33
  80. data/lib/gobstones/runner/head.rb +17 -20
  81. data/lib/gobstones/runner/program_result.rb +12 -0
  82. data/lib/gobstones/type_check_result.rb +0 -4
  83. data/spec/lang/commands/boom_spec.rb +7 -0
  84. data/spec/lang/commands/command_block_spec.rb +15 -0
  85. data/spec/lang/commands/if_spec.rb +32 -0
  86. data/spec/lang/commands/if_then_else_spec.rb +19 -0
  87. data/spec/lang/commands/ir_al_origen_spec.rb +11 -0
  88. data/spec/lang/commands/mover_spec.rb +30 -0
  89. data/spec/lang/commands/multiple_assignment_spec.rb +39 -22
  90. data/spec/lang/commands/poner_spec.rb +27 -0
  91. data/spec/lang/commands/procedure_call_spec.rb +26 -28
  92. data/spec/lang/commands/procedure_spec.rb +32 -32
  93. data/spec/lang/commands/repeat_with_spec.rb +64 -0
  94. data/spec/lang/commands/sacar_spec.rb +32 -0
  95. data/spec/lang/commands/single_assignment_spec.rb +5 -6
  96. data/spec/lang/commands/skip_spec.rb +10 -0
  97. data/spec/lang/commands/vaciar_tablero_spec.rb +10 -0
  98. data/spec/lang/commands/while_spec.rb +39 -0
  99. data/spec/lang/definitions/main_spec.rb +34 -0
  100. data/spec/lang/definitions/no_return_statement_spec.rb +4 -5
  101. data/spec/lang/definitions/var_tuple_spec.rb +4 -7
  102. data/spec/lang/expressions/arithmetic_expressions_spec.rb +37 -64
  103. data/spec/lang/expressions/boolean_expressions_spec.rb +25 -34
  104. data/spec/lang/expressions/comparison_expressions_spec.rb +109 -155
  105. data/spec/lang/expressions/enclosed_by_parens_expression_spec.rb +3 -7
  106. data/spec/lang/expressions/function_call_spec.rb +24 -20
  107. data/spec/lang/expressions/primitive_functions_spec.rb +28 -39
  108. data/spec/lang/expressions/type_bound_functions_spec.rb +10 -18
  109. data/spec/lang/expressions/var_name_spec.rb +8 -12
  110. data/spec/lang/literals/{booleans_spec.rb → boolean_spec.rb} +3 -5
  111. data/spec/lang/literals/color_spec.rb +19 -0
  112. data/spec/lang/literals/direction_spec.rb +46 -0
  113. data/spec/lang/literals/{numbers_spec.rb → number_spec.rb} +3 -4
  114. data/spec/matchers/parse_matcher.rb +9 -11
  115. data/spec/parser/arithmetic_expressions_spec.rb +51 -61
  116. data/spec/parser/assignments_spec.rb +21 -31
  117. data/spec/parser/boolean_expressions_spec.rb +35 -43
  118. data/spec/parser/command_block_spec.rb +18 -20
  119. data/spec/parser/data_types_spec.rb +9 -19
  120. data/spec/parser/function_calls_spec.rb +19 -19
  121. data/spec/parser/function_definitions_spec.rb +17 -22
  122. data/spec/parser/gobstones_program_spec.rb +30 -30
  123. data/spec/parser/if_command_spec.rb +19 -28
  124. data/spec/parser/main_definition_spec.rb +13 -16
  125. data/spec/parser/nested_expressions_spec.rb +20 -24
  126. data/spec/parser/primitive_expressions_spec.rb +33 -38
  127. data/spec/parser/procedure_calls_spec.rb +17 -18
  128. data/spec/parser/procedure_definitions_spec.rb +12 -15
  129. data/spec/parser/repeat_with_command_spec.rb +10 -10
  130. data/spec/parser/simple_commands_spec.rb +23 -37
  131. data/spec/parser/treetop_parser_spec.rb +87 -83
  132. data/spec/parser/var_tuple_spec.rb +8 -12
  133. data/spec/parser/while_command_spec.rb +11 -14
  134. data/spec/runner/board_spec.rb +28 -33
  135. data/spec/runner/cell_spec.rb +21 -28
  136. data/spec/runner/execution_context_spec.rb +18 -35
  137. data/spec/runner/head_spec.rb +54 -60
  138. data/spec/spec_helper.rb +10 -1
  139. data/spec/support/board_assertions.rb +18 -0
  140. data/spec/{gobstones_lang_test_objects.rb → support/gobstones_lang_test_objects.rb} +6 -4
  141. data/spec/type_checker_spec.rb +19 -25
  142. metadata +80 -56
  143. data/.ruby-version +0 -1
  144. data/lib/gobstones/lang/commands/boom_cmd.rb +0 -31
  145. data/lib/gobstones/lang/commands/conditional_cmd.rb +0 -31
  146. data/lib/gobstones/lang/commands/if_cmd.rb +0 -38
  147. data/lib/gobstones/lang/commands/ir_al_origen_cmd.rb +0 -19
  148. data/lib/gobstones/lang/commands/mover_cmd.rb +0 -27
  149. data/lib/gobstones/lang/commands/poner_cmd.rb +0 -35
  150. data/lib/gobstones/lang/commands/repeat_with_cmd.rb +0 -77
  151. data/lib/gobstones/lang/commands/sacar_cmd.rb +0 -33
  152. data/lib/gobstones/lang/commands/skip_cmd.rb +0 -19
  153. data/lib/gobstones/lang/commands/vaciar_tablero_cmd.rb +0 -19
  154. data/lib/gobstones/lang/commands/while_cmd.rb +0 -25
  155. data/lib/gobstones/modules/equal_by_class.rb +0 -13
  156. data/spec/lang/commands/boom_cmd_spec.rb +0 -8
  157. data/spec/lang/commands/cmd_block_spec.rb +0 -21
  158. data/spec/lang/commands/if_cmd_spec.rb +0 -50
  159. data/spec/lang/commands/ir_al_origen_cmd_spec.rb +0 -16
  160. data/spec/lang/commands/mover_cmd_spec.rb +0 -36
  161. data/spec/lang/commands/poner_cmd_spec.rb +0 -28
  162. data/spec/lang/commands/repeat_with_cmd_spec.rb +0 -60
  163. data/spec/lang/commands/sacar_cmd_spec.rb +0 -35
  164. data/spec/lang/commands/skip_cmd_spec.rb +0 -12
  165. data/spec/lang/commands/vaciar_tablero_cmd_spec.rb +0 -14
  166. data/spec/lang/commands/while_cmd_spec.rb +0 -43
  167. data/spec/lang/literals/colors_spec.rb +0 -13
  168. data/spec/lang/literals/directions_spec.rb +0 -45
@@ -1,17 +1,12 @@
1
1
  module Gobstones
2
-
3
2
  module Parser
4
-
5
3
  class ParseError < StandardError
6
-
7
4
  attr_reader :parser, :code
8
5
 
9
6
  def initialize(parser, code)
10
- @parser, @code = parser, code
7
+ @parser = parser
8
+ @code = code
11
9
  end
12
-
13
10
  end
14
-
15
11
  end
16
-
17
12
  end
@@ -3,11 +3,8 @@ require 'gobstones/parser/ast/ast'
3
3
  require 'gobstones/parser/parse_error'
4
4
 
5
5
  module Gobstones
6
-
7
6
  module Parser
8
-
9
7
  class TreetopParser
10
-
11
8
  def initialize
12
9
  Treetop.load grammar_file
13
10
  @parser = GobstonesParser.new
@@ -15,8 +12,9 @@ module Gobstones
15
12
 
16
13
  def parse(code)
17
14
  code_without_comments = remove_comments_from(code)
18
- result = @parser.parse code_without_comments
15
+ result = @parser.parse(code_without_comments)
19
16
  raise ParseError.new(self, code_without_comments) if result.nil?
17
+
20
18
  result.value
21
19
  end
22
20
 
@@ -33,21 +31,21 @@ module Gobstones
33
31
  end
34
32
 
35
33
  def remove_comments_from(code)
36
- code
37
- .gsub(single_line_c_style_comments_regex, '')
38
- .gsub(single_line_haskell_style_comments_regex, '')
39
- .gsub(multi_line_c_style_comments_regex, '')
40
- .gsub(multi_line_haskell_style_comments_regex, '')
34
+ code.
35
+ gsub(single_line_c_style_comments_regex, '').
36
+ gsub(single_line_haskell_style_comments_regex, '').
37
+ gsub(multi_line_c_style_comments_regex, '').
38
+ gsub(multi_line_haskell_style_comments_regex, '')
41
39
  end
42
40
 
43
41
  private
44
42
 
45
43
  def grammar_file
46
- File.join base_path, 'grammar/gobstones'
44
+ File.join(base_path, 'grammar/gobstones')
47
45
  end
48
46
 
49
47
  def base_path
50
- File.expand_path File.dirname(__FILE__)
48
+ __dir__
51
49
  end
52
50
 
53
51
  def single_line_c_style_comments_regex
@@ -65,9 +63,6 @@ module Gobstones
65
63
  def multi_line_haskell_style_comments_regex
66
64
  /{-.*?\-}/m
67
65
  end
68
-
69
66
  end
70
-
71
67
  end
72
-
73
68
  end
@@ -1,32 +1,32 @@
1
1
  require 'gobstones/runner/cell'
2
2
 
3
3
  module Gobstones
4
-
5
4
  module Runner
6
-
7
5
  class Board
8
-
9
6
  attr_reader :rows, :columns
10
7
 
11
- def initialize(r, c, matrix=[])
12
- @rows, @columns = r, c
8
+ def initialize(rows_num, cols_num, matrix = [])
9
+ @rows = rows_num
10
+ @columns = cols_num
13
11
  if matrix.empty?
14
12
  @matrix = []
15
- r.times { @matrix << []; c.times { @matrix.last << Cell.new } }
13
+ rows_num.times do
14
+ @matrix << []
15
+ cols_num.times { @matrix.last << Cell.new }
16
+ end
16
17
  else
17
18
  @matrix = matrix
18
19
  end
19
20
  end
20
21
 
21
22
  def cell_at(x, y)
22
- raise OutOfBoardError unless \
23
- x.between?(0, rows - 1) && y.between?(0, columns - 1)
23
+ raise OutOfBoardError unless x.between?(0, rows - 1) && y.between?(0, columns - 1)
24
24
 
25
25
  @matrix[x][y]
26
26
  end
27
27
 
28
28
  def each_cell
29
- @matrix.each { |row| row.each { |cell| yield cell } }
29
+ @matrix.each { |row| row.each { |cell| yield(cell) } }
30
30
  end
31
31
 
32
32
  def put(x, y, color)
@@ -46,7 +46,7 @@ module Gobstones
46
46
  end
47
47
 
48
48
  def empty!
49
- each_cell { |cell| cell.empty! }
49
+ each_cell(&:empty!)
50
50
  end
51
51
 
52
52
  def empty?
@@ -55,12 +55,9 @@ module Gobstones
55
55
  end
56
56
 
57
57
  def clone
58
- new_matrix = @matrix.map { |row| row.map { |cell| cell.clone } }
59
- self.class.new @rows, @columns, new_matrix
58
+ new_matrix = @matrix.map { |row| row.map(&:clone) }
59
+ self.class.new(rows, columns, new_matrix)
60
60
  end
61
-
62
61
  end
63
-
64
62
  end
65
-
66
63
  end
@@ -1,32 +1,32 @@
1
- module Gobstones
1
+ require 'gobstones/runner/errors/empty_cell_error'
2
2
 
3
+ module Gobstones
3
4
  module Runner
4
-
5
5
  class Cell
6
-
7
6
  def initialize
8
- @values = { Azul => 0, Negro => 0, Rojo => 0, Verde => 0 }
7
+ @values = Hash[Color.all.map { |color| [color, 0] }]
9
8
  end
10
9
 
11
10
  def put(color)
12
- check color
11
+ check(color)
13
12
  lookup(color) { |value| value + 1 }
14
13
  end
15
14
 
16
15
  def take_out(color)
17
- check color
16
+ check(color)
18
17
  raise EmptyCellError unless are_there_balls?(color)
18
+
19
19
  lookup(color) { |value| value - 1 }
20
20
  end
21
21
 
22
22
  def are_there_balls?(color)
23
- check color
24
- number_of_balls(color) > 0
23
+ check(color)
24
+ number_of_balls(color).positive?
25
25
  end
26
26
 
27
27
  def number_of_balls(color)
28
- check color
29
- lookup color
28
+ check(color)
29
+ lookup(color)
30
30
  end
31
31
 
32
32
  def empty!
@@ -34,15 +34,13 @@ module Gobstones
34
34
  end
35
35
 
36
36
  def empty?
37
- @values.values.all? { |value| value.zero? }
37
+ @values.values.all?(&:zero?)
38
38
  end
39
39
 
40
40
  def clone
41
41
  self.class.new.tap do |copy|
42
- [Azul.new, Negro.new, Rojo.new, Verde.new].each do |color|
43
- number_of_balls(color).times do
44
- copy.put color
45
- end
42
+ Color.all.map(&:new).each do |color|
43
+ number_of_balls(color).times { copy.put(color) }
46
44
  end
47
45
  end
48
46
  end
@@ -50,8 +48,7 @@ module Gobstones
50
48
  private
51
49
 
52
50
  def check(color)
53
- raise "'#{color}' is not a color" \
54
- unless [Azul, Negro, Rojo, Verde].include? color.class
51
+ raise "'#{color}' is not a color" unless Color.all.include?(color.class)
55
52
  end
56
53
 
57
54
  def lookup(color)
@@ -62,9 +59,6 @@ module Gobstones
62
59
  @values[value]
63
60
  end
64
61
  end
65
-
66
62
  end
67
-
68
63
  end
69
-
70
64
  end
@@ -3,6 +3,6 @@ require 'gobstones/runner/errors/definition_not_found_error'
3
3
  require 'gobstones/runner/errors/empty_cell_error'
4
4
  require 'gobstones/runner/errors/gobstones_runtime_error'
5
5
  require 'gobstones/runner/errors/gobstones_type_error'
6
- require 'gobstones/runner/errors/undefined_variable_error'
7
6
  require 'gobstones/runner/errors/out_of_board_error'
7
+ require 'gobstones/runner/errors/undefined_variable_error'
8
8
  require 'gobstones/runner/errors/wrong_arguments_error'
@@ -1,11 +1,6 @@
1
1
  module Gobstones
2
-
3
2
  module Runner
4
-
5
3
  class BoomError < StandardError
6
-
7
4
  end
8
-
9
5
  end
10
-
11
6
  end
@@ -1,19 +1,19 @@
1
1
  module Gobstones
2
-
3
2
  module Runner
4
-
5
3
  class DefinitionNotFound < StandardError
4
+ # TODO indicate if it is coming from a procedure or function
5
+
6
+ def initialize(definition_name)
7
+ @definition_name = definition_name
8
+ end
6
9
 
7
- def self.new(definition_name)
8
- super(message_for(definition_name))
10
+ def message
11
+ self.class.message_for(@definition_name)
9
12
  end
10
13
 
11
14
  def self.message_for(definition_name)
12
15
  "definition named '#{definition_name}' not found in program"
13
16
  end
14
-
15
17
  end
16
-
17
18
  end
18
-
19
19
  end
@@ -1,11 +1,6 @@
1
1
  module Gobstones
2
-
3
2
  module Runner
4
-
5
3
  class EmptyCellError < StandardError
6
-
7
4
  end
8
-
9
5
  end
10
-
11
6
  end
@@ -1,11 +1,6 @@
1
1
  module Gobstones
2
-
3
2
  module Runner
4
-
5
3
  class GobstonesRuntimeError < StandardError
6
-
7
4
  end
8
-
9
5
  end
10
-
11
6
  end
@@ -1,11 +1,6 @@
1
1
  module Gobstones
2
-
3
2
  module Runner
4
-
5
- class GobstonesTypeError < StandardError
6
-
7
- end
8
-
3
+ # TODO instantiate with the statement in which this exception occurs
4
+ GobstonesTypeError = Class.new(StandardError)
9
5
  end
10
-
11
6
  end
@@ -1,11 +1,6 @@
1
1
  module Gobstones
2
-
3
2
  module Runner
4
-
5
3
  class OutOfBoardError < StandardError
6
-
7
4
  end
8
-
9
5
  end
10
-
11
6
  end
@@ -1,11 +1,13 @@
1
1
  module Gobstones
2
-
3
2
  module Runner
4
-
5
3
  class UndefinedVariableError < StandardError
4
+ def self.for(variable_name)
5
+ new(undefined_variable_message_for(variable_name))
6
+ end
6
7
 
8
+ def self.undefined_variable_message_for(variable_name)
9
+ "Undefined variable: #{variable_name}"
10
+ end
7
11
  end
8
-
9
12
  end
10
-
11
13
  end
@@ -1,11 +1,6 @@
1
1
  module Gobstones
2
-
3
2
  module Runner
4
-
5
3
  class WrongArgumentsError < StandardError
6
-
7
4
  end
8
-
9
5
  end
10
-
11
6
  end
@@ -1,11 +1,10 @@
1
1
  require 'gobstones/runner/head'
2
+ require 'gobstones/runner/errors/undefined_variable_error'
3
+ require 'error_handling_protocol'
2
4
 
3
5
  module Gobstones
4
-
5
6
  module Runner
6
-
7
7
  class ExecutionContext
8
-
9
8
  def initialize
10
9
  @values = {}
11
10
  end
@@ -15,7 +14,7 @@ module Gobstones
15
14
  end
16
15
 
17
16
  def get(variable_name)
18
- @values[variable_name] || undefined_variable_error
17
+ @values[variable_name] || undefined_variable_error(variable_name)
19
18
  end
20
19
 
21
20
  def clear(variable_name)
@@ -23,27 +22,25 @@ module Gobstones
23
22
  end
24
23
 
25
24
  def has_variable_named?(name)
26
- @values.keys.any? { |variable| variable.named? name }
25
+ @values.keys.any? { |variable| variable.named?(name) }
27
26
  end
28
27
 
29
28
  def program_context
30
- raise 'subclass responsibility'
29
+ subclass_responsibility
31
30
  end
32
31
 
33
32
  protected
34
33
 
35
- def undefined_variable_error
36
- raise UndefinedVariableError
34
+ def undefined_variable_error(variable_name)
35
+ raise UndefinedVariableError.for(variable_name)
37
36
  end
38
-
39
37
  end
40
38
 
41
39
  class ProgramExecutionContext < ExecutionContext
42
-
43
40
  attr_reader :head
44
41
 
45
42
  def self.for(program)
46
- self.new program
43
+ new(program)
47
44
  end
48
45
 
49
46
  def initialize(program)
@@ -54,9 +51,8 @@ module Gobstones
54
51
 
55
52
  def definition_named(name, found_block, not_found_block)
56
53
  if_none = proc { return not_found_block.call }
57
- found_definition = @program.definitions.detect(if_none) \
58
- { |definition| definition.named? name }
59
- found_block.call found_definition
54
+ found_definition = @program.definitions.detect(if_none) { |definition| definition.named?(name) }
55
+ found_block.call(found_definition)
60
56
  end
61
57
 
62
58
  def program_context
@@ -66,13 +62,11 @@ module Gobstones
66
62
  def board
67
63
  head.board
68
64
  end
69
-
70
65
  end
71
66
 
72
67
  class ProcedureExecutionContext < ExecutionContext
73
-
74
68
  def self.based_on(outer_context)
75
- new outer_context
69
+ new(outer_context)
76
70
  end
77
71
 
78
72
  def initialize(outer_context)
@@ -87,15 +81,13 @@ module Gobstones
87
81
  def program_context
88
82
  @outer_context.program_context
89
83
  end
90
-
91
84
  end
92
85
 
93
86
  class FunctionExecutionContext < ExecutionContext
94
-
95
87
  attr_reader :head
96
88
 
97
89
  def self.based_on(outer_context)
98
- new outer_context
90
+ new(outer_context)
99
91
  end
100
92
 
101
93
  def initialize(outer_context)
@@ -107,33 +99,24 @@ module Gobstones
107
99
  def program_context
108
100
  @outer_context.program_context
109
101
  end
110
-
111
102
  end
112
103
 
113
104
  class NullExecutionContext < ExecutionContext
114
-
115
- def set(variable_name, value)
116
-
117
- end
105
+ def set(variable_name, value); end
118
106
 
119
107
  def get(variable_name)
120
- undefined_variable_error
108
+ undefined_variable_error(variable_name)
121
109
  end
122
110
 
123
- def clear(variable_name)
124
-
125
- end
111
+ def clear(variable_name); end
126
112
 
127
- def has_variable_named?(variable_name)
113
+ def has_variable_named?(_variable_name)
128
114
  false
129
115
  end
130
116
 
131
117
  def program_context
132
118
  raise 'a null execution does not know its program context'
133
119
  end
134
-
135
120
  end
136
-
137
121
  end
138
-
139
122
  end