italian-ruby 0.9.18 → 1.0.4
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 +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +2 -9
- data/bin/italian-rspec +9 -18
- data/bin/italian-ruby +7 -7
- data/{vim → dev/vim}/ftdetect/ir.vim +0 -0
- data/{vim → dev/vim}/syntax/ir.vim +0 -0
- data/{vim → dev/vim}/vimrc +0 -0
- data/{vscode → dev/vscode}/italianruby.tmGrammar.json +0 -0
- data/italian-ruby.gemspec +7 -6
- data/lib/italian/ruby.rb +39 -14
- data/lib/italian/ruby/alias.rb +29 -0
- data/lib/italian/ruby/{core_ext → alias}/array.rb +12 -80
- data/lib/italian/ruby/{core_ext → alias}/class.rb +9 -2
- data/lib/italian/ruby/{core_ext → alias}/date.rb +4 -36
- data/lib/italian/ruby/{core_ext → alias}/enumerator.rb +4 -5
- data/lib/italian/ruby/alias/error.rb +19 -0
- data/lib/italian/ruby/{core_ext → alias}/false_class.rb +4 -3
- data/lib/italian/ruby/{core_ext → alias}/file.rb +6 -9
- data/lib/italian/ruby/{core_ext → alias}/float.rb +3 -4
- data/lib/italian/ruby/{core_ext → alias}/hash.rb +5 -39
- data/lib/italian/ruby/{core_ext → alias}/integer.rb +2 -26
- data/lib/italian/ruby/alias/io.rb +7 -0
- data/lib/italian/ruby/alias/kernel.rb +9 -0
- data/lib/italian/ruby/{core_ext → alias}/main.rb +5 -23
- data/lib/italian/ruby/alias/module.rb +9 -0
- data/lib/italian/ruby/{core_ext → alias}/nil_class.rb +3 -5
- data/lib/italian/ruby/alias/numeric.rb +3 -0
- data/lib/italian/ruby/alias/object.rb +39 -0
- data/lib/italian/ruby/alias/open_struct.rb +3 -0
- data/lib/italian/ruby/{core_ext → alias}/proc.rb +4 -5
- data/lib/italian/ruby/{core_ext → alias}/range.rb +4 -7
- data/lib/italian/ruby/{core_ext → alias}/rational.rb +3 -4
- data/lib/italian/ruby/alias/regexp.rb +13 -0
- data/lib/italian/ruby/{core_ext/gems → alias}/rspec.rb +7 -61
- data/lib/italian/ruby/alias/set.rb +39 -0
- data/lib/italian/ruby/alias/socket.rb +48 -0
- data/lib/italian/ruby/{core_ext → alias}/string.rb +4 -69
- data/lib/italian/ruby/{core_ext → alias}/symbol.rb +4 -5
- data/lib/italian/ruby/alias/time.rb +26 -0
- data/lib/italian/ruby/{core_ext → alias}/true_class.rb +4 -3
- data/lib/italian/ruby/errori.rb +84 -0
- data/lib/italian/ruby/metodi.rb +17 -0
- data/lib/italian/ruby/metodi/array.rb +105 -0
- data/lib/italian/ruby/metodi/date.rb +46 -0
- data/lib/italian/ruby/metodi/hash.rb +57 -0
- data/lib/italian/ruby/metodi/integer.rb +45 -0
- data/lib/italian/ruby/metodi/json.rb +17 -0
- data/lib/italian/ruby/metodi/kernel.rb +86 -0
- data/lib/italian/ruby/metodi/main.rb +31 -0
- data/lib/italian/ruby/metodi/module.rb +46 -0
- data/lib/italian/ruby/metodi/nil_class.rb +11 -0
- data/lib/italian/ruby/metodi/object.rb +64 -0
- data/lib/italian/ruby/{core_ext → metodi}/open_struct.rb +5 -7
- data/lib/italian/ruby/metodi/range.rb +11 -0
- data/lib/italian/ruby/metodi/rspec.rb +64 -0
- data/lib/italian/ruby/metodi/socket.rb +18 -0
- data/lib/italian/ruby/metodi/string.rb +174 -0
- data/lib/italian/ruby/metodi/time.rb +51 -0
- data/lib/italian/ruby/traduttore.rb +93 -122
- data/lib/italian/ruby/traduttore/linea.rb +144 -0
- data/lib/italian/ruby/traduttore/pezzo.rb +106 -0
- data/lib/italian/ruby/traduttore/stringa.rb +76 -0
- data/lib/italian/ruby/{version.rb → versione.rb} +1 -1
- metadata +60 -43
- data/Rakefile +0 -6
- data/lib/italian/ruby/core_ext.rb +0 -32
- data/lib/italian/ruby/core_ext/errors.rb +0 -16
- data/lib/italian/ruby/core_ext/gems/bson.rb +0 -26
- data/lib/italian/ruby/core_ext/gems/fabrication.rb +0 -12
- data/lib/italian/ruby/core_ext/gems/hanami.rb +0 -92
- data/lib/italian/ruby/core_ext/gems/rack_test.rb +0 -15
- data/lib/italian/ruby/core_ext/json.rb +0 -11
- data/lib/italian/ruby/core_ext/kernel.rb +0 -111
- data/lib/italian/ruby/core_ext/module.rb +0 -32
- data/lib/italian/ruby/core_ext/numeric.rb +0 -6
- data/lib/italian/ruby/core_ext/object.rb +0 -83
- data/lib/italian/ruby/core_ext/time.rb +0 -69
- data/lib/italian/ruby/errore.rb +0 -52
- data/lib/italian/ruby/utils/debug.rb +0 -134
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "rspec"
|
3
|
+
require "rspec/mocks"
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
|
7
|
+
def self.descrivi(*args, &block)
|
8
|
+
describe *args, &block
|
9
|
+
end
|
10
|
+
def self.variabili_condivise(*args, &block)
|
11
|
+
shared_context *args, &block
|
12
|
+
end
|
13
|
+
def self.contesto_condiviso(*args, &block)
|
14
|
+
shared_context *args, &block
|
15
|
+
end
|
16
|
+
|
17
|
+
module Core
|
18
|
+
class ExampleGroup
|
19
|
+
define_example_group_method :contesto
|
20
|
+
|
21
|
+
def classe_descritta
|
22
|
+
described_class
|
23
|
+
end
|
24
|
+
|
25
|
+
def risposta(*args, &block)
|
26
|
+
last_response *args, &block
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Expectations
|
32
|
+
class ExpectationTarget
|
33
|
+
module InstanceMethods
|
34
|
+
def che(*args, &block)
|
35
|
+
to *args, &block
|
36
|
+
end
|
37
|
+
|
38
|
+
def che_non(*args, &block)
|
39
|
+
not_to *args, &block
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Mocks
|
46
|
+
class TargetBase
|
47
|
+
def che(*args)
|
48
|
+
to *args
|
49
|
+
end
|
50
|
+
def che_non(*args)
|
51
|
+
not_to *args
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def matcher_allowed?(matcher)
|
57
|
+
matcher.class.name.start_with?("RSpec::Mocks::Matchers".freeze) or
|
58
|
+
matcher.class.name.start_with?("RSpec::Matchers::AliasedMatcher".freeze)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "socket"
|
3
|
+
|
4
|
+
class UNIXSocket
|
5
|
+
|
6
|
+
def guarda(maxlen)
|
7
|
+
recv_nonblock maxlen, Socket::MSG_PEEK
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class TCPSocket
|
13
|
+
|
14
|
+
def guarda(maxlen)
|
15
|
+
recv_nonblock maxlen, Socket::MSG_PEEK
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class String
|
4
|
+
|
5
|
+
##
|
6
|
+
# Codici colori.
|
7
|
+
CODICI_COLORI = Hash[
|
8
|
+
rosso: "31",
|
9
|
+
verde: "32",
|
10
|
+
giallo: "33",
|
11
|
+
blu: "34",
|
12
|
+
magenta: "35",
|
13
|
+
azzurro: "36",
|
14
|
+
arancione: "38;5;214"
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
##
|
18
|
+
# Metodi per la colorizzazione delle stringhe,
|
19
|
+
# quando stampate a terminale.
|
20
|
+
def colorize(color_code)
|
21
|
+
"\e[#{color_code}m#{self}\e[0m"
|
22
|
+
end
|
23
|
+
|
24
|
+
def bianco
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def rosso
|
29
|
+
colorize CODICI_COLORI[:rosso]
|
30
|
+
end
|
31
|
+
|
32
|
+
def verde
|
33
|
+
colorize CODICI_COLORI[:verde]
|
34
|
+
end
|
35
|
+
|
36
|
+
def giallo
|
37
|
+
colorize CODICI_COLORI[:giallo]
|
38
|
+
end
|
39
|
+
|
40
|
+
def blu
|
41
|
+
colorize CODICI_COLORI[:blu]
|
42
|
+
end
|
43
|
+
|
44
|
+
def magenta
|
45
|
+
colorize CODICI_COLORI[:magenta]
|
46
|
+
end
|
47
|
+
|
48
|
+
def azzurro
|
49
|
+
colorize CODICI_COLORI[:azzurro]
|
50
|
+
end
|
51
|
+
|
52
|
+
def arancione
|
53
|
+
colorize CODICI_COLORI[:arancione]
|
54
|
+
end
|
55
|
+
|
56
|
+
def decolorizza
|
57
|
+
self.gsub /(\u001b\[3\dm|\u001b\[3\d;\d;\d\d\dm|\u001b\[0m)/, ""
|
58
|
+
end
|
59
|
+
|
60
|
+
def disaccoppia_colore
|
61
|
+
indice_inizio_colore = self.index "m"
|
62
|
+
codice_colore = self[2..indice_inizio_colore - 1]
|
63
|
+
|
64
|
+
porzione_decolorizzata = self[indice_inizio_colore + 1..-5]
|
65
|
+
colore = CODICI_COLORI.invert.fetch codice_colore
|
66
|
+
|
67
|
+
[ colore, porzione_decolorizzata ]
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Determina se la stringa esiste e non è vuota.
|
72
|
+
def esiste?
|
73
|
+
!nil? and self != ""
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Determina se la stringa non include un'altra stringa.
|
78
|
+
def non_include?(*args)
|
79
|
+
!include? *args
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Determina se la stringa non inizia con un'altra stringa.
|
84
|
+
def non_inizia_con?(*args)
|
85
|
+
!inizia_con? *args
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# Determina se la stringa non finisce con un'altra stringa.
|
90
|
+
def non_finisce_con?(*args)
|
91
|
+
!finisce_con? *args
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Converte la stringa in data.
|
96
|
+
def in_data
|
97
|
+
return unless defined? Date
|
98
|
+
Date.parse self
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Converte la stringa in tempo.
|
103
|
+
def in_tempo
|
104
|
+
return unless defined? Time
|
105
|
+
Time.parse self
|
106
|
+
end
|
107
|
+
|
108
|
+
##
|
109
|
+
# Converte la stringa nella classe con lo steso nome.
|
110
|
+
def in_classe
|
111
|
+
Object.const_get self
|
112
|
+
end
|
113
|
+
|
114
|
+
##
|
115
|
+
# Restituisce i primi n caratteri della stringa.
|
116
|
+
def primi(n)
|
117
|
+
self[0..(n - 1)]
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Restituisce il primo carattere della stringa.
|
122
|
+
def primo_carattere
|
123
|
+
self[0]
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# Restituisce l'ultimo carattere della stringa.
|
128
|
+
def ultimo_carattere
|
129
|
+
self[-1]
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# Restituisce la stringa escludendo i primi n caratteri.
|
134
|
+
def salta_caratteri(n)
|
135
|
+
self[(n - 1)..-1]
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# Restituisce la stringa escludendo il primo carattere.
|
140
|
+
def salta_il_primo_carattere
|
141
|
+
self[1..-1]
|
142
|
+
end
|
143
|
+
|
144
|
+
##
|
145
|
+
# Restituisce la stringa togliendo gli ultimi n caratteri.
|
146
|
+
def tronca_caratteri(n)
|
147
|
+
self[0..(-1 - n)]
|
148
|
+
end
|
149
|
+
|
150
|
+
##
|
151
|
+
# Restituisce la stringa togliendo l'ultimo carattere.
|
152
|
+
def tronca
|
153
|
+
self[0..-2]
|
154
|
+
end
|
155
|
+
|
156
|
+
##
|
157
|
+
# Adatta la stringa alla lunghezza specificata.
|
158
|
+
# Se la stringa è più lunga, la tronca e mette dei puntini di sospensione.
|
159
|
+
# Se la stringa è più corta, aggiunge n spazi vuoti alla fine per coprire.
|
160
|
+
def adatta(l)
|
161
|
+
if self.length > l
|
162
|
+
"#{self[0..l - 3]}.."
|
163
|
+
else
|
164
|
+
self.ljust l, " "
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
##
|
169
|
+
# Restituisce l'ultimo indice della stringa.
|
170
|
+
def ultimo_indice
|
171
|
+
self.length - 1
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Time
|
4
|
+
|
5
|
+
##
|
6
|
+
# Converte il tempo in data.
|
7
|
+
def in_data
|
8
|
+
self.to_date
|
9
|
+
end
|
10
|
+
|
11
|
+
##
|
12
|
+
# Converte il tempo in se stesso.
|
13
|
+
def in_tempo
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Formatta il tempo secondo la stringa passata.
|
19
|
+
def formatta_locale(format)
|
20
|
+
if defined? I18n
|
21
|
+
I18n.l self, format: format
|
22
|
+
else
|
23
|
+
strftime format
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Ritorna il tempo all'inizio dell'ora.
|
29
|
+
def inizio_ora
|
30
|
+
Time.new(self.year, self.month, self.day, self.hour)
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Ritorna il tempo alla fine dell'ora.
|
35
|
+
def fine_ora
|
36
|
+
Time.new(self.year, self.month, self.day, self.hour, 59, 59)
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Ritorna il tempo all'inizio del minuto.
|
41
|
+
def inizio_minuto
|
42
|
+
Time.new(self.year, self.month, self.day, self.hour, self.min)
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Ritorna il tempo alla fine del minuto.
|
47
|
+
def fine_minuto
|
48
|
+
Time.new(self.year, self.month, self.day, self.hour, self.min, 59)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -1,143 +1,114 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative
|
4
|
-
|
5
|
-
|
2
|
+
require_relative "errori"
|
3
|
+
require_relative "traduttore/linea"
|
4
|
+
|
5
|
+
##
|
6
|
+
# Traduttore per codice sorgente ItalianRuby.
|
7
|
+
#
|
8
|
+
# Il traduttore espone un metodo di classe `traduci`, che può
|
9
|
+
# essere chiamato passando un archivio o un blocco.
|
10
|
+
# Viene restituito lo stesso archivio o blocco tradotto in sorgente Ruby.
|
11
|
+
#
|
12
|
+
# Nella traduzione viene mantenuta la perfetta corrispondenza
|
13
|
+
# fra i numeri di linea, in modo tale da facilitare la lettura delle
|
14
|
+
# eventuali tracce di errore.
|
6
15
|
module Italian
|
7
16
|
module Ruby
|
8
17
|
class Traduttore
|
9
18
|
|
19
|
+
##
|
20
|
+
# Bandierina per stampare o meno i dettagli della traduzione,
|
21
|
+
# mentre questa viene eseguita.
|
10
22
|
STAMPA_DETTAGLI_TRADUZIONE = false
|
11
23
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
block.call
|
24
|
-
rescue StandardError => errore
|
25
|
-
Italian::Ruby::Errore.new([ errore.message, errore.backtrace ].join("\n"), "-", 0, 0).stampa
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
24
|
+
##
|
25
|
+
# Punto d'ingresso del traduttore. Questo metodo esegue del codice Ruby
|
26
|
+
# presente in un archivio. Il codice può essere stato precedentemente
|
27
|
+
# tradotto dal metodo `traduci` del traduttore ItalianRuby.
|
28
|
+
def self.esegui(percorso_archivio_tradotto)
|
29
|
+
load percorso_archivio_tradotto
|
30
|
+
rescue SyntaxError => errore
|
31
|
+
Italian::Ruby::Errori.recupera errore, percorso_archivio_tradotto
|
32
|
+
rescue StandardError => errore
|
33
|
+
Italian::Ruby::Errori.recupera errore, percorso_archivio_tradotto
|
34
|
+
end
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
linea[posizione_commento + 1..]
|
49
|
-
]
|
50
|
-
elsif posizione_stringa_doppia < posizione_commento
|
51
|
-
pezzi_da_tradurre = linea.scan( /([^"]*)("[^"]*")([^"]*)/ ).flatten
|
52
|
-
else
|
53
|
-
pezzi_da_tradurre = [ linea ]
|
54
|
-
end
|
36
|
+
##
|
37
|
+
# Punto d'ingresso del traduttore. Questo metodo accetta un archivio
|
38
|
+
# come argomento principale, oppure un blocco di codice.
|
39
|
+
def self.traduci(archivio = nil, sorgente = nil, &blocco)
|
40
|
+
return traduci_archivio archivio if archivio != nil
|
41
|
+
return traduci_sorgente sorgente if sorgente != nil
|
42
|
+
return traduci_blocco &blocco if block_given?
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
##
|
48
|
+
# Traduce un archivio sorgente da ItalianRuby a Ruby.
|
49
|
+
# Salva la versione tradotta dell'archivio originale nel percorso
|
50
|
+
# delle traduzioni.
|
51
|
+
def self.traduci_archivio(archivio)
|
52
|
+
puts "Traduzione archivio: #{archivio}" if STAMPA_DETTAGLI_TRADUZIONE
|
55
53
|
|
56
|
-
|
57
|
-
|
54
|
+
linee_sorgente = File.readlines archivio
|
55
|
+
linee_tradotte = linee_sorgente.map.with_index do |linea, numero_linea|
|
56
|
+
linea_da_tradurre = Italian::Ruby::Traduttore::Linea.new linea, numero_linea, archivio
|
57
|
+
linea_tradotta = linea_da_tradurre.traduci
|
58
58
|
|
59
|
-
|
60
|
-
puts "
|
61
|
-
|
59
|
+
puts "\t[#{numero_linea}] <- #{linea}" if STAMPA_DETTAGLI_TRADUZIONE
|
60
|
+
puts "\t[#{numero_linea}] -> #{linea_tradotta}" if STAMPA_DETTAGLI_TRADUZIONE
|
61
|
+
|
62
|
+
linea_tradotta.chomp
|
62
63
|
end
|
63
|
-
|
64
|
+
|
65
|
+
puts "Traduzione terminata." if STAMPA_DETTAGLI_TRADUZIONE
|
66
|
+
puts if STAMPA_DETTAGLI_TRADUZIONE
|
67
|
+
|
68
|
+
linee_tradotte = linee_tradotte.join("\n").freeze
|
69
|
+
archivio_tradotto = Italian::Ruby.percorso_archivio_tradotto archivio
|
70
|
+
cartella_archivio_tradotto = File.dirname archivio_tradotto
|
71
|
+
FileUtils.mkdir_p cartella_archivio_tradotto unless Dir.exist? cartella_archivio_tradotto
|
72
|
+
|
73
|
+
File.write archivio_tradotto, linee_tradotte
|
74
|
+
archivio_tradotto
|
75
|
+
rescue SyntaxError => errore
|
76
|
+
Italian::Ruby::Errori.recupera errore, archivio
|
64
77
|
end
|
65
78
|
|
66
|
-
|
79
|
+
##
|
80
|
+
# Traduce un pezzo di sorgente da ItalianRuby a Ruby.
|
81
|
+
def self.traduci_sorgente(sorgente)
|
82
|
+
puts "Traduzione sorgente." if STAMPA_DETTAGLI_TRADUZIONE
|
67
83
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
file, riga, posizione_stringa_singola).stampa
|
73
|
-
end
|
74
|
-
end
|
84
|
+
linee_sorgente = sorgente.split "\n"
|
85
|
+
linee_tradotte = linee_sorgente.map.with_index do |linea, numero_linea|
|
86
|
+
linea_da_tradurre = Italian::Ruby::Traduttore::Linea.new linea, numero_linea, nil
|
87
|
+
linea_tradotta = linea_da_tradurre.traduci
|
75
88
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
prossima_posizione_stringa_doppia = linea[posizione_stringa_doppia + 1..].index %{"}
|
80
|
-
if prossima_posizione_stringa_doppia.nil?
|
81
|
-
Italian::Ruby::Errore::IndividuazioneStringa.new(
|
82
|
-
"Non è stato possibile trovare la terminazione della stringa.",
|
83
|
-
file, riga, posizione_stringa_doppia).stampa
|
84
|
-
end
|
85
|
-
end
|
89
|
+
puts "\t[#{numero_linea}] <- #{linea}" if STAMPA_DETTAGLI_TRADUZIONE
|
90
|
+
puts "\t[#{numero_linea}] -> #{linea_tradotta}" if STAMPA_DETTAGLI_TRADUZIONE
|
86
91
|
|
87
|
-
|
88
|
-
return pezzo if pezzo.nil? or pezzo.length == 0
|
89
|
-
return pezzo if pezzo.start_with? %{#}
|
90
|
-
return pezzo if pezzo.start_with? %{"}
|
91
|
-
|
92
|
-
pezzo.gsub! /(\b)e(\b)/, "\\1and\\2"
|
93
|
-
pezzo.gsub! /(\b)inizia(\b)/, "\\1begin\\2"
|
94
|
-
pezzo.gsub! /(\b)blocco_dato\?(\b)/, "\\1block_given?\\2"
|
95
|
-
pezzo.gsub! /(\b)esci(\b)/, "\\1break\\2"
|
96
|
-
pezzo.gsub! /(\b)considera(\b)/, "\\1case\\2"
|
97
|
-
pezzo.gsub! /(\b)classe([\s]+[A-Z][\w]*)/, "\\1class\\2"
|
98
|
-
pezzo.gsub! /(\b)classe([\s]+)(<<)([\s]+)/, "\\1class\\2\\3\\4"
|
99
|
-
pezzo.gsub! /(\b)definisci([\s]+[^\s]+)/, "\\1def\\2"
|
100
|
-
pezzo.gsub! /(\b)definito\?([\s]+[^\s]+)/, "\\1defined?\\2"
|
101
|
-
pezzo.gsub! /(\b)definita\?([\s]+[^\s]+)/, "\\1defined?\\2"
|
102
|
-
pezzo.gsub! /(\b)esegui(\b)/, "\\1do\\2"
|
103
|
-
pezzo.gsub! /(\b)altrimenti(\b)/, "\\1else\\2"
|
104
|
-
pezzo.gsub! /(\b)altrimenti_se(\b)/, "\\1elsif\\2"
|
105
|
-
pezzo.gsub! /(\b)fine(\b)/, "\\1end\\2"
|
106
|
-
pezzo.gsub! /(\b)assicura(\b)/, "\\1ensure\\2"
|
107
|
-
pezzo.gsub! /(\b)estendi([\s]+[A-Z][\w]*)/, "\\1extend\\2"
|
108
|
-
pezzo.gsub! /(\b)no(\b)/, "\\1false\\2"
|
109
|
-
pezzo.gsub! /(\b)falso(\b)/, "\\1false\\2"
|
110
|
-
pezzo.gsub! /(\b)per(\b)/, "\\1for\\2"
|
111
|
-
pezzo.gsub! /(\b)se(\b)/, "\\1if\\2"
|
112
|
-
pezzo.gsub! /(\b)includi([\s]+[A-Z][\w]*)/, "\\1include\\2"
|
113
|
-
pezzo.gsub! /(\b)modulo([\s]+[A-Z][\w]*)/, "\\1module\\2"
|
114
|
-
pezzo.gsub! /(\b)prossimo(\b)/, "\\1next\\2"
|
115
|
-
pezzo.gsub! /(\b)prossima(\b)/, "\\1next\\2"
|
116
|
-
pezzo.gsub! /(\b)nullo(\b)/, "\\1nil\\2"
|
117
|
-
pezzo.gsub! /(\b)nulla(\b)/, "\\1nil\\2"
|
118
|
-
pezzo.gsub! /(\b)non(\b)/, "\\1not\\2"
|
119
|
-
pezzo.gsub! /(\b)o(\b)/, "\\1or\\2"
|
120
|
-
pezzo.gsub! /(\b)preponi([\s]+[A-Z][\w]*)/, "\\1prepend\\2"
|
121
|
-
pezzo.gsub! /(\b)riesegui(\b)/, "\\1redo\\2"
|
122
|
-
pezzo.gsub! /(\b)recupera(\b)/, "\\1rescue\\2"
|
123
|
-
pezzo.gsub! /(\b)riprova(\b)/, "\\1retry\\2"
|
124
|
-
pezzo.gsub! /(\b)ritorna(\b)/, "\\1return\\2"
|
125
|
-
pezzo.gsub! /(\b)istanza/, "\\1self"
|
126
|
-
pezzo.gsub! /(\b)se_stesso/, "\\1self"
|
127
|
-
pezzo.gsub! /(\b)se_stessa/, "\\1self"
|
128
|
-
pezzo.gsub! /(\b)allora(\b)/, "\\1then\\2"
|
129
|
-
pezzo.gsub! /(\b)si(\b)/, "\\1true\\2"
|
130
|
-
pezzo.gsub! /(\b)vero(\b)/, "\\1true\\2"
|
131
|
-
pezzo.gsub! /(\b)a_meno_che(\b)/, "\\1unless\\2"
|
132
|
-
pezzo.gsub! /(\b)finché(\b)/, "\\1until\\2"
|
133
|
-
pezzo.gsub! /(\b)quando(\b)/, "\\1when\\2"
|
134
|
-
pezzo.gsub! /(\b)mentre(\b)/, "\\1while\\2"
|
135
|
-
pezzo.gsub! /(\b)rilascia(\b)/, "\\1yield\\2"
|
136
|
-
pezzo
|
92
|
+
linea_tradotta.chomp
|
137
93
|
end
|
138
94
|
|
139
|
-
|
95
|
+
puts "Traduzione terminata." if STAMPA_DETTAGLI_TRADUZIONE
|
96
|
+
puts if STAMPA_DETTAGLI_TRADUZIONE
|
97
|
+
|
98
|
+
sorgente_tradotto = linee_tradotte.join("\n").freeze
|
99
|
+
sorgente_tradotto
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Traduce un blocco di codice da ItalianRuby a Ruby.
|
104
|
+
def self.traduci_blocco(&blocco)
|
105
|
+
blocco.call
|
106
|
+
rescue SyntaxError => errore
|
107
|
+
Italian::Ruby::Errori.recupera errore
|
108
|
+
rescue StandardError => errore
|
109
|
+
Italian::Ruby::Errori.recupera errore
|
110
|
+
end
|
140
111
|
|
141
112
|
end
|
142
113
|
end
|
143
|
-
end
|
114
|
+
end
|