dsl-python 0.16.0 → 0.17.0

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: 1f6b87c7423590b808254e15ecf767246000453726a5c28c861ea401acc57327
4
- data.tar.gz: 1fd4a84514981ab92addab9492291d56563d316cd6ba6b6168738d0c2178b583
3
+ metadata.gz: 53730ec810f653d2a91efbc21fdfb976eb63b7449939d5ac91eb2052926a98a9
4
+ data.tar.gz: e42b22f0d6cf72fb20b1898940cad1f02af4d4b6d0f6e0337a063d0765ee5dd1
5
5
  SHA512:
6
- metadata.gz: de618cd018d3229a3c0086c00a8e507011b818c7ad66da6e20b1b0adfc75e774f40e28f1c523ce72dd1afac00571cb44d8b8cdcbcf855ffa9e9812e4712136fb
7
- data.tar.gz: 7232c26fe6c31e422c40d18d1e6d4e0dd548ac42703c496ef2c12c32b6935612de045d74bd04e44b0f3268b7448e80d87e31d234433ff34f1c1dfda4f2169ce4
6
+ metadata.gz: 635779c8d1814833c4981cfe8b55dc655030faafdd35a13efa4e3e24a63f5021027f14509de2276f305967e55f1bf3ef36e5451ffa6dc7f335998d87e1e7f06c
7
+ data.tar.gz: 736bc13886414941ca91c99e1ef1fd12c022da9c401fd3277910d35bf6ff37b63fd3375fadd246960161336cd6418c0da153de641e5acb510c9d83cf9f128b2c
data/README.md CHANGED
@@ -44,7 +44,7 @@ Obiwan
44
44
  * Intérpre interactivo `npython`.
45
45
  * Booleans
46
46
  * Diccionarios
47
- * import
47
+ * import "this"
48
48
  * None
49
49
  * Ranges
50
50
  * Strings
data/bin/npython CHANGED
@@ -1,19 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
+ require "dsl/python"
3
+ require "dsl/python/version"
2
4
 
3
- VERSION="0.16.0"
5
+ VERSION=Dsl::Python::VERSION
4
6
 
5
- if ARGV.size.zero?
6
- # Open irb
7
+ def open_repl
7
8
  text = <<~TEXT
8
- nPython 0.16.0 (main, Nov 16 2025, 18:38:03) [GCC] on linux
9
+ nPython #{VERSION} (main, Nov 16 1970) [GCC] on linux
9
10
  Type "help", "copyright", "credits" or "license" for more information.
10
11
  TEXT
11
12
  puts text
13
+ system("irb --prompt simple --nocolorize --noecho-on-assignment -Ilib -rdsl/python")
14
+ end
12
15
 
13
- system("irb --prompt simple --nocolorize --noecho-on-assignment -Ilib -rnpython")
14
- elsif ["-v", "--version", "-V"].include? ARGV.first
16
+ def show_version
15
17
  puts "npython (#{VERSION})"
16
- elsif ["-h", "--help", "-?"].include? ARGV.first
18
+ end
19
+
20
+ def show_help
17
21
  text = <<~TEXT
18
22
  usage: npython [option | file ]
19
23
  Options:
@@ -22,10 +26,26 @@ elsif ["-h", "--help", "-?"].include? ARGV.first
22
26
 
23
27
  Arguments:
24
28
  file : program read from script file
25
- TEXT
29
+ TEXT
26
30
  puts text
27
- else
28
- require "dsl/python"
29
- content = File.read(ARGV.first)
31
+ end
32
+
33
+ def run_program(name)
34
+ unless File.exist? name
35
+ puts "npython: can't open file '#{name}': [Errno 2] No such file or directory"
36
+ exit 1
37
+ end
38
+
39
+ content = File.read(name)
30
40
  eval(content)
31
41
  end
42
+
43
+ if ARGV.size.zero?
44
+ open_repl
45
+ elsif ["-v", "--version", "-V"].include? ARGV.first
46
+ show_version
47
+ elsif ["-h", "--help", "-?"].include? ARGV.first
48
+ show_help
49
+ else
50
+ run_program ARGV.first
51
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  class FalseClass
3
4
  def to_s = "False"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  def copyright()
3
4
  text = <<~TEXT
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  def credits()
3
4
  text = <<~TEXT
4
5
  Thanks to Free Software, Yukuhiro Matzumoto, David Vargas Ruiz
5
6
  and a cast of thousands for supporting nPython
6
- development. See www.npython.org for more information.
7
+ development. See github.com/dvarrui/dsl-python for more information.
7
8
  TEXT
8
9
  puts text
9
10
  "(Credits)"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  class Hash
3
4
  def to_s
@@ -1,8 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ this = "this"
1
4
 
2
5
  def import(name)
3
- if File.exist? name
6
+ fullname = name + ".py"
7
+ if name.to_s == "this"
8
+ show_zen
9
+ elsif File.exist? name
4
10
  load name
5
11
  else
6
- load name + ".py"
12
+ puts "npython: can't open file '#{name}': [Errno 2] No such file or directory"
7
13
  end
8
14
  end
15
+
16
+ def show_zen
17
+ text = <<~TEXT
18
+ El Zen de nPython (Inspirado por Matz)
19
+
20
+ 1. La felicidad del programador es el fin último.
21
+ 2. Lo natural es mejor que lo explícito.
22
+ 3. La libertad es mejor que la restricción.
23
+ 4. La elegancia supera a la brevedad.
24
+ 5. Muchos caminos son mejores que uno solo (TIMTOWTDI).
25
+ 6. Si el código se lee como prosa, es buen código.
26
+ 7. No castigues al programador por ser inteligente.
27
+ 8. La pureza del objeto es sagrada.
28
+ 9. La metaprogramación es un superpoder, úsalo con sabiduría.
29
+ 10. El lenguaje debe adaptarse al humano, no el humano al lenguaje.
30
+ 11. Un bloque es a menudo la respuesta.
31
+ 12. Los símbolos son mejores que los strings para la identidad.
32
+ 13. El principio de Menor Sorpresa es subjetivo, pero vital.
33
+ 14. Si te hace sonreír al escribirlo, es Ruby.
34
+ TEXT
35
+ puts text
36
+ "(Zen)"
37
+ end
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  def license()
3
4
  text = <<~TEXT
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  None = nil
3
4
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  def range(value)
2
4
  Range.new(0,value - 1)
3
5
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Dsl
4
4
  module Python
5
- VERSION="0.16.0"
5
+ VERSION="0.17.0"
6
6
  end
7
7
  end
8
8
 
data/lib/dsl/python.rb CHANGED
@@ -6,6 +6,7 @@ require_relative "python/copyright"
6
6
  require_relative "python/credits"
7
7
  require_relative "python/none"
8
8
  require_relative "python/hashes"
9
+ require_relative "python/import"
9
10
  require_relative "python/license"
10
11
  require_relative "python/ranges"
11
12
  require_relative "python/strings"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsl-python
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas Ruiz