rbf 0.0.6 → 0.0.6.1

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.
Files changed (3) hide show
  1. data/lib/rbf/interpreter.rb +6 -6
  2. data/lib/rbf.rb +16 -3
  3. metadata +1 -1
@@ -16,14 +16,14 @@ require 'rbf/interpreter/storage'
16
16
  module RBF
17
17
 
18
18
  class Interpreter
19
- attr_reader :options, :storage
19
+ attr_reader :options, :storage, :output
20
20
 
21
21
  def initialize (options={})
22
22
  @options = options
23
23
 
24
24
  @storage = Storage.new(options[:env] || [])
25
25
  @input = STDIN
26
- @output = STDOUT
26
+ @output = options[:output] || STDOUT
27
27
 
28
28
  @parser = RBF::Parser.syntax(RBF.syntax(options[:syntax])).new
29
29
  @transform = RBF::Transform.new
@@ -47,7 +47,7 @@ class Interpreter
47
47
  if options[:catch]
48
48
  @output = StringIO.new
49
49
  else
50
- @output = STDOUT
50
+ @output = options[:output] || STDOUT
51
51
  end
52
52
 
53
53
  tree = parse(tree)
@@ -71,9 +71,9 @@ class Interpreter
71
71
  def cycle (tree)
72
72
  tree.each {|token|
73
73
  if token.is_a?(Array)
74
- self.loop(token)
74
+ loop(token)
75
75
  else
76
- self.send(token)
76
+ send(token)
77
77
  end
78
78
  }
79
79
  end
@@ -101,7 +101,7 @@ class Interpreter
101
101
  end
102
102
 
103
103
  define_method ?. do
104
- @output.print @storage.get.chr rescue nil
104
+ @output.print [@storage.get].pack('U') rescue 0
105
105
  @output.flush
106
106
  end
107
107
 
data/lib/rbf.rb CHANGED
@@ -90,11 +90,24 @@ module RBF
90
90
  STDOUT.puts 'Command not found or used improperly'.red
91
91
  end
92
92
  else
93
- output = interpreter.evaluate(line, interpreter.options.merge(:catch => true))
93
+ interpreter.evaluate(line, interpreter.options.merge(:output => Class.new {
94
+ attr_reader :last
94
95
 
95
- print output
96
- print "\n" unless output.empty? || output.end_with?("\n")
96
+ def print (text)
97
+ STDOUT.print(text)
98
+
99
+ @last = text[-1]
100
+ end
101
+
102
+ def flush
103
+ STDOUT.sync
104
+ end
105
+ }.new))
106
+
107
+ puts if interpreter.output.last != "\n"
97
108
  end
109
+ rescue SyntaxError
110
+ next
98
111
  rescue
99
112
  STDOUT.puts $!.inspect.red, $@.join("\n")
100
113
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rbf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.6.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - meh.