diff --git a/lib/vm/parser.rb b/lib/vm/parser.rb index a8eda234..4ec12f35 100644 --- a/lib/vm/parser.rb +++ b/lib/vm/parser.rb @@ -45,7 +45,7 @@ module Vm ((name.as(:param) >> (comma >> name.as(:param)).repeat(0)).maybe).as(:params) >> rparen } - - rule(:root) { func.repeat(0) >> expression } + root :args +# rule(:root) { func.repeat(0) >> expression } end end diff --git a/test/test_nodes.rb b/test/test_nodes.rb index 6c960142..dc85d894 100644 --- a/test/test_nodes.rb +++ b/test/test_nodes.rb @@ -1,98 +1,33 @@ require_relative "helper" -require 'minitest/spec' -include Vm -class FakeBuilder - attr_reader :result +#testing that parsing strings that we know to be correct returns the nodes we expect +# in a way the combination of test_parser and test_transform - Asm::InstructionTools::REGISTERS.each do |reg , number| - define_method(reg) { Asm::Register.new(reg , number) } +class NodesCase < MiniTest::Test + + def setup + @parser = Vm::Parser.new + @transform = Vm::Transform.new end - - def initialize - @result = '' + + def parse string + syntax = @parser.parse(string) + tree = @transform.apply(syntax) + tree end - - def class_builder - 'example' + + def test_number + tree = parse "42" + assert tree.is_a? Vm::NumberExpression + assert_equal 42 , tree.value end - - def int - 'int' - end - - def method_missing(name, *args, &block) - @result += ([name] + args.flatten).join(', ').sub(',', '') - @result += "\n" - block.call(self) if name.to_s == 'public_static_method' + def test_args + tree = parse "( 42 )" + assert tree.is_a? Hash + assert tree[:args].is_a? Vm::NumberExpression + assert_equal 42 , tree[:args].value end end -describe 'Nodes' do - before do - @context = Hash.new - @builder = FakeBuilder.new - end - it 'emits a number' do - input = Vm::NumberExpression.new 42 - expected = <