Skip to content
This repository was archived by the owner on Sep 25, 2023. It is now read-only.

Chore mulang 6 #2

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test and deploy

on:
- push
- workflow_dispatch

jobs:
test_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@21351ecc0a7c196081abca5dc55b08f085efe09a
with:
ruby-version: 2.6.3
- name: Install dependencies
run: bundle install
- name: Run tests
run: bundle exec rake
- name: Deploy
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push *.gem
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"

2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1
2.6.3
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions lib/mulang/php.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'ast'
require 'parser/current'
require 'mumukit/core'

require_relative "./php/version"
Expand All @@ -11,7 +10,7 @@ def self.parse(php_ast)
end

def self.language
Mumukit::Language::External.new { |it| parse(it) }
Mulang::Language::External.new { |it| parse(it) }
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/mulang/php/ast_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ def define_binary_operators!

if it[:supports_assign?]
self.class.redefine_method(:"on_Expr_AssignOp_#{it[:name]}") { |node|
binary_operator "#{it[:token]}=", process(node[:var]), process(node[:expr])
binary_application "#{it[:token]}=", process(node[:var]), process(node[:expr])
}
end
}
end

def process_binary_operator(operator, node)
binary_operator operator, process(node[:left]), process(node[:right])
binary_application operator, process(node[:left]), process(node[:right])
end

# ---
Expand Down Expand Up @@ -102,7 +102,7 @@ def on_Expr_ConstFetch(node)
when 'false'
ms :MuBool, false
when 'null'
ms :None
ms :MuNil
else
ms :Reference, value
end
Expand Down Expand Up @@ -134,20 +134,20 @@ def on_Param(node)
# OPERATORS

def on_Expr_BinaryOp_Equal(node)
ms :Equal, [process(node[:left]), process(node[:right])]
ms :Application, [primitive(:Equal), [process(node[:left]), process(node[:right])]]
end

def on_Expr_BinaryOp_NotEqual(node)
ms :NotEqual, [process(node[:left]), process(node[:right])]
ms :Application, [primitive(:NotEqual), [process(node[:left]), process(node[:right])]]
end

def on_Expr_PostInc(node)
binary_operator '+', process(node[:var]), ms(:MuNumber, 1)
binary_application '+', process(node[:var]), ms(:MuNumber, 1)
end
alias on_Expr_PreInc on_Expr_PostInc

def on_Expr_PostDec(node)
binary_operator '-', process(node[:var]), ms(:MuNumber, 1)
binary_application '-', process(node[:var]), ms(:MuNumber, 1)
end
alias on_Expr_PreDec on_Expr_PostDec

Expand Down
54 changes: 3 additions & 51 deletions lib/mulang/php/sexp.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,7 @@
require "mulang"

module Mulang::PHP
module Sexp
def sequence(*contents)
if contents.empty?
ms(:None)
elsif contents.size == 1
contents[0]
else
ms(:Sequence, *contents)
end
end

def ms(tag, *contents)
if contents.empty?
{tag: tag}
elsif contents.size == 1
{tag: tag, contents: contents.first}
else
{tag: tag, contents: contents}
end
end

def simple_function(name, args, body)
callable :Function, name, args, body
end

def simple_method(name, args, body)
callable :Method, name, args, body
end

def callable(type, name, args, body)
{
tag: type,
contents: [
name,
[
[ args, {tag: :UnguardedBody, contents: body }]
]
]
}
end

def application(name, args)
ms :Application, [ms(:Reference, name), args]
end

def binary_operator(operator, left, right)
application operator, [left, right]
end

def simple_send(sender, message, args)
ms(:Send, sender, ms(:Reference, message), args)
end
include Mulang::Sexp
end
end
2 changes: 1 addition & 1 deletion lib/mulang/php/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Mulang
module PHP
VERSION = "1.0.0"
VERSION = "0.2.0"
end
end
11 changes: 5 additions & 6 deletions mulang-php.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require 'mulang/php/version'
Gem::Specification.new do |spec|
spec.name = "mulang-php"
spec.version = Mulang::PHP::VERSION
spec.authors = ["Franco Leonardo Bulgarelli"]
spec.email = ["franco@mumuki.org"]
spec.authors = ["Rodrigo Alfonso", "Franco Leonardo Bulgarelli"]
spec.email = ["rodri042@gmail.com", "franco@mumuki.org"]

spec.summary = "PHP integration for the Mulang Language Analyzer"
spec.description = "PHP - Mulang Parser"
Expand All @@ -21,13 +21,12 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.14"
spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "pry"

spec.add_dependency "parser"
spec.add_dependency "ast"
spec.add_dependency "ast", "~> 2.4"
spec.add_dependency "mumukit-core", "~> 1.0"
spec.add_dependency "mulang", "~> 4.0"
spec.add_dependency "mulang", "~> 6.0"
end
4 changes: 2 additions & 2 deletions spec/mulang/operators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
]
} }

it { expect(result).to eq ms :Equal, ms(:MuString, 'h'), ms(:MuString, 'a') }
it { expect(result).to eq ms :Application, primitive(:Equal), [ms(:MuString, 'h'), ms(:MuString, 'a')] }
end

context '!=' do
Expand All @@ -56,7 +56,7 @@
]
} }

it { expect(result).to eq ms :NotEqual, ms(:MuString, 'h'), ms(:MuString, 'a') }
it { expect(result).to eq ms :Application, primitive(:NotEqual), [ms(:MuString, 'h'), ms(:MuString, 'a')] }
end

context '+' do
Expand Down
2 changes: 1 addition & 1 deletion spec/mulang/statements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
it {
expect(result).to eq ms(
:If,
ms(:Equal, ms(:MuNumber, 2), ms(:MuNumber, 3)),
ms(:Application, primitive(:Equal), [ms(:MuNumber, 2), ms(:MuNumber, 3)]),
sequence(
ms(:Print, ms(:MuString, 'Oh no!')),
ms(:Print, ms(:MuString, 'Math is broken!')),
Expand Down
2 changes: 1 addition & 1 deletion spec/mulang/values_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
]
} }

it { expect(result).to eq ms :None }
it { expect(result).to eq ms :MuNil }
end

context 'arrays' do
Expand Down