mulang 6.0.0 → 6.0.5

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: 8bb18e555a651ab4f2c24ac12c63c209e542c16f06568e64991f3805f6ade038
4
- data.tar.gz: fe43d0621ccdd7de1fb4456a847500f18643fa7073283fc7383bfd686e56fe2c
3
+ metadata.gz: 840be5bf9bea2b4855d162f1aa04249c43f6b03081715e3fd930eebf7ab25545
4
+ data.tar.gz: 5b6304cdd8c354fc8300064f8c2852f63556f39549157e6580ec904fea36b24f
5
5
  SHA512:
6
- metadata.gz: 54cb641d94595bb9bb7b7a90ca34b1d07c43d16f5e9f4cf1b4c8739e4caf4019a417c72d69dd3823bde6caa9d43b90a7e1214d1e2aa6a0f25010ace70413a4e1
7
- data.tar.gz: e3cc1287c561622172627a476548b0c721a8b3395928e5f0a26eb9ec11a10fe2275839668145a7bc63390be34556fda0e7230ca01675c7bf5df469897fc112ec
6
+ metadata.gz: d132b9c22e545e123f7badba82e9435f746a735d29346ae078f7c916f8d03968b0c3695e358931bab0d72255b2e4f3dd7f45211c5afe8b43826bbb590919e5b0
7
+ data.tar.gz: bc0a5da0bd4475e77b56d9daef6e2bf4f1af4f2250c9108c4203123669be1837177b9209e00809a6f50c7df70bc7d1f0d3c1fa2fe6fde8206e46b7adc5c2490a
data/bin/mulang CHANGED
Binary file
data/lib/locales/en.yml CHANGED
@@ -171,8 +171,8 @@ en:
171
171
  UsesComprehension: '%{binding} %{must} use comprehensions'
172
172
  UsesConditional: '%{binding} %{must} use conditionals'
173
173
  UsesCut: '%{binding} uses <code>!</li> operator, which is a bad practice'
174
- UsesDyamicPolymorphism: '%{binding} %{must} use polymorphism'
175
174
  UsesDynamicMethodOverload: '%{binding} %{must} use overload'
175
+ UsesDynamicPolymorphism: '%{binding} %{must} use polymorphism'
176
176
  UsesFail: '%{binding} uses <code>%{keyword_Fail}</li>, which is a bad practice'
177
177
  UsesFindall: '%{binding} %{must} use <code>%{keyword_Findall}</code>'
178
178
  UsesForall: '%{binding} %{must} use <code>%{keyword_Forall}</code>'
@@ -185,6 +185,7 @@ en:
185
185
  UsesLoop: '%{binding} %{must} use a loop%{matching}'
186
186
  UsesMath: '%{binding} %{must} usar math expressions'
187
187
  UsesMixin: '%{binding} %{must} use mixins'
188
+ UsesNamedSelfReference: '%{binding} should use <code>%{keyword_Self}</code> instead of a global reference'
188
189
  UsesNot: '%{binding} %{must} use not'
189
190
  UsesObjectComposition: '%{binding} %{must} use composition'
190
191
  UsesPatternMatching: '%{binding} %{must} use pattern matching'
data/lib/locales/es.yml CHANGED
@@ -183,8 +183,8 @@ es:
183
183
  UsesComprehension: '%{binding} %{must} emplear listas por comprensión'
184
184
  UsesConditional: '%{binding} %{must} utilizar condicionales'
185
185
  UsesCut: '%{binding} usa el operador !, lo cual es una mala práctica'
186
- UsesDyamicPolymorphism: '%{binding} %{must} usar polimorfismo'
187
186
  UsesDynamicMethodOverload: '%{binding} %{must} usar sobrecarga'
187
+ UsesDynamicPolymorphism: '%{binding} %{must} usar polimorfismo'
188
188
  UsesExceptionHandling: '%{binding} %{must} realizar manejo de excepciones'
189
189
  UsesExceptions: '%{binding} %{must} usar excepciones'
190
190
  UsesFail: '%{binding} usa <code>%{keyword_Fail}</li>, lo cual es una mala práctica'
@@ -201,6 +201,7 @@ es:
201
201
  UsesMath: '%{binding} %{must} usar expresiones matemáticas'
202
202
  UsesMixin: '%{binding} %{must} utilizar mixins'
203
203
  UsesMixins: '%{binding} %{must} usar mixins'
204
+ UsesNamedSelfReference: '%{binding} debería usar <code>%{keyword_Self}</code> en lugar de una referencia global'
204
205
  UsesNot: '%{binding} %{must} utilizar <code>%{keyword_Not}</code>'
205
206
  UsesObjectComposition: '%{binding} %{must} usar composición'
206
207
  UsesPatternMatching: '%{binding} %{must} utilizar pattern matching'
data/lib/locales/pt.yml CHANGED
@@ -145,7 +145,7 @@ pt:
145
145
  Instantiates_named: '%{binding} %{must} instantiate %{target}'
146
146
  Instantiates: '%{binding} %{must} instanciar objetos'
147
147
  IsLongCode: '%{binding} é muito longo. Tente delegar mais'
148
- JavaScript#UsesVarInsteadOfLet: '% {binding} deve usar <code>let</code> em vez de <code>var</code>'
148
+ JavaScript#UsesVarInsteadOfLet: '%{binding} deve usar <code>let</code> em vez de <code>var</code>'
149
149
  OverridesEqualOrHashButNotBoth: '%{binding} redefine os métodos <code>equals</code> ou <code>hash </code>, mas não ambos'
150
150
  Raises_except: '%{binding} %{must} lançar exceções diferentes de %{target}'
151
151
  Raises_like: '%{binding} %{must} lançar exceções semelhantes a %{target}'
@@ -175,8 +175,8 @@ pt:
175
175
  UsesComprehension: '%{binding} %{must} usar listas pelo entendimento'
176
176
  UsesConditional: '%{binding} %{must} usar conditional'
177
177
  UsesCut: '%{binding} usa o operador !, que é uma má prática'
178
- UsesDyamicPolymorphism: '%{binding} %{must} usar polimorfismo'
179
178
  UsesDynamicMethodOverload: '%{binding} %{must} usar sobrecarga'
179
+ UsesDynamicPolymorphism: '%{binding} %{must} usar polimorfismo'
180
180
  UsesExceptionHandling: '%{binding} %{must} executar o tratamento de exceção'
181
181
  UsesExceptions: '%{binding} %{must} usar exceções'
182
182
  UsesFail: '%{binding} usa <code>%{keyword_Fail}</li>, o que é uma prática ruim'
@@ -192,6 +192,7 @@ pt:
192
192
  UsesLoop: '%{binding} %{must} usar um loop%{matching}'
193
193
  UsesMath: '%{binding} %{must} usar expressões matemáticas'
194
194
  UsesMixins: '%{binding} %{must} usar mixins'
195
+ UsesNamedSelfReference: '%{binding} deve usar <code>%{keyword_Self}</code> em vez de uma referência global'
195
196
  UsesNot: '%{binding} %{must} usar <code>%{keyword_Not}</code>'
196
197
  UsesObjectComposition: '%{binding} %{must} usar composição'
197
198
  UsesPatternMatching: '%{binding} %{must} usar o padrão de correspondência'
data/lib/mulang/code.rb CHANGED
@@ -30,8 +30,8 @@ module Mulang
30
30
  @language.sample @content
31
31
  end
32
32
 
33
- def analysis(spec)
34
- { sample: sample, spec: spec }
33
+ def analysis(spec, **options)
34
+ @language.build_analysis @content, spec, **options
35
35
  end
36
36
 
37
37
  def analyse(spec, **options)
@@ -60,8 +60,8 @@ module Mulang
60
60
  native(*args).tap { |it| it.expect('Parses') }
61
61
  end
62
62
 
63
- def self.external(content, &tool)
64
- new Mulang::Language::External.new(&tool), content
63
+ def self.external(language_name = nil, content, &tool)
64
+ new Mulang::Language::External.new(language_name, &tool), content
65
65
  end
66
66
 
67
67
  def self.analyse_many(codes, spec, **options)
@@ -76,13 +76,13 @@ module Mulang
76
76
  run_many(codes, key: 'transformedAsts', **options) { |it| it.transformed_asts_analysis(operations, **options) }
77
77
  end
78
78
 
79
- private
80
-
81
79
  def self.run_many(codes, key: nil, **options)
82
80
  result = Mulang.analyse(codes.map { |it| yield it }, **options)
83
81
  key ? result.map { |it| it[key] } : result
84
82
  end
85
83
 
84
+ private
85
+
86
86
  def expectation_results_for(result)
87
87
  raise result['reason'] if result['tag'] == 'AnalysisFailed'
88
88
  result['expectationResults']
@@ -8,6 +8,7 @@ module Mulang::Expectation
8
8
 
9
9
  FUNCTIONAL_SMELLS = %w(
10
10
  HasRedundantGuards
11
+ HasRedundantLambda
11
12
  HasRedundantParameter
12
13
  ShouldUseOtherwise
13
14
  )
@@ -15,23 +16,25 @@ module Mulang::Expectation
15
16
  OBJECT_ORIENTED_SMELLS = %w(
16
17
  DoesNilTest
17
18
  DoesNullTest
19
+ DoesTypeTest
18
20
  HasTooManyMethods
19
21
  OverridesEqualOrHashButNotBoth
20
22
  ReturnsNil
21
23
  ReturnsNull
24
+ UsesNamedSelfReference
22
25
  )
23
26
 
24
27
  IMPERATIVE_SMELLS = %w(
25
28
  HasAssignmentCondition
26
29
  HasAssignmentReturn
27
30
  HasEmptyRepeat
28
- HasRedundantLocalVariableReturn
29
31
  HasRedundantRepeat
30
32
  )
31
33
 
32
34
  EXPRESSIVENESS_SMELLS = %w(
33
35
  HasMisspelledBindings
34
36
  HasMisspelledIdentifiers
37
+ HasTooShortBindings
35
38
  HasTooShortIdentifiers
36
39
  HasWrongCaseBinding
37
40
  HasWrongCaseIdentifiers
@@ -40,7 +43,6 @@ module Mulang::Expectation
40
43
  GENERIC_SMELLS = %w(
41
44
  DiscardsExceptions
42
45
  DoesConsolePrint
43
- DoesTypeTest
44
46
  HasCodeDuplication
45
47
  HasDeclarationTypos
46
48
  HasEmptyIfBranches
@@ -48,8 +50,7 @@ module Mulang::Expectation
48
50
  HasLongParameterList
49
51
  HasRedundantBooleanComparison
50
52
  HasRedundantIf
51
- HasRedundantLambda
52
- HasTooShortBindings
53
+ HasRedundantLocalVariableReturn
53
54
  HasUnreachableCode
54
55
  HasUsageTypos
55
56
  IsLongCode
@@ -57,12 +58,22 @@ module Mulang::Expectation
57
58
  ShouldUseStrictComparators
58
59
  )
59
60
 
60
- SMELLS = GENERIC_SMELLS + EXPRESSIVENESS_SMELLS + IMPERATIVE_SMELLS + OBJECT_ORIENTED_SMELLS + FUNCTIONAL_SMELLS + LOGIC_SMELLS
61
+ JAVA_SCRIPT_SMELLS = %w(
62
+ JavaScript#UsesVarInsteadOfLet
63
+ )
64
+
65
+ SMELLS = GENERIC_SMELLS +
66
+ EXPRESSIVENESS_SMELLS +
67
+ IMPERATIVE_SMELLS +
68
+ OBJECT_ORIENTED_SMELLS +
69
+ FUNCTIONAL_SMELLS +
70
+ LOGIC_SMELLS +
71
+ JAVA_SCRIPT_SMELLS
61
72
 
62
73
  def self.guess_type(expectation)
63
74
  if expectation[:binding] == '<<custom>>'
64
75
  Custom
65
- elsif expectation[:inspection] =~ /(Not\:)?Has.*/ && !has_smell?(expectation[:inspection])
76
+ elsif expectation[:inspection] =~ /^(Not\:)?Has.*/ && !has_smell?(expectation[:inspection])
66
77
  V0
67
78
  else
68
79
  V2
@@ -1,11 +1,25 @@
1
1
  module Mulang::Language
2
+ CORE_LANGUAGES = %w(
3
+ Java
4
+ JavaScript
5
+ Prolog
6
+ Haskell
7
+ Python
8
+ Python2
9
+ Python3
10
+ Ruby
11
+ Php
12
+ C
13
+ Mulang
14
+ )
15
+
2
16
  class Base
3
17
  def identifiers(content, **options)
4
18
  Mulang.analyse(identifiers_analysis(content, **options), **options)['outputIdentifiers'] rescue nil
5
19
  end
6
20
 
7
21
  def identifiers_analysis(content, **options)
8
- base_analysis content, {includeOutputIdentifiers: true}, **options
22
+ build_analysis content, {includeOutputIdentifiers: true}, **options
9
23
  end
10
24
 
11
25
  def transformed_asts(content, operations, **options)
@@ -13,16 +27,22 @@ module Mulang::Language
13
27
  end
14
28
 
15
29
  def transformed_asts_analysis(content, operations, **options)
16
- base_analysis content, {transformationSpecs: operations}, **options
30
+ build_analysis content, {transformationSpecs: operations}, **options
17
31
  end
18
32
 
19
33
  def normalization_options(**options)
20
34
  options.except(:serialization).presence
21
35
  end
22
36
 
23
- private
37
+ def ast(content, **options)
38
+ Mulang.analyse(ast_analysis(content, **options), **options)['outputAst'] rescue nil
39
+ end
40
+
41
+ def ast_analysis(content, **options)
42
+ build_analysis content, {includeOutputAst: true}, **options
43
+ end
24
44
 
25
- def base_analysis(content, spec, **options)
45
+ def build_analysis(content, spec, **options)
26
46
  {
27
47
  sample: sample(content),
28
48
  spec: {
@@ -36,41 +56,60 @@ module Mulang::Language
36
56
  end
37
57
 
38
58
  class Native < Base
39
- def initialize(language)
40
- @language = language
41
- end
59
+ attr_accessor :name
42
60
 
43
- def ast(content, **options)
44
- Mulang.analyse(ast_analysis(content, **options), **options)['outputAst'] rescue nil
45
- end
46
-
47
- def ast_analysis(content, **options)
48
- base_analysis content, {includeOutputAst: true}, **options
61
+ def initialize(language_name)
62
+ @name = language_name
49
63
  end
50
64
 
51
65
  def sample(content)
52
66
  {
53
67
  tag: 'CodeSample',
54
- language: @language,
68
+ language: @name,
55
69
  content: content
56
70
  }
57
71
  end
72
+
73
+ def core_name
74
+ @name
75
+ end
58
76
  end
59
77
 
60
78
  class External < Base
61
- def initialize(&tool)
79
+ attr_accessor :name
80
+
81
+ def initialize(language_name = nil, &tool)
82
+ @name = language_name
62
83
  @tool = block_given? ? tool : proc { |it| it }
63
84
  end
64
85
 
65
86
  def ast(content, **args)
66
- @tool.call(content) rescue nil
87
+ if args[:serialization]
88
+ super
89
+ else
90
+ call_tool content
91
+ end
67
92
  end
68
93
 
69
94
  def sample(content)
70
95
  {
71
96
  tag: 'MulangSample',
72
- ast: ast(content)
97
+ ast: call_tool(content)
73
98
  }
74
99
  end
100
+
101
+ def build_analysis(*)
102
+ super.deep_merge(spec: {originalLanguage: core_name}.compact)
103
+ end
104
+
105
+ def core_name
106
+ @name.in?(CORE_LANGUAGES) ? name : nil
107
+ end
108
+
109
+ private
110
+
111
+ def call_tool(content)
112
+ @tool.call(content) rescue nil
113
+ end
75
114
  end
76
115
  end
data/lib/mulang/tokens.rb CHANGED
@@ -92,6 +92,7 @@ module Mulang
92
92
  keyword_ForEach: 'for',
93
93
  keyword_Interface: 'interface',
94
94
  keyword_Switch: 'switch',
95
+ keyword_Self: 'this',
95
96
  operator_And: '&amp;&amp;',
96
97
  operator_Divide: '/',
97
98
  operator_Equal: 'equal',
@@ -123,6 +124,7 @@ module Mulang
123
124
  keyword_If: 'if',
124
125
  keyword_Return: 'return',
125
126
  keyword_While: 'while',
127
+ keyword_Self: 'this',
126
128
  operator_And: '&amp;&amp;',
127
129
  operator_Divide: '/',
128
130
  operator_Equal: '===',
@@ -155,6 +157,7 @@ module Mulang
155
157
  keyword_If: 'if',
156
158
  keyword_Return: 'return',
157
159
  keyword_While: 'while',
160
+ keyword_Self: 'self',
158
161
  operator_And: 'and',
159
162
  operator_Divide: '/',
160
163
  operator_Equal: '==',
@@ -188,6 +191,7 @@ module Mulang
188
191
  keyword_ForEach: 'for',
189
192
  keyword_Include: 'include',
190
193
  keyword_Switch: 'case',
194
+ keyword_Self: 'self',
191
195
  operator_And: '&amp;&amp;',
192
196
  operator_Divide: '/',
193
197
  operator_Equal: '==',
@@ -207,6 +211,7 @@ module Mulang
207
211
  operator_BitwiseXor: '^',
208
212
  operator_BitwiseLeftShift: '&lt;&lt;',
209
213
  operator_BitwiseRightShift: '&gt;&gt;',
214
+ operator_Size: 'length',
210
215
  operator_Hash: 'hash',
211
216
  operator_ForwardComposition: '&gt;&gt;',
212
217
  operator_BackwardComposition: '&lt;&lt;'
@@ -219,6 +224,7 @@ module Mulang
219
224
  keyword_If: 'if',
220
225
  keyword_Return: 'return',
221
226
  keyword_While: 'while',
227
+ keyword_Self: 'this',
222
228
  operator_And: '&amp;&amp;',
223
229
  operator_Divide: '/',
224
230
  operator_Equal: '==',
@@ -1,4 +1,4 @@
1
1
  module Mulang
2
- VERSION = "6.0.0"
3
- MULANG_VERSION = "6.0.0"
2
+ VERSION = "6.0.5"
3
+ MULANG_VERSION = "6.0.5"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mulang
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Bulgarelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-19 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: mumukit-core