dsl-python 0.17.0 → 0.19.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: 53730ec810f653d2a91efbc21fdfb976eb63b7449939d5ac91eb2052926a98a9
4
- data.tar.gz: e42b22f0d6cf72fb20b1898940cad1f02af4d4b6d0f6e0337a063d0765ee5dd1
3
+ metadata.gz: febe5712a15cb8f68bb07dac949484bb607d46b283a76181a63db4ddb70d6faa
4
+ data.tar.gz: 5c1a5e28bbd0db0d972e494cb7fa9439432bc32b3869022e4d8d5ae9fac2270a
5
5
  SHA512:
6
- metadata.gz: 635779c8d1814833c4981cfe8b55dc655030faafdd35a13efa4e3e24a63f5021027f14509de2276f305967e55f1bf3ef36e5451ffa6dc7f335998d87e1e7f06c
7
- data.tar.gz: 736bc13886414941ca91c99e1ef1fd12c022da9c401fd3277910d35bf6ff37b63fd3375fadd246960161336cd6418c0da153de641e5acb510c9d83cf9f128b2c
6
+ metadata.gz: cb22bfbef89bc09178df63299a45080f70212d60fcb0c48771c3a716f35c251b3685ebf88cdbbdd2b1ff413c2fe24433d5862400a871217b43fb06f6016565cd
7
+ data.tar.gz: 36a5c4e75e6cdf706135159229b5f6608d5e164a8468359923149713adba10d6a28449655d856f2e6b0ca2e29fdd5f7287ecebb3d0161c71aae6914cda35bc3e
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Dsl::Python
2
2
 
3
3
  ```
4
- DSL para programar en Python usando Ruby.
4
+ DSL para hacer que Ruby "parezca" Python
5
5
  ```
6
6
 
7
- Este es un proyecto que no tiene utilidad práctica. El objetivo era poner a prueba las características del lenguaje Ruby para crear un DSL de Python en un corto espacio de tiempo.
7
+ Este proyecto que no tiene utilidad práctica. El objetivo es poner a prueba las capacidades del lenguaje Ruby para crear un DSL de Python en un corto espacio de tiempo.
8
8
 
9
- > NOTA: `Dsl::Python` usa bloques delimitados por `end`, en lugar del clásico sangrado de Python.
9
+ > **NOTA**: La principal diferencia con el original, es que se usa la palabra reservada `end` para delimitar el final de bloque, en lugar de los `:` y sangrado.
10
10
 
11
11
  ## Instalación
12
12
 
@@ -18,13 +18,13 @@ Este es un proyecto que no tiene utilidad práctica. El objetivo era poner a pru
18
18
  Crear un programa con el contenido de un programa Python:
19
19
 
20
20
  ```python
21
- x = 4 #=> x is of type int
22
- print(x)
23
- print(type(x))
21
+ name = "Obiwan Kwnobi"
22
+ print(name)
23
+ print(type(name)) #=> name is str class
24
24
 
25
- x = "Obiwan" #=> x is now of type str
26
- print(x)
27
- print(type(x))
25
+ words = name.split()
26
+ print(words)
27
+ print(type(words)) #=> words is list class
28
28
  ```
29
29
 
30
30
  * Ejecutar con el "intérprete": `npython FILENAME`.
@@ -32,9 +32,9 @@ print(type(x))
32
32
  ```bash
33
33
  $ npython examples/03-variables.py
34
34
  4
35
- <type 'int'>
35
+ <class 'int'>
36
36
  Obiwan
37
- <type 'str'>
37
+ <class 'str'>
38
38
  ```
39
39
 
40
40
  > Más [ejemplos](./examples/)
@@ -42,13 +42,14 @@ Obiwan
42
42
  ## Features
43
43
 
44
44
  * Intérpre interactivo `npython`.
45
- * Booleans
46
- * Diccionarios
47
- * import "this"
48
- * None
49
- * Ranges
50
- * Strings
51
- * Type
45
+ - Se muestra el Zen de nPython: `import this`, `import that`, `zen`.
46
+ * Tipos de datos:
47
+ - Booleans: `True`, `False`
48
+ - Diccionarios: `dict = {"name": "Obiwan", "age": 55}`
49
+ - None
50
+ - Ranges
51
+ - Strings: `join`.
52
+ * Funciones comunes: `id`, `len`, `type`
52
53
 
53
54
  ## Contributing
54
55
 
@@ -58,4 +59,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/dvarru
58
59
 
59
60
  Enlaces de interés:
60
61
 
62
+ * [dsl-clang](https://github.com/dvarrui/dsl-clang)
63
+ * [dsl-graph](https://github.com/dvarrui/dsl-graph)
61
64
  * [dsl-latin](https://github.com/dvarrui/dsl-latin)
data/bin/npython CHANGED
@@ -1,51 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
- require "dsl/python"
3
- require "dsl/python/version"
4
2
 
5
- VERSION=Dsl::Python::VERSION
6
-
7
- def open_repl
8
- text = <<~TEXT
9
- nPython #{VERSION} (main, Nov 16 1970) [GCC] on linux
10
- Type "help", "copyright", "credits" or "license" for more information.
11
- TEXT
12
- puts text
13
- system("irb --prompt simple --nocolorize --noecho-on-assignment -Ilib -rdsl/python")
14
- end
15
-
16
- def show_version
17
- puts "npython (#{VERSION})"
18
- end
19
-
20
- def show_help
21
- text = <<~TEXT
22
- usage: npython [option | file ]
23
- Options:
24
- -h : print this help message and exit (also -? or --help)
25
- -v : show current version (also -V or --version)
26
-
27
- Arguments:
28
- file : program read from script file
29
- TEXT
30
- puts text
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)
40
- eval(content)
41
- end
3
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
4
+ require "dsl/python/cli"
42
5
 
43
6
  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
7
+ Dsl::Python.open_repl
8
+ elsif ["v", "-v", "--version", "-V"].include? ARGV.first
9
+ Dsl::Python.show_version
10
+ elsif ["h", "-h", "--help", "-?"].include? ARGV.first
11
+ Dsl::Python.show_help
49
12
  else
50
13
  run_program ARGV.first
51
14
  end
@@ -0,0 +1,109 @@
1
+
2
+ # PiByrras 202605
3
+
4
+ * Abrir REPL python3 y npython
5
+
6
+ ```
7
+ name = "Obiwan"
8
+ len(name)
9
+ type(name)
10
+ name.__len__()
11
+
12
+ >>> name = name + " Kenobi"
13
+ >>> name
14
+ 'Obiwan Kenobi'
15
+ >>> name = name.__add__(" Kenobi")
16
+ >>> name
17
+ 'Obiwan Kenobi Kenobi'
18
+ >>> print(name)
19
+ Obiwan Kenobi Kenobi
20
+ >>> len(name)
21
+ 20
22
+ >>>
23
+ True
24
+ >>> id(16)
25
+ 140717975471496
26
+ >>> id(16)
27
+ 140717975471496
28
+ >>> id(16)
29
+ 140717975471496
30
+ >>> id(256)
31
+ 140717975479176
32
+ >>> id(256)
33
+ 140717975479176
34
+ >>> id(257)
35
+ 2647436846352
36
+ >>> id(257)
37
+ 2647436845104
38
+ >>> id(257)
39
+ 2647436845232
40
+ >>> id(257)
41
+ 2647436845328
42
+ >>> a = "obiwan"
43
+ >>> b = "obiwan"
44
+ >>> id(a)
45
+ 2647432805904
46
+ >>> id(b)
47
+ 2647432805904
48
+ >>>
49
+
50
+ --
51
+ Crear método .__ para "mostrar" todos los métodos "ocultos" de broma.
52
+ crear función id que invoque a object_id.
53
+ ---
54
+ Trabajar con las clases:
55
+ crear un alias de initialize a __init__... es posible?
56
+ hacer metaprogramación para self.name= name
57
+ cree @name = name
58
+
59
+ >>> class Persona:
60
+ ...     def __init__(self, name, age):
61
+ ...         self.name = name
62
+ ...         self.age = age
63
+ ...
64
+ >>> obiwan = Persona("Obiwan")
65
+ Traceback (most recent call last):
66
+   File "<python-input-59>", line 1, in <module>
67
+     obiwan = Persona("Obiwan")
68
+ TypeError: Persona.__init__() missing 1 required positional argument: 'age'
69
+ >>> obiwan = Persona("Obiwan", 55)
70
+ >>> print(obiwan)
71
+ <__main__.Persona object at 0x000002686780A210>
72
+
73
+ >>> type(obiwan)
74
+ <class '__main__.Persona'>
75
+ >>>
76
+
77
+ ---
78
+ >>> type(obiwan)
79
+ <class '__main__.Persona'>
80
+ >>> class Persona:
81
+ ...     class Persona:
82
+ ...         print("hola")
83
+ ...
84
+ hola
85
+ >>> class Persona:
86
+ ...     class Persona:
87
+ ...         print("hola")
88
+ ...     a = Persona()
89
+ ...     print(a)
90
+ ...     print(type(a))
91
+ ...
92
+ hola
93
+ <__main__.Persona.Persona object at 0x00000268678A86E0>
94
+ <class '__main__.Persona.Persona'>
95
+
96
+ ---
97
+
98
+ >>> obiwan.age
99
+ 55
100
+ >>> obiwan.age= 56
101
+ >>> obiwan.age
102
+ 56
103
+ >>> if obiwan.age > 18:
104
+ ...     print("Adulto")
105
+ ...
106
+ Adulto
107
+ >>>
108
+ --
109
+ ```
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "io/console"
4
+
5
+ # Códigos ANSI de color:
6
+ # Color Código Uso en Ruby
7
+ # Rojo \e[31m puts "\e[31mEste texto es rojo\e[0m"
8
+ # Verde \e[32m puts "\e[32mEste texto es verde\e[0m"
9
+ # Amarillo \e[33m puts "\e[33mEste texto es amarillo\e[0m"
10
+ # Reset \e[0m (Obligatorio para volver al color normal)
11
+
12
+ class ANSI
13
+ COLORS = {
14
+ red: "\e[31m",
15
+ green: "\e[32m",
16
+ yellow: "\e[33m"
17
+ }
18
+ RESET = "\e[0m"
19
+ CLEAR_SCREEN = "\e[2J\e[H"
20
+
21
+ attr_reader :height, :width
22
+
23
+ def initialize
24
+ @height, @width = `stty size`.split.map { _1.to_i }
25
+ end
26
+
27
+ def green(text)
28
+ print_with_color(:green, text)
29
+ end
30
+
31
+ def red(text)
32
+ print_with_color(:red, text)
33
+ end
34
+
35
+ def yellow(text)
36
+ print_with_color(:yellow, text)
37
+ end
38
+
39
+ def print_with_color(color, text)
40
+ "#{COLORS[color]}#{text}#{RESET}"
41
+ end
42
+
43
+ def self.clear_screen
44
+ print "\e[2J\e[H"
45
+ end
46
+
47
+ def self.move_cursor(row, col)
48
+ print "\033[#{row};#{col}H"
49
+ end
50
+
51
+ def self.reset_cursor
52
+ print "\e[0m"
53
+ end
54
+
55
+ def self.print_text_at(row, col, text)
56
+ print "\033[#{row + 1};#{col}H"
57
+ print text
58
+ print "\e[0m"
59
+ end
60
+
61
+ def self.pressed_key
62
+ char = begin
63
+ STDIN.read_nonblock(3)
64
+ rescue
65
+ nil
66
+ end
67
+ return nil unless char
68
+
69
+ case char
70
+ when "\e[A" then :up
71
+ when "\e[B" then :down
72
+ when "\e[C" then :right
73
+ when "\e[D" then :left
74
+ when "q" then :quit
75
+ else char
76
+ end
77
+ end
78
+
79
+ def self.set_raw_mode
80
+ STDIN.echo = false
81
+ STDIN.raw!
82
+ end
83
+
84
+ def self.set_cooked_mode
85
+ STDIN.cooked!
86
+ STDIN.echo = true
87
+ end
88
+ end
@@ -0,0 +1,45 @@
1
+ require_relative "../python"
2
+ require_relative "version"
3
+
4
+ # VERSION=Dsl::Python::VERSION
5
+
6
+ module Dsl
7
+ module Python
8
+ def self.open_repl
9
+ text = <<~TEXT
10
+ nPython #{VERSION} (main, Nov 16 1970) [GCC] on linux
11
+ Type "help", "copyright", "credits" or "license" for more information.
12
+ TEXT
13
+ puts text
14
+ system("irb --nobanner --prompt simple --nocolorize --noecho-on-assignment -Ilib -rdsl/python")
15
+ end
16
+
17
+ def self.show_version
18
+ puts "npython #{VERSION}"
19
+ end
20
+
21
+ def self.show_help
22
+ text = <<~TEXT
23
+ usage: npython [option | file ]
24
+ Options:
25
+ -h : print this help message and exit (also -? or --help)
26
+ -v : show current version (also -V or --version)
27
+
28
+ Arguments:
29
+ file : program read from script file
30
+ TEXT
31
+ puts text
32
+ end
33
+ end
34
+ end
35
+
36
+ def run_program(filepath)
37
+ unless File.exist? filepath
38
+ puts "npython: can't open file '#{filepath}': [Errno 2] No such file or directory"
39
+ exit 1
40
+ end
41
+
42
+ $main_filepath = filepath
43
+ content = File.read(filepath)
44
+ eval(content)
45
+ end
@@ -0,0 +1,15 @@
1
+ def len(obj)
2
+ if obj.respond_to?(:length)
3
+ obj.length
4
+ elsif obj.respond_to?(:count)
5
+ obj.count
6
+ elsif obj.respond_to?(:size)
7
+ obj.size
8
+ else
9
+ puts "TypeError: object of type '#{type(obj)}' has no len()"
10
+ end
11
+ end
12
+
13
+ def id(obj)
14
+ obj.object_id
15
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../repl/zen"
4
+
5
+ $main_binding = binding
6
+
7
+ def import(filename)
8
+ filename.to_s
9
+ dirbase = File.dirname($main_filepath)
10
+ filepath = File.join(dirbase, filename + ".py")
11
+
12
+ if filename.to_s == "this"
13
+ Dsl::Python.show_zen
14
+ elsif filename.to_s == "that"
15
+ Dsl::Python.show_zen(ofuscate: true)
16
+ elsif File.exist? filepath
17
+
18
+ content = File.read(filepath)
19
+ eval(content, $main_binding)
20
+ else
21
+ puts "npython: can't open file '#{filepath}': [Errno 2] No such file or directory"
22
+ end
23
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  def type(x)
3
4
  key = x.class.to_s.to_sym
@@ -12,7 +13,8 @@ def type(x)
12
13
  String: "str",
13
14
  TrueClass: "bool"
14
15
  }
15
- "<type '#{types[key]}'>"
16
+
17
+ "<class '#{types[key]}'>"
16
18
  end
17
19
 
18
20
  def float(obj) = obj.to_f
@@ -1 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
3
+ # Sintaxis: type(nombre_de_la_clase, bases_de_las_que_hereda, diccionario_de_atributos)
4
+ # Persona = type('Persona', (), {'saludar': lambda self: "¡Hola!"})
5
+
6
+ # Ahora puedes usarla como cualquier clase normal:
7
+ # instancia = Persona()
8
+ # print(instancia.saludar()) # Resultado: ¡Hola!
9
+ # print(type(instancia)) # Resultado: <class '__main__.Persona'>
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ def copyright
4
+ text = <<~TEXT
5
+ Copyright (c) 2025-2025 nPython Software Foundation.
6
+ All Rights Reserved.
7
+ TEXT
8
+ puts text
9
+ "(Copyright)"
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ def credits
4
+ text = <<~TEXT
5
+ Thanks to Free Software, Yukuhiro Matzumoto, David Vargas Ruiz
6
+ and a cast of thousands for supporting nPython development.
7
+ See 'github.com/dvarrui/dsl-python' for more information.
8
+ TEXT
9
+ puts text
10
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../ansi"
4
+
5
+ def whoareyou
6
+ name = ANSI.new.green("dsl-python")
7
+ puts " Hi! I'm a ruby gem called '#{name}'."
8
+ end
9
+
10
+ def whereareyou
11
+ text = ANSI.new.green("https://github.com/dvarrui/dsl-python")
12
+ puts " You can find me at: #{text}"
13
+ text = ANSI.new.green("https://rubygems.org/gems/dsl-python")
14
+ puts " And also at: #{text}"
15
+ nil
16
+ end
17
+
18
+ def bye
19
+ puts ""
20
+ system("figlet 'I love Ruby'")
21
+ puts ""
22
+ exit
23
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ def license
4
+ text = <<~TEXT
5
+ nPython is copyrighted free software by David Vargas Ruiz <dvarrui@proton.me>.
6
+ You can redistribute it and/or modify it under either the terms of the
7
+ 2-clause BSDL (see the file BSDL), or the conditions below:
8
+
9
+ 1. You may make and give away verbatim copies of the source form of the
10
+ software without restriction, provided that you duplicate all of the
11
+ original copyright notices and associated disclaimers.
12
+
13
+ 2. You may modify your copy of the software in any way, provided that
14
+ you do at least ONE of the following:
15
+
16
+ a) place your modifications in the Public Domain or otherwise
17
+ make them Freely Available, such as by posting said
18
+ modifications to Usenet or an equivalent medium, or by allowing
19
+ the author to include your modifications in the software.
20
+
21
+ b) use the modified software only within your corporation or
22
+ organization.
23
+
24
+ c) give non-standard binaries non-standard names, with
25
+ instructions on where to get the original software distribution.
26
+
27
+ d) make other distribution arrangements with the author.
28
+
29
+ 3. You may distribute the software in object code or binary form,
30
+ provided that you do at least ONE of the following:
31
+
32
+ a) distribute the binaries and library files of the software,
33
+ together with instructions (in the manual page or equivalent)
34
+ on where to get the original distribution.
35
+
36
+ b) accompany the distribution with the machine-readable source of
37
+ the software.
38
+
39
+ c) give non-standard binaries non-standard names, with
40
+ instructions on where to get the original software distribution.
41
+
42
+ d) make other distribution arrangements with the author.
43
+
44
+ 4. You may modify and include the part of the software into any other
45
+ software (possibly commercial). But some files in the distribution
46
+ are not written by the author, so that they are not under these terms.
47
+
48
+ For the list of those files and their copying conditions, see the
49
+ file LEGAL.
50
+
51
+ 5. The scripts and library files supplied as input to or produced as
52
+ output from the software do not automatically fall under the
53
+ copyright of the software, but belong to whomever generated them,
54
+ and may be sold commercially, and may be aggregated with this
55
+ software.
56
+
57
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
58
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
59
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60
+ PURPOSE.
61
+ TEXT
62
+ puts text
63
+ "(License)"
64
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../ansi"
4
+
5
+ def this
6
+ "this"
7
+ end
8
+
9
+ def that
10
+ "that"
11
+ end
12
+
13
+ def zen
14
+ Dsl::Python.show_zen
15
+ end
16
+
17
+ module Dsl
18
+ module Python
19
+ def self.show_zen(ofuscate: false)
20
+ text = <<~TEXT
21
+ El Zen de nPython (Inspirado por Matz)
22
+
23
+ 1. La felicidad del programador es el fin último.
24
+ 2. Lo natural es mejor que lo explícito.
25
+ 3. La libertad es mejor que la restricción.
26
+ 4. La elegancia supera a la brevedad.
27
+ 5. Muchos caminos son mejores que uno solo (TIMTOWTDI).
28
+ 6. Si el código se lee como prosa, es buen código.
29
+ 7. No castigues al programador por ser inteligente.
30
+ 8. La pureza del objeto es sagrada.
31
+ 9. La metaprogramación es un superpoder, úsalo con sabiduría.
32
+ 10. El lenguaje debe adaptarse al humano, no el humano al lenguaje.
33
+ 11. Un bloque es a menudo la respuesta.
34
+ 12. Los símbolos son mejores que los strings para la identidad.
35
+ 13. El principio de Menor Sorpresa es subjetivo, pero vital.
36
+ 14. Si te hace sonreír al escribirlo, es Ruby.
37
+ TEXT
38
+
39
+ lines = text.split("\n")
40
+ lines.each_with_index do |line, index|
41
+ if line.empty?
42
+ puts ""
43
+ next
44
+ end
45
+ words = line.split
46
+ index = if index.zero?
47
+ words.shift
48
+ else
49
+ ANSI.new.green(words.shift)
50
+ end
51
+ text = words.join(" ")
52
+ text = text.gsub(/[^\d\s]/, "*") if ofuscate
53
+ puts " #{index} #{text}"
54
+ end
55
+ nil
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Array
4
+ def __
5
+ puts <<-METHODS
6
+ list.__add__( list.__ge__( list.__iter__() list.__reversed__()
7
+ list.__class__( list.__getattribute__( list.__le__( list.__rmul__(
8
+ list.__class_getitem__( list.__getitem__( list.__len__() list.__setattr__(
9
+ list.__contains__( list.__getstate__() list.__lt__( list.__setitem__(
10
+ list.__delattr__( list.__gt__( list.__mul__( list.__sizeof__()
11
+ list.__delitem__( list.__hash__ list.__ne__( list.__str__()
12
+ list.__dir__() list.__iadd__( list.__new__( list.__subclasshook__(
13
+ list.__doc__ list.__imul__( list.__reduce__()
14
+ list.__eq__( list.__init__( list.__reduce_ex__(
15
+ list.__format__( list.__init_subclass__() list.__repr__()
16
+ METHODS
17
+ end
18
+
19
+ def to_s
20
+ inspect
21
+ end
22
+ end
@@ -10,4 +10,3 @@ end
10
10
 
11
11
  True = true
12
12
  False = false
13
-
@@ -2,7 +2,7 @@
2
2
 
3
3
  class Hash
4
4
  def to_s
5
- values = self.map do
5
+ values = map do
6
6
  value1 = _1
7
7
  value1 = "'#{_1}'" if _1.is_a? String
8
8
  value2 = _2
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Integer
4
+ def __
5
+ puts <<~TEXT
6
+ int.__abs__() int.__floordiv__( int.__le__( int.__rdivmod__( int.__rsub__(
7
+ int.__add__( int.__format__( int.__lshift__( int.__reduce__() int.__rtruediv__(
8
+ int.__and__( int.__ge__( int.__lt__( int.__reduce_ex__( int.__rxor__(
9
+ int.__bool__() int.__getattribute__( int.__mod__( int.__repr__() int.__setattr__(
10
+ int.__ceil__() int.__getnewargs__() int.__mul__( int.__rfloordiv__( int.__sizeof__()
11
+ int.__class__( int.__getstate__() int.__ne__( int.__rlshift__( int.__str__()
12
+ int.__delattr__( int.__gt__( int.__neg__() int.__rmod__( int.__sub__(
13
+ int.__dir__() int.__hash__() int.__new__( int.__rmul__( int.__subclasshook__(
14
+ int.__divmod__( int.__index__() int.__or__( int.__ror__( int.__truediv__(
15
+ int.__doc__ int.__init__( int.__pos__() int.__round__( int.__trunc__()
16
+ int.__eq__( int.__init_subclass__() int.__pow__( int.__rpow__( int.__xor__(
17
+ int.__float__() int.__int__() int.__radd__( int.__rrshift__(
18
+ int.__floor__() int.__invert__() int.__rand__( int.__rshift__(
19
+ TEXT
20
+ end
21
+
22
+ def __add__(other)
23
+ self + other
24
+ end
25
+
26
+ def __floordiv__(other)
27
+ self / other
28
+ end
29
+
30
+ def __mul__(other)
31
+ self * other
32
+ end
33
+
34
+ def __sub__(other)
35
+ self - other
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  def range(value)
4
- Range.new(0,value - 1)
4
+ Range.new(0, value - 1)
5
5
  end
@@ -0,0 +1,33 @@
1
+ class String
2
+ def format(arg)
3
+ self % arg
4
+ end
5
+
6
+ def join(list)
7
+ list.join(self)
8
+ end
9
+
10
+ def lower
11
+ downcase
12
+ end
13
+
14
+ def upper
15
+ upcase
16
+ end
17
+
18
+ def replace(a, b)
19
+ tr(a, b)
20
+ end
21
+
22
+ def __
23
+ puts " str.__add__( str.__getattribute__( str.__le__( str.__repr__()
24
+ str.__class__( str.__getitem__( str.__len__() str.__rmod__(
25
+ str.__contains__( str.__getnewargs__() str.__lt__( str.__rmul__(
26
+ str.__delattr__( str.__getstate__() str.__mod__( str.__setattr__(
27
+ str.__dir__() str.__gt__( str.__mul__( str.__sizeof__()
28
+ str.__doc__ str.__hash__() str.__ne__( str.__str__()
29
+ str.__eq__( str.__init__( str.__new__( str.__subclasshook__(
30
+ str.__format__( str.__init_subclass__() str.__reduce__()
31
+ str.__ge__( str.__iter__() str.__reduce_ex__( "
32
+ end
33
+ end
@@ -2,11 +2,11 @@
2
2
 
3
3
  module Dsl
4
4
  module Python
5
- VERSION="0.17.0"
5
+ VERSION = "0.19.0"
6
6
  end
7
7
  end
8
8
 
9
- def version()
9
+ def version
10
10
  puts Dsl::Python::VERSION
11
11
  "(Version)"
12
12
  end
data/lib/dsl/python.rb CHANGED
@@ -1,27 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "python/import"
4
- require_relative "python/booleans"
5
- require_relative "python/copyright"
6
- require_relative "python/credits"
7
- require_relative "python/none"
8
- require_relative "python/hashes"
9
- require_relative "python/import"
10
- require_relative "python/license"
11
- require_relative "python/ranges"
12
- require_relative "python/strings"
13
- require_relative "python/type"
3
+ require_relative "python/repl/copyright"
4
+ require_relative "python/repl/credits"
5
+ require_relative "python/repl/etc"
6
+ require_relative "python/repl/license"
7
+ require_relative "python/repl/zen"
8
+
9
+ require_relative "python/types/array"
10
+ require_relative "python/types/boolean"
11
+ require_relative "python/types/hash"
12
+ require_relative "python/types/integer"
13
+ require_relative "python/types/none"
14
+ require_relative "python/types/range"
15
+ require_relative "python/types/string"
16
+
17
+ require_relative "python/functions/etc"
18
+ require_relative "python/functions/import"
19
+ require_relative "python/functions/type"
20
+
14
21
  require_relative "python/version"
15
22
 
16
23
  def print(*args)
17
24
  if args.is_a? Array
18
- puts args.join(" ")
25
+ if args.count == 1
26
+ puts args.first
27
+ else
28
+ puts args.join " "
29
+ end
19
30
  else
20
31
  puts(args)
21
32
  end
22
33
  end
23
34
 
24
-
25
35
  module Dsl
26
36
  module Python
27
37
  class Error < StandardError; end
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.17.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas Ruiz
@@ -18,22 +18,31 @@ extensions: []
18
18
  extra_rdoc_files:
19
19
  - LICENSE
20
20
  - README.md
21
+ - docs/pybirras-2026.md
21
22
  files:
22
23
  - LICENSE
23
24
  - README.md
24
25
  - bin/npython
26
+ - docs/pybirras-2026.md
25
27
  - lib/dsl/python.rb
26
- - lib/dsl/python/booleans.rb
27
- - lib/dsl/python/copyright.rb
28
- - lib/dsl/python/credits.rb
29
- - lib/dsl/python/hashes.rb
30
- - lib/dsl/python/import.rb
28
+ - lib/dsl/python/ansi.rb
29
+ - lib/dsl/python/cli.rb
30
+ - lib/dsl/python/functions/etc.rb
31
+ - lib/dsl/python/functions/import.rb
32
+ - lib/dsl/python/functions/type.rb
31
33
  - lib/dsl/python/klasses.rb
32
- - lib/dsl/python/license.rb
33
- - lib/dsl/python/none.rb
34
- - lib/dsl/python/ranges.rb
35
- - lib/dsl/python/strings.rb
36
- - lib/dsl/python/type.rb
34
+ - lib/dsl/python/repl/copyright.rb
35
+ - lib/dsl/python/repl/credits.rb
36
+ - lib/dsl/python/repl/etc.rb
37
+ - lib/dsl/python/repl/license.rb
38
+ - lib/dsl/python/repl/zen.rb
39
+ - lib/dsl/python/types/array.rb
40
+ - lib/dsl/python/types/boolean.rb
41
+ - lib/dsl/python/types/hash.rb
42
+ - lib/dsl/python/types/integer.rb
43
+ - lib/dsl/python/types/none.rb
44
+ - lib/dsl/python/types/range.rb
45
+ - lib/dsl/python/types/string.rb
37
46
  - lib/dsl/python/version.rb
38
47
  homepage: https://github.com/dvarrui/dsl-python
39
48
  licenses:
@@ -56,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
65
  - !ruby/object:Gem::Version
57
66
  version: '0'
58
67
  requirements: []
59
- rubygems_version: 3.7.2
68
+ rubygems_version: 4.0.10
60
69
  specification_version: 4
61
70
  summary: DSL para programar Python usando Ruby
62
71
  test_files: []
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- def copyright()
4
- text = <<~TEXT
5
- Copyright (c) 2025-2025 nPython Software Foundation.
6
- All Rights Reserved.
7
- TEXT
8
- puts text
9
- "(Copyright)"
10
- end
11
-
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- def credits()
4
- text = <<~TEXT
5
- Thanks to Free Software, Yukuhiro Matzumoto, David Vargas Ruiz
6
- and a cast of thousands for supporting nPython
7
- development. See github.com/dvarrui/dsl-python for more information.
8
- TEXT
9
- puts text
10
- "(Credits)"
11
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- this = "this"
4
-
5
- def import(name)
6
- fullname = name + ".py"
7
- if name.to_s == "this"
8
- show_zen
9
- elsif File.exist? name
10
- load name
11
- else
12
- puts "npython: can't open file '#{name}': [Errno 2] No such file or directory"
13
- end
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
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- def license()
4
- text = <<~TEXT
5
- nPython is copyrighted free software by David Vargas Ruiz <dvarrui@proton.me>.
6
- You can redistribute it and/or modify it under either the terms of the
7
- 2-clause BSDL (see the file BSDL), or the conditions below:
8
-
9
- 1. You may make and give away verbatim copies of the source form of the
10
- software without restriction, provided that you duplicate all of the
11
- original copyright notices and associated disclaimers.
12
-
13
- 2. You may modify your copy of the software in any way, provided that
14
- you do at least ONE of the following:
15
-
16
- a) place your modifications in the Public Domain or otherwise
17
- make them Freely Available, such as by posting said
18
- modifications to Usenet or an equivalent medium, or by allowing
19
- the author to include your modifications in the software.
20
-
21
- b) use the modified software only within your corporation or
22
- organization.
23
-
24
- c) give non-standard binaries non-standard names, with
25
- instructions on where to get the original software distribution.
26
-
27
- d) make other distribution arrangements with the author.
28
-
29
- 3. You may distribute the software in object code or binary form,
30
- provided that you do at least ONE of the following:
31
-
32
- a) distribute the binaries and library files of the software,
33
- together with instructions (in the manual page or equivalent)
34
- on where to get the original distribution.
35
-
36
- b) accompany the distribution with the machine-readable source of
37
- the software.
38
-
39
- c) give non-standard binaries non-standard names, with
40
- instructions on where to get the original software distribution.
41
-
42
- d) make other distribution arrangements with the author.
43
-
44
- 4. You may modify and include the part of the software into any other
45
- software (possibly commercial). But some files in the distribution
46
- are not written by the author, so that they are not under these terms.
47
-
48
- For the list of those files and their copying conditions, see the
49
- file LEGAL.
50
-
51
- 5. The scripts and library files supplied as input to or produced as
52
- output from the software do not automatically fall under the
53
- copyright of the software, but belong to whomever generated them,
54
- and may be sold commercially, and may be aggregated with this
55
- software.
56
-
57
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
58
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
59
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60
- PURPOSE.
61
- TEXT
62
- puts text
63
- "(License)"
64
- end
65
-
@@ -1,18 +0,0 @@
1
-
2
- class String
3
- def lower
4
- self.downcase
5
- end
6
-
7
- def upper
8
- self.upcase
9
- end
10
-
11
- def replace(a, b)
12
- self.tr(a, b)
13
- end
14
-
15
- def format(arg)
16
- self % arg
17
- end
18
- end
File without changes