rpl 0.1.1 → 0.2.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 +4 -4
- data/bin/rpl +38 -3
- data/lib/rpl/interpreter.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c0b6dde921b1be42f37aada134849b5a96f458243f261e14b4bc4d7b17175d3
|
4
|
+
data.tar.gz: 0bac9ebecadaab0cc5ac023284dbad7a12d6e543e4b266b52cdcdd5815933e24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c26e7c6146a97efd4dc45d7f2f93979156d459a47a7e3c6aa93b2ad4afac4f1fd40e5fcb67f5052e9a026dbb20109fae9dcd93cf5501e9e7d9f60ef469d41f7
|
7
|
+
data.tar.gz: a282895d927482056affe83b864b985f8251e97e6b6e80eb742959cfa7adaf0901739e3f45fb0ba3cf8ce0cd3f4851b51671c8b6e454d377a5963f963a86304d
|
data/bin/rpl
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'English'
|
5
|
+
require 'optparse'
|
4
6
|
require 'readline'
|
5
7
|
|
6
8
|
require 'rpl'
|
7
9
|
|
8
10
|
class RplRepl
|
9
|
-
def initialize
|
10
|
-
|
11
|
+
def initialize( interpreter )
|
12
|
+
interpreter ||= Rpl.new
|
13
|
+
@interpreter = interpreter
|
11
14
|
end
|
12
15
|
|
13
16
|
def run
|
17
|
+
print_stack unless @interpreter.stack.empty?
|
18
|
+
|
14
19
|
Readline.completion_proc = proc do |s|
|
15
20
|
( @interpreter.dictionary.words.keys + @interpreter.dictionary.vars.keys ).grep(/^#{Regexp.escape(s)}/)
|
16
21
|
end
|
@@ -48,4 +53,34 @@ class RplRepl
|
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
|
-
|
56
|
+
interpreter = Rpl.new
|
57
|
+
|
58
|
+
options = { run_REPL: ARGV.empty?,
|
59
|
+
files: [],
|
60
|
+
programs: [] }
|
61
|
+
|
62
|
+
OptionParser.new do |opts|
|
63
|
+
opts.on('-c', '--code "program"', ' ') do |program|
|
64
|
+
options[:programs] << program
|
65
|
+
end
|
66
|
+
|
67
|
+
opts.on('-f', '--file program.rpl', 'load program.rpl') do |filename|
|
68
|
+
options[:files] << filename
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on('-i', '--interactive', 'launch interactive REPL') do
|
72
|
+
options[:run_REPL] = true
|
73
|
+
end
|
74
|
+
end.parse!
|
75
|
+
|
76
|
+
options[:files].each do |filename|
|
77
|
+
interpreter.run "\"#{filename}\" feval"
|
78
|
+
end
|
79
|
+
|
80
|
+
options[:programs].each do |program|
|
81
|
+
interpreter.run program
|
82
|
+
end
|
83
|
+
|
84
|
+
RplRepl.new( interpreter ).run if options[:run_REPL]
|
85
|
+
|
86
|
+
pp interpreter.stack.map { |elt| interpreter.stringify( elt ) }.join(' ')
|
data/lib/rpl/interpreter.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gwenhael Le Moine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A language inspired by HP's RPL and https://github.com/louisrubet/rpn/
|
14
14
|
email: gwenhael@le-moine.org
|