italian-ruby 0.7.2 → 0.7.3

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: b589fd000be0d0e27a8e4bb9fa847d771d8f0b2ae0dbab458d8c526c3b13070e
4
- data.tar.gz: 6cf44046cd2838b05d47e59250b25510f9529150f233ef69527a4d4661d10090
3
+ metadata.gz: 5e15f6f86b0961ca74ad83f10083f4c6fe2cdaff1d3d7285af51ff1d15f1a3ff
4
+ data.tar.gz: c1d4294786b4604dc750b0faa3881088b6d49e7df4bc1b5ef638baf589607b91
5
5
  SHA512:
6
- metadata.gz: 4d6ef447970787404649ac1935504df3c1a0b2820cd8a5275053db0ceba429acbd8d5a51491147bc7911351ab0d371894e147abcbed23b385c278911c8dfd949
7
- data.tar.gz: ba46632ff6d881d95bbf8ddee8b7034273b110c86798da70e5cd51b3ed2a546fe099f980acc2bffb38f64eac2f9ded0e29cb85b0c233b08646b9e5c7711c42f0
6
+ metadata.gz: e5945be346028fc2dbebb5a5b20b7c61da3954733a4a9b6d8d3b3d8955eb7a09f65562896fc02bd1350b65fd9b872eba41c22e6c9893e7bc72036dd5eee3f480
7
+ data.tar.gz: f84419f5ddff172b0831ab9326178be0ef95f9c4f2a468aab422bf704eaa28818fd39ee21c063c430eddf9db023a8387eba468b2d446a6c22b9a6b16c48a4634
@@ -17,7 +17,12 @@ module Kernel
17
17
  file_to_require = $:.map { |dir| Dir["#{dir}/**/#{name}.ir"] }.flatten.compact.first
18
18
 
19
19
  if file_to_require.nil?
20
- require name
20
+ begin
21
+ require name
22
+ rescue SyntaxError => errore
23
+ riga = errore.message.split("\n").first.split(":")[1].to_i rescue 0
24
+ Italian::Ruby::Errore::Sintassi.new("Errore di sintassi.", name, riga, 0).stampa
25
+ end
21
26
  else
22
27
  traduci_e_carica file_to_require
23
28
  end
@@ -72,10 +77,12 @@ module Kernel
72
77
  end
73
78
 
74
79
  File.write parsed_file, parsed_code
75
- require parsed_file
76
- # require_output = require tmp_parsed_file
77
- # File.delete tmp_parsed_file if File.exist? tmp_parsed_file
78
- #require_output
80
+ begin
81
+ require parsed_file
82
+ rescue SyntaxError => errore
83
+ riga = errore.message.split("\n").first.split(":")[1].to_i rescue 0
84
+ Italian::Ruby::Errore::Sintassi.new("Errore di sintassi.", parsed_file, riga, 0).stampa
85
+ end
79
86
  end
80
87
 
81
88
  end
@@ -0,0 +1,52 @@
1
+ require_relative "utils/debug"
2
+
3
+ module Italian
4
+ module Ruby
5
+ class Errore < StandardError
6
+ class Sintassi < Errore; end
7
+ class NonSupportato < Errore; end
8
+ class IndividuazioneStringa < Errore; end
9
+
10
+ def initialize(messaggio = nil, file = nil, riga = 0, posizione = 0)
11
+ @messaggio = messaggio
12
+ @file = file
13
+ @riga = riga
14
+ @posizione = posizione
15
+ begin
16
+ @linea = File.readlines(@file)[@riga - 1]
17
+ rescue StandardError => e
18
+ @linea = "Non è stato possibile recuperare la riga #{@riga} del file."
19
+ end
20
+ end
21
+
22
+ def stampa
23
+ prova_ad_ottenere_maggiori_informazioni
24
+ puts "-----------------------------------------------------------------------------".alzavola
25
+ puts "Si è verificato un errore durante la traduzione del file `#{@file}`."
26
+ print "L'errore è: "
27
+ puts "#{self.class}.".rosso
28
+ puts @messaggio
29
+ puts
30
+ print "Riga: "
31
+ puts "#{@riga}".ciano
32
+ puts @linea
33
+ puts "^".rjust(@posizione + 1, " ").verde_lime
34
+ puts
35
+ puts "-----------------------------------------------------------------------------".alzavola
36
+ exit 1
37
+ end
38
+
39
+ private
40
+
41
+ ##
42
+ # Prova a recuperare maggiori informazioni su errore.
43
+ def prova_ad_ottenere_maggiori_informazioni
44
+ case
45
+ when self.class.is_a?(Sintassi)
46
+ # TO DO
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require "rainbow"
3
3
  require_relative "utils/debug"
4
+ require_relative "errore"
4
5
 
5
6
  module Italian
6
7
  module Ruby
@@ -8,43 +9,22 @@ module Italian
8
9
 
9
10
  STAMPA_DETTAGLI_TRADUZIONE = false
10
11
 
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
-
26
12
  class << self
27
13
 
28
- def traduci(file)
29
- begin
14
+ def traduci(file = nil, &block)
15
+ if not file.nil?
30
16
  codice_tradotto = File.readlines(file).map.with_index do |linea, riga|
31
17
  traduci_linea file, linea, riga
32
18
  end
33
19
  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
20
+ else
21
+ if block_given?
22
+ begin
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
48
28
  end
49
29
  end
50
30
 
@@ -85,13 +65,11 @@ module Italian
85
65
 
86
66
  private
87
67
 
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
68
  def controlla_stringa_singola(file, linea, riga, posizione_commento, posizione_stringa_singola, posizione_stringa_doppia)
93
69
  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
70
+ Italian::Ruby::Errore::NonSupportato.new(
71
+ "Le stringhe con singolo apice non sono supportate.",
72
+ file, riga, posizione_stringa_singola).stampa
95
73
  end
96
74
  end
97
75
 
@@ -100,7 +78,9 @@ module Italian
100
78
 
101
79
  prossima_posizione_stringa_doppia = linea[posizione_stringa_doppia + 1..].index %{"}
102
80
  if prossima_posizione_stringa_doppia.nil?
103
- errore! Errore::IndividuazioneStringa, "Non è stato possibile trovare la terminazione della stringa.", file, linea, riga, posizione_stringa_doppia
81
+ Italian::Ruby::Errore::IndividuazioneStringa.new(
82
+ "Non è stato possibile trovare la terminazione della stringa.",
83
+ file, riga, posizione_stringa_doppia).stampa
104
84
  end
105
85
  end
106
86
 
@@ -1,5 +1,5 @@
1
1
  module Italian
2
2
  module Ruby
3
- VERSION = "0.7.2"
3
+ VERSION = "0.7.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: italian-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
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-21 00:00:00.000000000 Z
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,6 +99,7 @@ files:
99
99
  - lib/italian/ruby/core_ext/string.rb
100
100
  - lib/italian/ruby/core_ext/symbol.rb
101
101
  - lib/italian/ruby/core_ext/time.rb
102
+ - lib/italian/ruby/errore.rb
102
103
  - lib/italian/ruby/traduttore.rb
103
104
  - lib/italian/ruby/utils/debug.rb
104
105
  - lib/italian/ruby/version.rb