mulang-ruby 4.0.2 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33cc9575fa24b31d336ce8101fc680c7f1f86b2796f80ef769833189b331fa27
4
- data.tar.gz: ace4b0be67c260bc1205fcf4e95be821eb270ac5f28b4fea6b9dea22bf74e3ad
3
+ metadata.gz: 534bc3c5a44381a2ba606c51162b1ccc664a20cdfe20470e3cd1c328fd43285b
4
+ data.tar.gz: abddef43c33abb13f13ae185ba94e310d384e0257fb7a62a1192b18e8b0bd6b9
5
5
  SHA512:
6
- metadata.gz: e5ee8d009b6670930b98e260cb9455e80561483515f06ed9c02f837186ed4a9ae89ff82639e02f187bcbae8e6b17791cb19495565a74b4b2f7432edcdeafcf2b
7
- data.tar.gz: 5072f9a4f05803bcf5385674859350c133873c6269845e663c75b2db569328fcebe3b85cb581900a72ae2f2a9bf5df4c8c4a2947a11b33ef69f59e4306629f4b
6
+ metadata.gz: 523da2d9961e079ddc1061988dfee999ae73f753ac386588066f8942676eb01e66725af10777da41a31f5ecc2037841e5574a7c11ceb2387bec245a99ee40973
7
+ data.tar.gz: 6eba9d4083da3c9e63932c491c7b90d4b8b95ebe7e50fbb7c9bd99206e7ee56d41c938920ece70cdefc0baa72d6413f882991332e4efd0c5fe6485fa7e1331f8
@@ -0,0 +1,31 @@
1
+ name: Test and deploy
2
+
3
+ on:
4
+ - push
5
+ - workflow_dispatch
6
+
7
+ jobs:
8
+ test_and_deploy:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Set up Ruby
13
+ uses: ruby/setup-ruby@21351ecc0a7c196081abca5dc55b08f085efe09a
14
+ with:
15
+ ruby-version: 2.6.3
16
+ - name: Install dependencies
17
+ run: bundle install
18
+ - name: Run tests
19
+ run: bundle exec rake
20
+ - name: Deploy
21
+ if: ${{ startsWith(github.ref, 'refs/tags/v') }}
22
+ run: |
23
+ mkdir -p $HOME/.gem
24
+ touch $HOME/.gem/credentials
25
+ chmod 0600 $HOME/.gem/credentials
26
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
27
+ gem build *.gemspec
28
+ gem push *.gem
29
+ env:
30
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
31
+
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/lib/mulang/ruby.rb CHANGED
@@ -1,17 +1,23 @@
1
1
  require 'ast'
2
- require 'parser/ruby23'
3
2
  require 'mumukit/core'
4
-
3
+ require 'parser/ruby26'
5
4
  require_relative "./ruby/version"
6
5
 
7
6
  module Mulang
8
7
  module Ruby
9
- def self.parse(ruby_code)
10
- Mulang::Ruby::AstProcessor.new.process Mulang::Ruby::SexpParser.parser(ruby_code)
8
+ def self.parse(ruby_code, parser_class: nil)
9
+ parser_class ||= default_parser_class
10
+ Mulang::Ruby::AstProcessor.new.process Mulang::Ruby::SexpParser.parser(ruby_code, parser_class)
11
+ end
12
+
13
+ def self.language(parser_class: nil)
14
+ Mulang::Language::External.new("Ruby") { |it| parse(it, parser_class: parser_class) }
11
15
  end
12
16
 
13
- def self.language
14
- Mulang::Language::External.new { |it| parse(it) }
17
+ private
18
+
19
+ def self.default_parser_class
20
+ Parser::Ruby26
15
21
  end
16
22
  end
17
23
  end
@@ -3,9 +3,12 @@ module Mulang::Ruby
3
3
  include AST::Sexp
4
4
  include Mulang::Ruby::Sexp
5
5
 
6
+ def process(node)
7
+ node.nil? ? none : super
8
+ end
9
+
6
10
  def on_class(node)
7
11
  name, superclass, body = *node
8
- body ||= s(:nil)
9
12
 
10
13
  _, class_name = *name
11
14
  _, superclass_name = *superclass
@@ -15,7 +18,6 @@ module Mulang::Ruby
15
18
 
16
19
  def on_module(node)
17
20
  name, body = *node
18
- body ||= s(:nil)
19
21
 
20
22
  _, module_name = *name
21
23
 
@@ -23,18 +25,22 @@ module Mulang::Ruby
23
25
  end
24
26
 
25
27
  def on_begin(node)
26
- sequence(*process_all(node))
28
+ if node.children.size == 1 && node.children[0].nil?
29
+ none # ruby < 2.6 only
30
+ else
31
+ sequence(*process_all(node))
32
+ end
27
33
  end
28
34
 
29
35
  def on_rescue(node)
30
36
  try, *catch, _ = *node
31
- ms :Try, process(try), process_all(catch), ms(:MuNil)
37
+ ms :Try, process(try), process_all(catch), none
32
38
  end
33
39
 
34
40
  def on_resbody(node)
35
41
  patterns, variable, block = *node
36
42
 
37
- [to_mulang_pattern(patterns, variable), process(block) || ms(:MuNil)]
43
+ [to_mulang_pattern(patterns, variable), process(block) || none]
38
44
  end
39
45
 
40
46
  def _
@@ -109,20 +115,18 @@ module Mulang::Ruby
109
115
 
110
116
  def on_defs(node)
111
117
  _target, id, args, body = *node
112
- body ||= s(:nil)
113
118
 
114
119
  simple_method id, process_all(args), process(body)
115
120
  end
116
121
 
117
122
  def on_def(node)
118
123
  id, args, body = *node
119
- body ||= s(:nil)
120
124
 
121
125
  case id
122
126
  when :equal?, :eql?, :==
123
- mu_method :EqualMethod, process_all(args), process(body)
127
+ primitive_method :Equal, process_all(args), process(body)
124
128
  when :hash
125
- mu_method :HashMethod, process_all(args), process(body)
129
+ primitive_method :Hash, process_all(args), process(body)
126
130
  else
127
131
  simple_method id, process_all(args), process(body)
128
132
  end
@@ -130,7 +134,7 @@ module Mulang::Ruby
130
134
 
131
135
  def on_block(node)
132
136
  send, parameters, body = *node
133
- lambda = ms(:Lambda, process_all(parameters), process(body) || ms(:MuNil))
137
+ lambda = ms(:Lambda, process_all(parameters), process(body) || none)
134
138
  handle_send_with_args send, [lambda]
135
139
  end
136
140
 
@@ -139,7 +143,7 @@ module Mulang::Ruby
139
143
  end
140
144
 
141
145
  def on_nil(_)
142
- ms :MuNil
146
+ mnil
143
147
  end
144
148
 
145
149
  def on_self(_)
@@ -148,14 +152,18 @@ module Mulang::Ruby
148
152
 
149
153
  def on_arg(node)
150
154
  name, _ = *node
151
- ms :VariablePattern, name
155
+ if name.is_a? Parser::AST::Node
156
+ process name
157
+ else
158
+ ms :VariablePattern, name
159
+ end
152
160
  end
153
161
 
154
162
  def on_for(node)
155
163
  variable, list, block = *node
156
164
 
157
165
  pattern = ms(:VariablePattern, variable.children.first)
158
- ms(:For, [ms(:Generator, pattern, process(list))], process(block) || ms(:MuNil))
166
+ ms(:For, [ms(:Generator, pattern, process(list))], process(block) || none)
159
167
  end
160
168
 
161
169
  def on_optarg(node)
@@ -184,8 +192,6 @@ module Mulang::Ruby
184
192
 
185
193
  def on_if(node)
186
194
  condition, if_true, if_false = *node
187
- if_true ||= s(:nil)
188
- if_false ||= s(:nil)
189
195
 
190
196
  ms :If, process(condition), process(if_true), process(if_false)
191
197
  end
@@ -217,7 +223,7 @@ module Mulang::Ruby
217
223
 
218
224
  def var_assignment(assignee, message, value)
219
225
  id = assignee.to_a.first
220
- ms :Assignment, id, simple_send(ms(:Reference, id), message, [process(value)])
226
+ ms :Assignment, id, ms(:Send, ms(:Reference, id), message_reference(message), [process(value)])
221
227
  end
222
228
 
223
229
  def property_assignment(assignee, message, value)
@@ -229,9 +235,9 @@ module Mulang::Ruby
229
235
  def reasign(accessor, args, id, message, value)
230
236
  simple_send id,
231
237
  "#{accessor}=".to_sym,
232
- args + [simple_send(
238
+ args + [ms(:Send,
233
239
  simple_send(id, accessor, args),
234
- message,
240
+ message_reference(message),
235
241
  [value])]
236
242
  end
237
243
 
@@ -274,15 +280,29 @@ module Mulang::Ruby
274
280
  receptor, message, *args = *node
275
281
  receptor ||= s(:self)
276
282
 
277
- if message == :==
278
- message = {tag: :Equal}
279
- elsif message == :!=
280
- message = {tag: :NotEqual}
281
- else
282
- message = {tag: :Reference, contents: message}
283
+ ms :Send, process(receptor), message_reference(message), (process_all(args) + extra_args)
284
+ end
285
+
286
+ def message_reference(message)
287
+ case message
288
+ when :== then primitive :Equal
289
+ when :!= then primitive :NotEqual
290
+ when :! then primitive :Negation
291
+ when :'&&' then primitive :And
292
+ when :'||' then primitive :Or
293
+ when :hash then primitive :Hash
294
+ when :>= then primitive :GreatherOrEqualThan
295
+ when :> then primitive :GreatherThan
296
+ when :<= then primitive :LessOrEqualThan
297
+ when :< then primitive :LessThan
298
+ when :+ then primitive :Plus
299
+ when :- then primitive :Minus
300
+ when :* then primitive :Multiply
301
+ when :/ then primitive :Divide
302
+ when :length then primitive :Size
303
+ when :size then primitive :Size
304
+ else ms :Reference, message
283
305
  end
284
-
285
- ms :Send, process(receptor), message, (process_all(args) + extra_args)
286
306
  end
287
307
 
288
308
  end
@@ -1,48 +1,12 @@
1
+ require "mulang"
2
+
1
3
  module Mulang::Ruby
2
4
  module Sexp
3
- def sequence(*contents)
4
- if contents.empty?
5
- ms(:MuNil)
6
- elsif contents.size == 1
7
- contents[0]
8
- else
9
- ms(:Sequence, *contents)
10
- end
11
- end
5
+ include Mulang::Sexp
12
6
 
13
- def ms(tag, *contents)
14
- if contents.empty?
15
- {tag: tag}
16
- elsif contents.size == 1
17
- {tag: tag, contents: contents.first}
18
- else
19
- {tag: tag, contents: contents}
20
- end
21
- end
22
-
23
- def simple_method(name, args, body)
24
- {
25
- tag: :Method,
26
- contents: [
27
- name,
28
- [
29
- [ args, {tag: :UnguardedBody, contents: body }]
30
- ]
31
- ]
32
- }
33
- end
34
-
35
- def mu_method(tag, args, body)
36
- {
37
- tag: tag,
38
- contents: [
39
- [ args, {tag: :UnguardedBody, contents: body }]
40
- ]
41
- }
42
- end
43
-
44
- def simple_send(sender, message, args)
45
- ms(:Send, sender, {tag: :Reference, contents: message}, args)
7
+ def mnil
8
+ ms(:MuNil)
46
9
  end
47
10
  end
11
+
48
12
  end
@@ -3,9 +3,10 @@ module Mulang::Ruby
3
3
  Parser::Builders::Default.emit_lambda = true
4
4
  Parser::Builders::Default.emit_procarg0 = true
5
5
 
6
- def self.parser(ruby_code)
7
- parser = Parser::Ruby23.new
6
+ def self.parser(ruby_code, parser_class)
7
+ parser = parser_class.new
8
8
  parser.diagnostics.consumer = lambda {|it|}
9
+ parser.diagnostics.all_errors_are_fatal = true
9
10
  buffer = Parser::Source::Buffer.new('(string)')
10
11
  buffer.source = ruby_code
11
12
  parser.parse(buffer).tap do |result|
@@ -1,5 +1,5 @@
1
1
  module Mulang
2
2
  module Ruby
3
- VERSION = "4.0.2"
3
+ VERSION = "6.1.0"
4
4
  end
5
5
  end
data/mulang-ruby.gemspec CHANGED
@@ -21,13 +21,13 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.14"
24
+ spec.add_development_dependency "bundler", '>= 1.1', '< 3'
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
  spec.add_development_dependency "pry"
28
28
 
29
- spec.add_dependency "parser"
30
- spec.add_dependency "ast"
29
+ spec.add_dependency "parser", "~> 2.6"
30
+ spec.add_dependency "ast", "~> 2.4"
31
31
  spec.add_dependency "mumukit-core", "~> 1.0"
32
- spec.add_dependency "mulang", "~> 4.0"
32
+ spec.add_dependency "mulang", '~> 6.0', '>= 6.0.3'
33
33
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mulang-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Leonardo Bulgarelli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-11 00:00:00.000000000 Z
11
+ date: 2021-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '1.14'
22
+ version: '3'
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '1.14'
32
+ version: '3'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rake
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -70,30 +76,30 @@ dependencies:
70
76
  name: parser
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
- - - ">="
79
+ - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '0'
81
+ version: '2.6'
76
82
  type: :runtime
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
- - - ">="
86
+ - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: '0'
88
+ version: '2.6'
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: ast
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
- - - ">="
93
+ - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: '0'
95
+ version: '2.4'
90
96
  type: :runtime
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
- - - ">="
100
+ - - "~>"
95
101
  - !ruby/object:Gem::Version
96
- version: '0'
102
+ version: '2.4'
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: mumukit-core
99
105
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +120,20 @@ dependencies:
114
120
  requirements:
115
121
  - - "~>"
116
122
  - !ruby/object:Gem::Version
117
- version: '4.0'
123
+ version: '6.0'
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 6.0.3
118
127
  type: :runtime
119
128
  prerelease: false
120
129
  version_requirements: !ruby/object:Gem::Requirement
121
130
  requirements:
122
131
  - - "~>"
123
132
  - !ruby/object:Gem::Version
124
- version: '4.0'
133
+ version: '6.0'
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 6.0.3
125
137
  description: Ruby - Mulang Parser
126
138
  email:
127
139
  - franco@mumuki.org
@@ -129,9 +141,10 @@ executables: []
129
141
  extensions: []
130
142
  extra_rdoc_files: []
131
143
  files:
144
+ - ".github/workflows/test_and_deploy.yml"
132
145
  - ".gitignore"
133
146
  - ".rspec"
134
- - ".travis.yml"
147
+ - ".ruby-version"
135
148
  - CODE_OF_CONDUCT.md
136
149
  - COPYRIGHT.txt
137
150
  - Gemfile
data/.travis.yml DELETED
@@ -1,18 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.1
5
- before_install:
6
- # Extend Path
7
- - mkdir -p ~/.local/bin
8
- - export PATH=$HOME/.local/bin:$PATH
9
- # Install bundler
10
- - gem install bundler -v 1.14.6
11
- deploy:
12
- provider: rubygems
13
- api_key:
14
- secure: UReab6XV1hLEiB+qmV2z7urHDApuD8MLINMOXxjaU7X6jplHmTttgci+wuP3w8Q+oqAy1s97j270ofQszHogppOtxa+AZzmXvI9TPZ5XRJJXFNH4Bt5RguP/gIN2bZEmCESdbpsTC6w5gxvDAfSQTPSE0mO/MLY5xRUYja/RdmhxdrvQuzir+c9L+hzGT4ysoiJ7UXkaKEUsfi2ief9/XRflmzTytf+C0uNSjFbVo0JCB5StBJwxmaUAMH2F5LQTZPUBDu+/FFJJO3w/yyYcRrqsNxujqJozXQZAwsmR3myMxyKIOZFAGCeC22+6XKPDHDSBLnNsQzWFdCieUzgsd3jZJFYeorXY63Uv5cGa1F+S7tbLmdXHBlbSfN2e5g6AUse1HyFXqgzgVUUftgZ8Uv7Ttc+BN9R1uzxMTJ7ox1wGncc01rbfQ/KPD0W0XEwON18aiCYjM5XvVNb4F1W4e7mNk28tdrxIC6RNkScpKLg5E0td1xPRkRDo2ZO2KWRZGGrabzjr05TTTWrI1+YVx3Mm4N1RiirjC5HybdHy5JO7eLDYU/FIXlVRwjCN7LKnP42zUsic1Y5JCYNs1RzZdJlH5sQaC/boy0bi2pVbehh3BlAbdCQu/ckqla7RG0ab5Bbw01m4aNSO5PkdIksxAN6yuelKkFXrSrs3pXEr528=
15
- gem: mulang-ruby
16
- on:
17
- tags: true
18
- repo: mumuki/mulang-ruby