mulang-ruby 6.0.0 → 6.2.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: bffbfe0515ffc42d5a7cc62ac0c219f01efed7ca0a09867e081f87db7d60e17e
4
- data.tar.gz: b4b58bb43f77bf21979922180af6a1dbcd2b99b9400e6a67b41cea7d618e8428
3
+ metadata.gz: 310222a26a40c26d470baccbff896da1b2f1ecf871391c2a5b1fb1dbebd4ff26
4
+ data.tar.gz: 26396d194ccc29a39bb2982dd83c4debb4dccc95a504fe6cac80c581d5dd433d
5
5
  SHA512:
6
- metadata.gz: '0259e8d0bd2b6ae8782381eb98fa3025d461b0e7f5735547575af614bad2900b187b4dca409fa78d95554300fa2500513bbfcbf448501231008915aae7eb2b62'
7
- data.tar.gz: 3c3c1cf74dee097855440376b97a934e273523545a82a38ad1fc47778b3b8c4ed2e39333e39d2b51945fa748cb31b91c778d7f2d8d7d0e42a5c50c3ab5f3a877
6
+ metadata.gz: 67c0ecd31d721393beb7612cf56b8f31e1cfc5d51b0731ebd00b4f36026647992cb951afd3535707b9ed5ea7200bfb4cf0d632b5683f15f379d6116069d7d6dc
7
+ data.tar.gz: 9c4c5fea0ad0e708ca81fa8fc05b08bee69604865151458428e50fa09e99a17884d0f1366bffafeb3e2648d1202dfd7decf68a0595da9f19f03aaeaa9ad2da95
@@ -13,8 +13,8 @@ jobs:
13
13
  uses: ruby/setup-ruby@21351ecc0a7c196081abca5dc55b08f085efe09a
14
14
  with:
15
15
  ruby-version: 2.6.3
16
- - name: Install dependencies
17
- run: bundle install
16
+ bundler: 2.1.4
17
+ bundler-cache: true
18
18
  - name: Run tests
19
19
  run: bundle exec rake
20
20
  - name: Deploy
@@ -3,27 +3,55 @@ module Mulang::Ruby
3
3
  include AST::Sexp
4
4
  include Mulang::Ruby::Sexp
5
5
 
6
+ def initialize
7
+ @contexts = []
8
+ end
9
+
10
+ def process(node)
11
+ node.nil? ? none : super
12
+ end
13
+
6
14
  def on_class(node)
15
+ @contexts.push :class
16
+
7
17
  name, superclass, body = *node
8
- body ||= s(:nil)
9
18
 
10
19
  _, class_name = *name
11
20
  _, superclass_name = *superclass
12
21
 
13
22
  ms :Class, class_name, superclass_name, process(body)
23
+ ensure
24
+ @contexts.pop
25
+ end
26
+
27
+ def on_sclass(node)
28
+ @contexts.push :sclass
29
+
30
+ target, body = *node
31
+
32
+ ms :EigenClass, process(target), process(body)
33
+ ensure
34
+ @contexts.pop
14
35
  end
15
36
 
16
37
  def on_module(node)
38
+ @contexts.push :module
39
+
17
40
  name, body = *node
18
- body ||= s(:nil)
19
41
 
20
42
  _, module_name = *name
21
43
 
22
44
  ms :Object, module_name, process(body)
45
+ ensure
46
+ @contexts.pop
23
47
  end
24
48
 
25
49
  def on_begin(node)
26
- sequence(*process_all(node))
50
+ if node.children.size == 1 && node.children[0].nil?
51
+ none # ruby < 2.6 only
52
+ else
53
+ sequence(*process_all(node))
54
+ end
27
55
  end
28
56
 
29
57
  def on_rescue(node)
@@ -108,15 +136,23 @@ module Mulang::Ruby
108
136
  end
109
137
 
110
138
  def on_defs(node)
111
- _target, id, args, body = *node
112
- body ||= s(:nil)
139
+ target, id, args, body = *node
113
140
 
114
- simple_method id, process_all(args), process(body)
141
+ result = simple_method id, process_all(args), process(body)
142
+
143
+ if target.type == :self
144
+ if @contexts.last == :module
145
+ result
146
+ else
147
+ ms(:Decorator, [ms(:Classy)], result)
148
+ end
149
+ else
150
+ ms(:EigenClass, process(target), result)
151
+ end
115
152
  end
116
153
 
117
154
  def on_def(node)
118
155
  id, args, body = *node
119
- body ||= s(:nil)
120
156
 
121
157
  case id
122
158
  when :equal?, :eql?, :==
@@ -139,7 +175,7 @@ module Mulang::Ruby
139
175
  end
140
176
 
141
177
  def on_nil(_)
142
- ms :MuNil
178
+ mnil
143
179
  end
144
180
 
145
181
  def on_self(_)
@@ -148,7 +184,11 @@ module Mulang::Ruby
148
184
 
149
185
  def on_arg(node)
150
186
  name, _ = *node
151
- ms :VariablePattern, name
187
+ if name.is_a? Parser::AST::Node
188
+ process name
189
+ else
190
+ ms :VariablePattern, name
191
+ end
152
192
  end
153
193
 
154
194
  def on_for(node)
@@ -184,8 +224,6 @@ module Mulang::Ruby
184
224
 
185
225
  def on_if(node)
186
226
  condition, if_true, if_false = *node
187
- if_true ||= s(:nil)
188
- if_false ||= s(:nil)
189
227
 
190
228
  ms :If, process(condition), process(if_true), process(if_false)
191
229
  end
@@ -4,8 +4,9 @@ module Mulang::Ruby
4
4
  module Sexp
5
5
  include Mulang::Sexp
6
6
 
7
- def none
7
+ def mnil
8
8
  ms(:MuNil)
9
9
  end
10
10
  end
11
+
11
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 = "6.0.0"
3
+ VERSION = '6.2.0'
4
4
  end
5
5
  end
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
data/mulang-ruby.gemspec CHANGED
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "parser", "~> 2.6"
30
30
  spec.add_dependency "ast", "~> 2.4"
31
31
  spec.add_dependency "mumukit-core", "~> 1.0"
32
- spec.add_dependency "mulang", "~> 6.0"
32
+ spec.add_dependency "mulang", '~> 6.0', '>= 6.0.3'
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mulang-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.2.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: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2022-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -121,6 +121,9 @@ dependencies:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
123
  version: '6.0'
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 6.0.3
124
127
  type: :runtime
125
128
  prerelease: false
126
129
  version_requirements: !ruby/object:Gem::Requirement
@@ -128,6 +131,9 @@ dependencies:
128
131
  - - "~>"
129
132
  - !ruby/object:Gem::Version
130
133
  version: '6.0'
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 6.0.3
131
137
  description: Ruby - Mulang Parser
132
138
  email:
133
139
  - franco@mumuki.org