diff --git a/lib/parser/parser.rb b/lib/parser/parser.rb index b9d43b63..99420b83 100644 --- a/lib/parser/parser.rb +++ b/lib/parser/parser.rb @@ -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? } diff --git a/lib/parser/transform.rb b/lib/parser/transform.rb index 314a139f..4dc529ec 100644 --- a/lib/parser/transform.rb +++ b/lib/parser/transform.rb @@ -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 diff --git a/test/test_all.rb b/test/test_all.rb new file mode 100644 index 00000000..04175afc --- /dev/null +++ b/test/test_all.rb @@ -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" diff --git a/test/test_nodes.rb b/test/test_nodes.rb index 5d9a1d3c..8ac05f99 100644 --- a/test/test_nodes.rb +++ b/test/test_nodes.rb @@ -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 diff --git a/test/test_parser.rb b/test/test_parser.rb index 37ed714e..f4e35435 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -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 diff --git a/test/test_transform.rb b/test/test_transform.rb index 206253c3..add1fb9a 100644 --- a/test/test_transform.rb +++ b/test/test_transform.rb @@ -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