italian-ruby 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2928e098120452f555eff573f0d8062e76c111763e30605232b67cd607c9c085
4
- data.tar.gz: 1e765b113a325fbe8386cbff11514815ba634f96022cbd9ee27c12bd393b4336
3
+ metadata.gz: aedc827ee49cc7cf621b798f94d8ef76b5b612a3a0574f517c6dcdc0e63b2b3b
4
+ data.tar.gz: f6fdb3bb560d18d7eaeb138686e79af3871d4bcd36915addb82cd93e60755f43
5
5
  SHA512:
6
- metadata.gz: 9c1f878878db7ebe45eceb58ad381b225bd7590f3c5c23c06823d5961687cfbad599b8c5d8929cdf134b5c896c04bcb9045306e9e62332441c7e1007485c0a77
7
- data.tar.gz: b64217e3825727127a74282c7817cc5df123237e4768b91ef3784232fdcbdff168e05c80452fbb9e0da5685f7067e5031e730e5001844545206dba4a73aaee34
6
+ metadata.gz: 7c4ccd909945352f8f572d0fbbb3cf3f2c91846445f68d18c1b015400a1d862ed9aeaf1f51124af7be12bafddb4f98b7fee356d2756f205330d9f88d9f69bc5d
7
+ data.tar.gz: 04d1adf2f23352a9dfd7f6a8154b5ec09d59eb9cc05840c1eb39582b62024fe963d70d7ebb9713acb9a4e868291eeb67de91d06fe09eabd13c6599d863a45d73
data/italian-ruby.gemspec CHANGED
@@ -28,8 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
29
29
  spec.require_paths = ["lib"]
30
30
 
31
- spec.add_dependency 'ruby2ruby', '~> 2.4'
32
-
33
31
  spec.add_development_dependency 'bundler', '~> 2.1'
34
32
  spec.add_development_dependency 'rake', '~> 13.0'
35
33
  spec.add_development_dependency 'rspec', '~> 3.9'
@@ -27,6 +27,8 @@ module Kernel
27
27
  caller_location_dir = File.dirname caller_locations.first.absolute_path
28
28
  if caller_location_dir.start_with?(Italian::Ruby.translations_dir_path)
29
29
  caller_location_dir = caller_location_dir[Italian::Ruby.translations_dir_path.length..-1]
30
+ elsif caller_location_dir.include?(".italian-ruby/")
31
+ caller_location_dir.gsub! ".italian-ruby/", ""
30
32
  end
31
33
  caller_location_file = File.expand_path "#{caller_location_dir}/#{name}"
32
34
  file_to_require = Dir["#{caller_location_file}.{ir,rb}"].compact.first
@@ -1,30 +1,161 @@
1
1
  # frozen_string_literal: true
2
- require "ruby2ruby"
3
- require "ruby_parser"
4
- require_relative "ruby_parser_patches"
2
+ require "rainbow"
3
+ require_relative "utils/debug"
5
4
 
6
5
  module Italian
7
6
  module Ruby
8
7
  class Traduttore
9
8
 
9
+ STAMPA_DETTAGLI_TRADUZIONE = false
10
+
11
+ class Errore < StandardError
12
+ attr_accessor :messaggio, :file, :linea, :riga, :posizione
13
+
14
+ def initialize(messaggio: nil, file: nil, linea: nil, riga: 0, posizione: 0)
15
+ @messaggio = messaggio
16
+ @file = file
17
+ @linea = linea
18
+ @riga = riga
19
+ @posizione = posizione
20
+ end
21
+
22
+ class NonSupportato < Errore; end
23
+ class IndividuazioneStringa < Errore; end
24
+ end
25
+
10
26
  class << self
11
27
 
12
28
  def traduci(file)
13
29
  begin
14
- @@ruby2ruby ||= Ruby2Ruby.new
15
- @@parser ||= RubyParser.new
16
-
17
- codice = File.read file
18
- sexp = @@parser.process("# encoding: utf-8\n#{codice}")
19
- codice_ruby = @@ruby2ruby.process(sexp)
20
-
21
- "# encoding: utf-8\n#{codice_ruby}"
22
- rescue StandardError => error
23
- raise "Errore nella traduzione del file #{file}.\n"\
24
- "#{error.message}\n#{error.backtrace.join("\n")}"
30
+ codice_tradotto = File.readlines(file).map.with_index do |linea, riga|
31
+ traduci_linea file, linea, riga
32
+ end
33
+ codice_tradotto.join
34
+ rescue Italian::Ruby::Traduttore::Errore => errore
35
+ puts "-----------------------------------------------------------------------------".alzavola
36
+ puts "Si è verificato un errore durante la traduzione del file `#{errore.file}`."
37
+ print "L'errore è: "
38
+ puts "#{errore.classe}.".rosso
39
+ puts errore.messaggio
40
+ puts
41
+ print "Riga: "
42
+ puts "#{errore.riga}".ciano
43
+ puts errore.linea
44
+ puts "^".rjust(errore.posizione + 1, " ").verde_lime
45
+ puts
46
+ puts "-----------------------------------------------------------------------------".alzavola
47
+ exit 1
48
+ end
49
+ end
50
+
51
+ def traduci_linea(file, linea, riga)
52
+ puts "Traduco linea [#{riga}]: #{linea.inspect}".magenta if STAMPA_DETTAGLI_TRADUZIONE
53
+ posizione_commento = linea.index(%{#}) || linea.length
54
+ posizione_stringa_singola = linea.index(%{'}) || linea.length
55
+ posizione_stringa_doppia = linea.index(%{"}) || linea.length
56
+ contesto = [
57
+ file, linea, riga,
58
+ posizione_commento,
59
+ posizione_stringa_singola,
60
+ posizione_stringa_doppia ]
61
+
62
+ controlla_stringa_singola *contesto
63
+ controlla_stringa_doppia *contesto
64
+
65
+ if posizione_commento < posizione_stringa_doppia
66
+ pezzi_da_tradurre = [
67
+ linea[0..posizione_commento],
68
+ linea[posizione_commento + 1..]
69
+ ]
70
+ elsif posizione_stringa_doppia < posizione_commento
71
+ pezzi_da_tradurre = linea.scan( /([^"]*)("[^"]*")([^"]*)/ ).flatten
72
+ else
73
+ pezzi_da_tradurre = [ linea ]
74
+ end
75
+
76
+ debug pezzi_da_tradurre if STAMPA_DETTAGLI_TRADUZIONE
77
+ linea_tradotta = pezzi_da_tradurre.map { |pezzo| traduci_pezzo pezzo }.join
78
+
79
+ if STAMPA_DETTAGLI_TRADUZIONE
80
+ puts "Linea tradotta [#{riga}]: #{linea_tradotta.inspect}".verde_lime
81
+ puts
25
82
  end
83
+ linea_tradotta
26
84
  end
27
85
 
86
+ private
87
+
88
+ def errore!(classe, messaggio, file, linea, riga, posizione)
89
+ raise classe.new(messaggio: messaggio, file: file, linea: linea, riga: riga, posizione: posizione)
90
+ end
91
+
92
+ def controlla_stringa_singola(file, linea, riga, posizione_commento, posizione_stringa_singola, posizione_stringa_doppia)
93
+ if posizione_stringa_singola < posizione_commento and posizione_stringa_singola < posizione_stringa_doppia
94
+ errore! Errore::NonSupportato, "Le stringhe con singolo apice non sono supportate.", file, linea, riga, posizione_stringa_singola
95
+ end
96
+ end
97
+
98
+ def controlla_stringa_doppia(file, linea, riga, posizione_commento, posizione_stringa_singola, posizione_stringa_doppia)
99
+ return if posizione_commento <= posizione_stringa_doppia
100
+
101
+ prossima_posizione_stringa_doppia = linea[posizione_stringa_doppia + 1..].index %{"}
102
+ if prossima_posizione_stringa_doppia.nil?
103
+ errore! Errore::IndividuazioneStringa, "Non è stato possibile trovare la terminazione della stringa.", file, linea, riga, posizione_stringa_doppia
104
+ end
105
+ end
106
+
107
+ def traduci_pezzo(pezzo)
108
+ return pezzo if pezzo.nil? or pezzo.length == 0
109
+ return pezzo if pezzo.start_with? %{#}
110
+ return pezzo if pezzo.start_with? %{"}
111
+
112
+ pezzo.gsub! /(\b)e(\b)/, "\\1and\\2"
113
+ pezzo.gsub! /(\b)inizia(\b)/, "\\1begin\\2"
114
+ pezzo.gsub! /(\b)blocco_dato\?(\b)/, "\\1block_given?\\2"
115
+ pezzo.gsub! /(\b)esci(\b)/, "\\1break\\2"
116
+ pezzo.gsub! /(\b)considera(\b)/, "\\1case\\2"
117
+ pezzo.gsub! /(\b)classe([\s]+[A-Z][\w]*)/, "\\1class\\2"
118
+ pezzo.gsub! /(\b)classe([\s]+)(<<)([\s]+)/, "\\1class\\2\\3\\4"
119
+ pezzo.gsub! /(\b)definisci([\s]+[^\s]+)/, "\\1def\\2"
120
+ pezzo.gsub! /(\b)definito\?([\s]+[^\s]+)/, "\\1defined?\\2"
121
+ pezzo.gsub! /(\b)definita\?([\s]+[^\s]+)/, "\\1defined?\\2"
122
+ pezzo.gsub! /(\b)esegui(\b)/, "\\1do\\2"
123
+ pezzo.gsub! /(\b)altrimenti(\b)/, "\\1else\\2"
124
+ pezzo.gsub! /(\b)altrimenti_se(\b)/, "\\1elsif\\2"
125
+ pezzo.gsub! /(\b)fine(\b)/, "\\1end\\2"
126
+ pezzo.gsub! /(\b)assicura(\b)/, "\\1ensure\\2"
127
+ pezzo.gsub! /(\b)estendi([\s]+[A-Z][\w]*)/, "\\1extend\\2"
128
+ pezzo.gsub! /(\b)no(\b)/, "\\1false\\2"
129
+ pezzo.gsub! /(\b)falso(\b)/, "\\1false\\2"
130
+ pezzo.gsub! /(\b)per(\b)/, "\\1for\\2"
131
+ pezzo.gsub! /(\b)se(\b)/, "\\1if\\2"
132
+ pezzo.gsub! /(\b)includi([\s]+[A-Z][\w]*)/, "\\1include\\2"
133
+ pezzo.gsub! /(\b)modulo([\s]+[A-Z][\w]*)/, "\\1module\\2"
134
+ pezzo.gsub! /(\b)prossimo(\b)/, "\\1next\\2"
135
+ pezzo.gsub! /(\b)prossima(\b)/, "\\1next\\2"
136
+ pezzo.gsub! /(\b)nullo(\b)/, "\\1nil\\2"
137
+ pezzo.gsub! /(\b)nulla(\b)/, "\\1nil\\2"
138
+ pezzo.gsub! /(\b)non(\b)/, "\\1not\\2"
139
+ pezzo.gsub! /(\b)o(\b)/, "\\1or\\2"
140
+ pezzo.gsub! /(\b)preponi([\s]+[A-Z][\w]*)/, "\\1prepend\\2"
141
+ pezzo.gsub! /(\b)riesegui(\b)/, "\\1redo\\2"
142
+ pezzo.gsub! /(\b)recupera(\b)/, "\\1rescue\\2"
143
+ pezzo.gsub! /(\b)riprova(\b)/, "\\1retry\\2"
144
+ pezzo.gsub! /(\b)ritorna(\b)/, "\\1return\\2"
145
+ pezzo.gsub! /(\b)istanza/, "\\1self"
146
+ pezzo.gsub! /(\b)se_stesso/, "\\1self"
147
+ pezzo.gsub! /(\b)se_stessa/, "\\1self"
148
+ pezzo.gsub! /(\b)allora(\b)/, "\\1then\\2"
149
+ pezzo.gsub! /(\b)si(\b)/, "\\1true\\2"
150
+ pezzo.gsub! /(\b)vero(\b)/, "\\1true\\2"
151
+ pezzo.gsub! /(\b)a_meno_che(\b)/, "\\1unless\\2"
152
+ pezzo.gsub! /(\b)finché(\b)/, "\\1until\\2"
153
+ pezzo.gsub! /(\b)quando(\b)/, "\\1when\\2"
154
+ pezzo.gsub! /(\b)mentre(\b)/, "\\1while\\2"
155
+ pezzo.gsub! /(\b)rilascia(\b)/, "\\1yield\\2"
156
+ pezzo
157
+ end
158
+
28
159
  end
29
160
 
30
161
  end
@@ -30,9 +30,9 @@ end
30
30
 
31
31
  ##
32
32
  # Crea un metodo per ogni colore da poter chiamare su un'istanza di una stringa.
33
- class Stringa
33
+ class String
34
34
 
35
- COLORI = Mappa[
35
+ COLORI = Hash[
36
36
  aliceblue: :blu_ghiaccio,
37
37
  antiquewhite: :bianco_antico,
38
38
  aqua: :acqua,
@@ -1,5 +1,5 @@
1
1
  module Italian
2
2
  module Ruby
3
- VERSION = "0.7.0"
3
+ VERSION = "0.7.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: italian-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Ballardin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: ruby2ruby
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.4'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2.4'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -113,7 +99,6 @@ files:
113
99
  - lib/italian/ruby/core_ext/string.rb
114
100
  - lib/italian/ruby/core_ext/symbol.rb
115
101
  - lib/italian/ruby/core_ext/time.rb
116
- - lib/italian/ruby/ruby_parser_patches.rb
117
102
  - lib/italian/ruby/traduttore.rb
118
103
  - lib/italian/ruby/utils/debug.rb
119
104
  - lib/italian/ruby/version.rb
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyParserStuff
4
- class Keyword
5
- expr_woot = EXPR_FNAME|EXPR_FITEM
6
-
7
- italian_wordlist = [
8
- ["alias", [:kALIAS, :kALIAS ], expr_woot ],
9
- ["e", [:kAND, :kAND ], EXPR_BEG ],
10
- ["inizia", [:kBEGIN, :kBEGIN ], EXPR_BEG ],
11
- ["esci", [:kBREAK, :kBREAK ], EXPR_MID ],
12
- ["considera", [:kCASE, :kCASE ], EXPR_BEG ],
13
- ["classe", [:kCLASS, :kCLASS ], EXPR_CLASS ],
14
- ["def", [:kDEF, :kDEF ], EXPR_FNAME ],
15
- ["definisci", [:kDEF, :kDEF ], EXPR_FNAME ],
16
- ["definito?", [:kDEFINED, :kDEFINED ], EXPR_ARG ],
17
- ["definita?", [:kDEFINED, :kDEFINED ], EXPR_ARG ],
18
- ["esegui", [:kDO, :kDO ], EXPR_BEG ],
19
- ["fai", [:kDO, :kDO ], EXPR_BEG ],
20
- ["altrimenti", [:kELSE, :kELSE ], EXPR_BEG ],
21
- ["altrimenti_se", [:kELSIF, :kELSIF ], EXPR_BEG ],
22
- ["fine", [:kEND, :kEND ], EXPR_END ],
23
- ["assicura", [:kENSURE, :kENSURE ], EXPR_BEG ],
24
- ["no", [:kFALSE, :kFALSE ], EXPR_END ],
25
- ["falso", [:kFALSE, :kFALSE ], EXPR_END ],
26
- ["per", [:kFOR, :kFOR ], EXPR_BEG ],
27
- ["se", [:kIF, :kIF_MOD ], EXPR_BEG ],
28
- ["in", [:kIN, :kIN ], EXPR_BEG ],
29
- ["modulo", [:kMODULE, :kMODULE ], EXPR_BEG ],
30
- ["prossimo", [:kNEXT, :kNEXT ], EXPR_MID ],
31
- ["prossima", [:kNEXT, :kNEXT ], EXPR_MID ],
32
- ["nullo", [:kNIL, :kNIL ], EXPR_END ],
33
- ["nulla", [:kNIL, :kNIL ], EXPR_END ],
34
- ["non", [:kNOT, :kNOT ], EXPR_ARG ],
35
- ["o", [:kOR, :kOR ], EXPR_BEG ],
36
- ["rifai", [:kREDO, :kREDO ], EXPR_END ],
37
- ["riesegui", [:kREDO, :kREDO ], EXPR_END ],
38
- ["recupera", [:kRESCUE, :kRESCUE_MOD ], EXPR_MID ],
39
- ["riprova", [:kRETRY, :kRETRY ], EXPR_END ],
40
- ["ritorna", [:kRETURN, :kRETURN ], EXPR_MID ],
41
- ["istanza", [:kSELF, :kSELF ], EXPR_END ],
42
- ["se_stesso", [:kSELF, :kSELF ], EXPR_END ],
43
- ["se_stessa", [:kSELF, :kSELF ], EXPR_END ],
44
- ["super", [:kSUPER, :kSUPER ], EXPR_ARG ],
45
- ["allora", [:kTHEN, :kTHEN ], EXPR_BEG ],
46
- ["si", [:kTRUE, :kTRUE ], EXPR_END ],
47
- ["vero", [:kTRUE, :kTRUE ], EXPR_END ],
48
- ["undef", [:kUNDEF, :kUNDEF ], expr_woot ],
49
- ["a_meno_che", [:kUNLESS, :kUNLESS_MOD ], EXPR_BEG ],
50
- ["finché", [:kUNTIL, :kUNTIL_MOD ], EXPR_BEG ],
51
- ["quando", [:kWHEN, :kWHEN ], EXPR_BEG ],
52
- ["mentre", [:kWHILE, :kWHILE_MOD ], EXPR_BEG ],
53
- ["rilascia", [:kYIELD, :kYIELD ], EXPR_ARG ],
54
- ["INIZIA", [:klBEGIN, :klBEGIN ], EXPR_END ],
55
- ["FINE", [:klEND, :klEND ], EXPR_END ],
56
- ["__FILE__", [:k__FILE__, :k__FILE__ ], EXPR_END ],
57
- ["__LINE__", [:k__LINE__, :k__LINE__ ], EXPR_END ],
58
- ["__ENCODING__", [:k__ENCODING__, :k__ENCODING__], EXPR_END],
59
- ].map { |args| KWtable.new(*args) }
60
-
61
- ITALIAN_WORDLIST = Hash[*italian_wordlist.map { |o| [o.name, o] }.flatten]
62
-
63
- def self.keyword str
64
- ITALIAN_WORDLIST[str]
65
- end
66
- end
67
- end