lrb 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lrb +5 -5
- data/lib/lrb.rb +35 -37
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294318f491436616cca102f561589256b103640a
|
4
|
+
data.tar.gz: a272338296524e821c4f2cfd53ce5aaf7a02dfa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 947acff96b79c641bd39ac4ffecda87af08d5152e7a0013ddbaf83cfc0fd73f6ac09b4d09d0a1adb117ab87d7212b07e32a5220e965bb5eaf1becfff646f2812
|
7
|
+
data.tar.gz: 351ee6bee811e3fe9fe8508b61c15948040acb89ab2b317f685b7260bd7008942fe85600bcde59173acfe86840191f33dc062018cc6850067f1907db9c924ecf
|
data/bin/lrb
CHANGED
@@ -12,20 +12,20 @@ spec = Oyster.spec do
|
|
12
12
|
lrb FILE_NAME [OPTIONS]
|
13
13
|
EOS
|
14
14
|
|
15
|
-
flag :
|
16
|
-
'Start an interactive Scheme session'
|
15
|
+
flag :debug, :desc => 'Start an interactive Lrb debug session'
|
17
16
|
end
|
18
17
|
|
19
18
|
require "rubygems"
|
20
19
|
|
21
20
|
begin
|
22
21
|
options = spec.parse
|
22
|
+
version = Gem.loaded_specs["lrb"].version.to_s
|
23
23
|
|
24
|
-
if options[:
|
25
|
-
puts "lrb:
|
24
|
+
if options[:unclaimed].empty?
|
25
|
+
puts "lrb #{version} #{'DEBUG' if options[:debug]} REPL".light_yellow
|
26
26
|
Lrb.new.repl
|
27
27
|
else
|
28
|
-
puts "lrb
|
28
|
+
puts "lrb #{version} COMPILE".light_yellow
|
29
29
|
lrb = Lrb.new
|
30
30
|
lrb.eval_file File.expand_path(options[:unclaimed].first)
|
31
31
|
end
|
data/lib/lrb.rb
CHANGED
@@ -1,34 +1,33 @@
|
|
1
1
|
require "readline"
|
2
2
|
require "colorize"
|
3
3
|
require "bracer"
|
4
|
-
# require "sexpistol"
|
5
4
|
require "pry"
|
6
5
|
|
7
6
|
class Lrb
|
8
7
|
attr_accessor :parser, :debug
|
9
8
|
|
10
9
|
def initialize
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
10
|
+
@_dbg = false
|
11
|
+
@_indent = 0
|
12
|
+
@_stack = Array.new
|
13
|
+
@_parser = Bracer.new
|
14
|
+
@_parser.ruby_keyword_literals = true
|
16
15
|
readline_autocompletion
|
17
16
|
end
|
18
17
|
|
19
18
|
def parse source
|
20
|
-
@
|
19
|
+
@_parser.parse_string source
|
21
20
|
end
|
22
21
|
|
23
22
|
def repl
|
24
23
|
begin
|
25
24
|
while line = readline_with_hist_management
|
26
|
-
@
|
25
|
+
@_stack << line
|
27
26
|
if balanced?
|
28
|
-
e = eval_source @
|
27
|
+
e = eval_source @_stack.join " "
|
29
28
|
puts e.to_s.blue
|
30
|
-
@
|
31
|
-
@
|
29
|
+
@_stack.clear
|
30
|
+
@_indent = 0
|
32
31
|
end
|
33
32
|
end
|
34
33
|
rescue Interrupt => e
|
@@ -47,13 +46,13 @@ class Lrb
|
|
47
46
|
e = to_ruby source
|
48
47
|
evaluated = eval e
|
49
48
|
rescue Exception => ex
|
50
|
-
if @
|
49
|
+
if @_dbg
|
51
50
|
puts ex.backtrace.join("\n").red
|
52
51
|
binding.pry
|
53
52
|
end
|
54
53
|
puts ex.message.red
|
55
54
|
end
|
56
|
-
if @
|
55
|
+
if @_dbg
|
57
56
|
if mode == :compile
|
58
57
|
puts "[LRB]:".light_yellow
|
59
58
|
puts source.light_yellow
|
@@ -74,7 +73,7 @@ class Lrb
|
|
74
73
|
def list_to_ruby ast
|
75
74
|
ast = ast.map do |sexp|
|
76
75
|
result = transform sexp
|
77
|
-
puts result if @
|
76
|
+
puts result if @_dbg
|
78
77
|
result
|
79
78
|
end
|
80
79
|
ast.join "\n\n"
|
@@ -82,17 +81,17 @@ class Lrb
|
|
82
81
|
|
83
82
|
def to_ruby source
|
84
83
|
ast = parse source
|
85
|
-
puts "parsed: #{ast}".green if @
|
84
|
+
puts "parsed: #{ast}".green if @_dbg
|
86
85
|
list_to_ruby ast
|
87
86
|
end
|
88
87
|
|
89
88
|
def transform sexp
|
90
|
-
puts line if @
|
89
|
+
puts line if @_dbg
|
91
90
|
if sexp.class == Array
|
92
91
|
fun = sexp.first
|
93
92
|
args = wrap_string sexp.drop(1)
|
94
93
|
result = ""
|
95
|
-
if @
|
94
|
+
if @_dbg
|
96
95
|
puts "function: #{fun}".yellow
|
97
96
|
puts "args: #{args}".yellow
|
98
97
|
puts line
|
@@ -108,23 +107,23 @@ class Lrb
|
|
108
107
|
result = compose_function fun, args
|
109
108
|
end
|
110
109
|
|
111
|
-
if @
|
110
|
+
if @_dbg
|
112
111
|
puts result.light_green
|
113
112
|
puts line
|
114
113
|
end
|
115
114
|
indent + result
|
116
115
|
else
|
117
|
-
puts "#{sexp}".yellow if @
|
116
|
+
puts "#{sexp}".yellow if @_dbg
|
118
117
|
sexp
|
119
118
|
end
|
120
119
|
end
|
121
120
|
|
122
121
|
private
|
123
122
|
def balanced?
|
124
|
-
source = @
|
123
|
+
source = @_stack.join " "
|
125
124
|
@left = source.count "["
|
126
125
|
@right = source.count "]"
|
127
|
-
@
|
126
|
+
@_indent = @left - @right if (@left - @right) > 0
|
128
127
|
@left == @right
|
129
128
|
end
|
130
129
|
|
@@ -165,13 +164,20 @@ class Lrb
|
|
165
164
|
end
|
166
165
|
|
167
166
|
def replace_parenthese arg
|
168
|
-
if arg.
|
169
|
-
|
170
|
-
|
171
|
-
|
167
|
+
if arg.kind_of? Array
|
168
|
+
arg = arg.map{ |element|
|
169
|
+
replace_parenthese element
|
170
|
+
}
|
172
171
|
arg
|
173
172
|
else
|
174
|
-
arg
|
173
|
+
if arg.to_s["("] && arg.to_s[")"]
|
174
|
+
old = arg
|
175
|
+
arg = arg.to_s.gsub(/\((.*)\)/, '[\1]').to_sym
|
176
|
+
puts "arg: #{old} => #{arg}".light_yellow if @_dbg
|
177
|
+
arg
|
178
|
+
else
|
179
|
+
arg
|
180
|
+
end
|
175
181
|
end
|
176
182
|
end
|
177
183
|
|
@@ -191,21 +197,13 @@ class Lrb
|
|
191
197
|
end
|
192
198
|
|
193
199
|
def indent
|
194
|
-
" " * @
|
200
|
+
" " * @_indent
|
195
201
|
end
|
196
202
|
|
197
203
|
def line
|
198
204
|
"-" * 80
|
199
205
|
end
|
200
206
|
|
201
|
-
def push node
|
202
|
-
@stack.push node
|
203
|
-
end
|
204
|
-
|
205
|
-
def fetch
|
206
|
-
@stack.pop unless @stack.empty?
|
207
|
-
end
|
208
|
-
|
209
207
|
def operator op, args
|
210
208
|
args = args.map do |arg|
|
211
209
|
transform arg
|
@@ -283,8 +281,8 @@ class Lrb
|
|
283
281
|
].join("\n")
|
284
282
|
},
|
285
283
|
:debug => lambda {
|
286
|
-
@
|
287
|
-
puts "[DEBUG = #{@
|
284
|
+
@_dbg = !@_dbg
|
285
|
+
puts "[DEBUG = #{@_dbg}]".light_yellow
|
288
286
|
""
|
289
287
|
},
|
290
288
|
:do => lambda {|fun, args, bodies|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Trung
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: It transform Ruby to a Lisp with braces, included REPL mode.
|
69
|
+
description: It transform Ruby to a Lisp with braces, included REPL and COMPILE mode.
|
70
70
|
email: deulamco@gmail.com
|
71
71
|
executables:
|
72
72
|
- lrb
|