fixed tests (namespacing) and finally created a test_all

This commit is contained in:
Torsten Ruger 2014-04-27 15:44:34 +03:00
parent 436a5dac5a
commit d72c9a3bb0
6 changed files with 18 additions and 14 deletions

View File

@ -1,5 +1,5 @@
module Vm
module Parser
class Parser < Parslet::Parser
rule(:name) { match('[a-z]').repeat(1).as(:name) >> space? }
rule(:number) { match('[0-9]').repeat(1).as(:number) >> space? }

View File

@ -1,33 +1,33 @@
require 'parslet'
require 'vm/nodes'
module Vm
module Parser
class Transform < Parslet::Transform
rule(:number => simple(:value)) { NumberExpression.new(value.to_i) }
rule(:name => simple(:name)) { NameExpression.new(name.to_s) }
rule(:number => simple(:value)) { Vm::NumberExpression.new(value.to_i) }
rule(:name => simple(:name)) { Vm::NameExpression.new(name.to_s) }
rule(:arg => simple(:arg)) { arg }
rule(:args => sequence(:args)) { args }
rule(:funcall => simple(:funcall),
:args => simple(:args)) { FuncallExpression.new(funcall.name, [args]) }
:args => simple(:args)) { Vm::FuncallExpression.new(funcall.name, [args]) }
rule(:funcall => simple(:funcall),
:args => sequence(:args)) { FuncallExpression.new(funcall.name, args) }
:args => sequence(:args)) { Vm::FuncallExpression.new(funcall.name, args) }
rule(:cond => simple(:cond),
:if_true => {:body => simple(:if_true)},
:if_false => {:body => simple(:if_false)}) { ConditionalExpression.new(cond, if_true, if_false) }
:if_false => {:body => simple(:if_false)}) { Vm::ConditionalExpression.new(cond, if_true, if_false) }
rule(:param => simple(:param)) { param }
rule(:params => sequence(:params)) { params }
rule(:func => simple(:func),
:params => simple(:name),
:body => simple(:body)) { FunctionExpression.new(func.name, [name], body) }
:body => simple(:body)) { Vm::FunctionExpression.new(func.name, [name], body) }
rule(:func => simple(:func),
:params => sequence(:params),
:body => simple(:body)) { FunctionExpression.new(func.name, params, body) }
:body => simple(:body)) { Vm::FunctionExpression.new(func.name, params, body) }
end
end

5
test/test_all.rb Normal file
View File

@ -0,0 +1,5 @@
require_relative "test_crystal"
require_relative "test_nodes"
require_relative "test_parser"
require_relative "test_small_program"
require_relative "test_transform"

View File

@ -7,8 +7,8 @@ require_relative "helper"
class NodesCase < MiniTest::Test
def setup
@parser = Vm::Parser.new
@transform = Vm::Transform.new
@parser = Parser::Parser.new
@transform = Parser::Transform.new
end
def parse string

View File

@ -5,7 +5,7 @@ include Vm
describe Parser do
before do
@parser = Vm::Parser.new
@parser = Parser::Parser.new
end
it 'reads a number' do

View File

@ -1,12 +1,11 @@
require_relative 'helper'
require 'vm/transform'
include Vm
class TransformTest < MiniTest::Test
def setup
@transform = Vm::Transform.new
@transform = Parser::Transform.new
end
def check_equals