pal 0.0.1 → 0.1.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.
- data/bin/pal +1 -2
- data/lib/pal.rb +18 -23
- metadata +3 -4
data/bin/pal
CHANGED
data/lib/pal.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
require "readline"
|
2
|
-
|
3
1
|
# Public: Exposes a simple read-eval-print loop interface.
|
4
2
|
module Pal
|
5
3
|
# Public: The current version of Pal.
|
6
|
-
Version = "0.0
|
4
|
+
Version = "0.1.0"
|
7
5
|
|
8
6
|
# Public: Defines the evaluation context. All instance methods defined in
|
9
7
|
# this class are made available as top-level methods during evaluation.
|
@@ -29,18 +27,6 @@ module Pal
|
|
29
27
|
# Public: Gets the result of the last-evaluated expression.
|
30
28
|
attr_reader :result
|
31
29
|
|
32
|
-
class << self
|
33
|
-
# Internal: Gets the current REPL instance.
|
34
|
-
attr_reader :messenger
|
35
|
-
|
36
|
-
# Public: Creates a new REPL instance. The `messenger` class instance
|
37
|
-
# variable is used by the REPL instance to correctly set and expose
|
38
|
-
# the result of the last-evaluated expression to the evaluation context.
|
39
|
-
def create(name = "pal", context = Context.new)
|
40
|
-
@messenger = new(name, context)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
30
|
def initialize(name, context)
|
45
31
|
@name = name
|
46
32
|
@context = context
|
@@ -54,8 +40,18 @@ module Pal
|
|
54
40
|
catch :exit do
|
55
41
|
read while true
|
56
42
|
end
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
# Public: Gets a line from the standard input using Readline.
|
47
|
+
def get(prompt)
|
48
|
+
require "readline"
|
49
|
+
Readline.readline("#{prompt}> ", true)
|
57
50
|
end
|
58
51
|
|
52
|
+
# Public: Writes a line to the standard output.
|
53
|
+
alias_method :put, :puts
|
54
|
+
|
59
55
|
# Public: Reads, evaluates, and prints a line of Ruby code. If the line is
|
60
56
|
# `exit` or `quit`, an `exit` signal is sent and the loop terminates. If an
|
61
57
|
# interrupt is sent via Control-C, a blank line is printed before exiting.
|
@@ -63,13 +59,13 @@ module Pal
|
|
63
59
|
# escape character (`\`).
|
64
60
|
def read(prompt = @name)
|
65
61
|
@error = nil
|
66
|
-
@input =
|
62
|
+
@input = get prompt
|
67
63
|
throw :exit if @input.nil? || %w{exit quit}.include?(@input)
|
68
64
|
unless @input.empty?
|
69
65
|
@statements << @input
|
70
66
|
if @statements.last[-1] == "\\"
|
71
67
|
@statements.last.chop!
|
72
|
-
read
|
68
|
+
read "." * @name.size
|
73
69
|
else
|
74
70
|
@input = @statements.join($/)
|
75
71
|
@statements.clear
|
@@ -83,15 +79,14 @@ module Pal
|
|
83
79
|
|
84
80
|
# Public: Evaluates a line of code in the current context. If an error was
|
85
81
|
# raised, the stack trace is printed. To reduce noise, all lines containing
|
86
|
-
# the current file name are
|
82
|
+
# the current file name are omitted from the trace.
|
87
83
|
def evaluate(value)
|
88
84
|
@result = eval(value, @context.instance_eval { binding }, "(#{@name})", @line)
|
89
|
-
@context.instance_variable_set(:@_,
|
85
|
+
@context.instance_variable_set(:@_, result)
|
90
86
|
rescue Exception => exception
|
91
87
|
@error = true
|
92
|
-
|
93
|
-
|
94
|
-
warn %Q{#{exception.class}: #{stack.join($/ + " " * 4)}}
|
88
|
+
trace = exception.backtrace.reject { |line| line.include? File.basename(__FILE__) }.unshift(exception.message)
|
89
|
+
warn "#{exception.class}: #{trace.join("\n\t")}"
|
95
90
|
ensure
|
96
91
|
@line += 1
|
97
92
|
end
|
@@ -99,7 +94,7 @@ module Pal
|
|
99
94
|
# Public: Prints the last output, prepending the output symbol to a
|
100
95
|
# human-readable representation of the result.
|
101
96
|
def print(result)
|
102
|
-
|
97
|
+
put "=> #{result.inspect}" unless @error
|
103
98
|
end
|
104
99
|
end
|
105
100
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
15
|
-
project-specific shells.
|
14
|
+
description: A miniature Ruby read-evaluate-print loop for project-specific shells.
|
16
15
|
email: kitcambridge@me.com
|
17
16
|
executables:
|
18
17
|
- pal
|