diff --git a/lib/gobstones/lang/commands/command_block.rb b/lib/gobstones/lang/commands/command_block.rb index 4ee2e1a..3ebdb6b 100644 --- a/lib/gobstones/lang/commands/command_block.rb +++ b/lib/gobstones/lang/commands/command_block.rb @@ -8,26 +8,26 @@ class CmdBlock include Gobstones::EqualByClass - attr_reader :cmds + attr_reader :commands def self.empty self.new [] end - def initialize(cmds) - @cmds = cmds + def initialize(commands) + @commands = commands end def ==(other) - super(other) && self.cmds == other.cmds + super(other) && self.commands == other.commands end def empty? - cmds.empty? + commands.empty? end def evaluate(context) - cmds.each { |cmd| cmd.evaluate context } + commands.each { |command| command.evaluate context } end end diff --git a/lib/gobstones/parser/ast/ast.rb b/lib/gobstones/parser/ast/ast.rb index 0cf4b6f..958f450 100644 --- a/lib/gobstones/parser/ast/ast.rb +++ b/lib/gobstones/parser/ast/ast.rb @@ -201,10 +201,10 @@ def self.ast_node(name, &value_block) Program.new defs, main_def.value end - def create_commands(cmds) - cmds.elements.map { |node| node.command.value } + def create_commands(commands) + commands.elements.map { |node| node.command.value } end end -end \ No newline at end of file +end diff --git a/spec/parser/command_block_spec.rb b/spec/parser/command_block_spec.rb index 5e5782f..a284f31 100644 --- a/spec/parser/command_block_spec.rb +++ b/spec/parser/command_block_spec.rb @@ -12,7 +12,7 @@ '{ Skip }'.should be_parsed_as(:command).and_return(cmd_block) end - it "should parse a block with many simple cmds" do + it "should parse a block with many simple commands" do first = Poner.new Verde.new second = Boom.new "error" third = Mover.new Oeste.new @@ -25,7 +25,7 @@ }'.should be_parsed_as(:command).and_return(cmd_block) end - it "should allow ; between cmds" do + it "should allow ; between commands" do first = Poner.new Verde.new second = Boom.new "error" third = Mover.new Oeste.new @@ -36,7 +36,7 @@ }'.should be_parsed_as(:command).and_return(cmd_block) end - it "should parse a block with simple and complex cmds" do + it "should parse a block with simple and complex commands" do first = ProcedureCall.new 'Proc', [] second = IfCmd.new True.new, CmdBlock.empty cmd_block = CmdBlock.new [first, second] @@ -47,4 +47,4 @@ }'.should be_parsed_as(:command).and_return(cmd_block) end -end \ No newline at end of file +end diff --git a/spec/parser/if_command_spec.rb b/spec/parser/if_command_spec.rb index 784b78f..99b0c52 100644 --- a/spec/parser/if_command_spec.rb +++ b/spec/parser/if_command_spec.rb @@ -3,7 +3,7 @@ describe "if" do it "should parse a statement with a simple boolean and an empty block" do - if_cmd = IfCmd.new True.new, CmdBlock.new([]) + if_cmd = IfCmd.new True.new, CmdBlock.empty 'if (True) {}'.should be_parsed_as(:command).and_return(if_cmd) 'if (True) { @@ -12,7 +12,7 @@ {}'.should be_parsed_as(:command).and_return(if_cmd) end - it "should parse a statement with a simple boolean and a block with cmds" do + it "should parse a statement with a simple boolean and a block with commands" do cmd_block = CmdBlock.new [Poner.new(Verde.new), Skip.new] if_cmd = IfCmd.new False.new, cmd_block @@ -23,7 +23,7 @@ it "should parse a statement with a complex boolean expression" do and_expr = And.new VarName.new('a'), False.new exp = Or.new PuedeMover.new(Norte.new), ParenthesesExpr.new(and_expr) - if_cmd = IfCmd.new exp, CmdBlock.new([]) + if_cmd = IfCmd.new exp, CmdBlock.empty 'if (puedeMover(Norte) || (a && False)) {}'. should be_parsed_as(:command).and_return(if_cmd) @@ -35,7 +35,7 @@ it "should parse a statement with an else block" do else_block = CmdBlock.new [Mover.new(Norte.new)] - if_else_cmd = IfElseCmd.new False.new, CmdBlock.new([]), else_block + if_else_cmd = IfElseCmd.new False.new, CmdBlock.empty, else_block 'if (False) { } else { Mover(Norte) }'. should be_parsed_as(:command).and_return(if_else_cmd) @@ -43,4 +43,4 @@ end -end \ No newline at end of file +end diff --git a/spec/parser/while_command_spec.rb b/spec/parser/while_command_spec.rb index 234090e..a096595 100644 --- a/spec/parser/while_command_spec.rb +++ b/spec/parser/while_command_spec.rb @@ -1,7 +1,7 @@ describe Gobstones::Parser, "while statements" do it "should parse a statement with a simple boolean and an empty block" do - while_cmd = WhileCmd.new True.new, CmdBlock.new([]) + while_cmd = WhileCmd.new True.new, CmdBlock.empty 'while (True) {}'.should be_parsed_as(:command).and_return(while_cmd) 'while (True) { @@ -10,7 +10,7 @@ {}'.should be_parsed_as(:command).and_return(while_cmd) end - it "should parse a statement with a simple boolean and a block with cmds" do + it "should parse a statement with a simple boolean and a block with commands" do cmd_block = CmdBlock.new [Poner.new(Verde.new), Skip.new] while_cmd = WhileCmd.new False.new, cmd_block @@ -21,10 +21,10 @@ it "should parse a statement with a complex boolean expression" do and_expr = And.new VarName.new('a'), False.new exp = Or.new PuedeMover.new(Norte.new), ParenthesesExpr.new(and_expr) - while_cmd = WhileCmd.new exp, CmdBlock.new([]) + while_cmd = WhileCmd.new exp, CmdBlock.empty 'while (puedeMover(Norte) || (a && False)) {}'. should be_parsed_as(:command).and_return(while_cmd) end -end \ No newline at end of file +end