riml 0.2.0 → 0.2.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.
data/lib/repl.rb CHANGED
@@ -59,6 +59,7 @@ module Riml
59
59
  rescue => e
60
60
  print_error(e)
61
61
  reset!
62
+ reload!
62
63
  end
63
64
 
64
65
  def current_indent
@@ -67,10 +68,13 @@ module Riml
67
68
  end
68
69
 
69
70
  def compile_unit!
70
- puts Riml.compile(current_compilation_unit.join("\n"), parser, compiler), "\n"
71
+ viml = Riml.compile(current_compilation_unit.join("\n"), parser, compiler).chomp
72
+ escape_newlines_in_strings!(viml)
73
+ puts viml, "\n"
71
74
  rescue => e
72
75
  raise unless e.kind_of?(RimlError)
73
76
  print_error(e)
77
+ reload!
74
78
  ensure
75
79
  reset!
76
80
  end
@@ -88,6 +92,10 @@ module Riml
88
92
  puts "#{e.class}: #{e}"
89
93
  end
90
94
 
95
+ def escape_newlines_in_strings!(viml)
96
+ viml.gsub!(/("[^"]*?)\n+([^"]?")/, '\1\\n\2')
97
+ end
98
+
91
99
  def exit_repl
92
100
  exit
93
101
  end
data/lib/riml.rb CHANGED
@@ -41,15 +41,16 @@ module Riml
41
41
 
42
42
  # expects `file_names` to be readable files
43
43
  def self.compile_files(*filenames)
44
- threads = []
45
- filenames.each do |fname|
46
- threads << Thread.new do
47
- f = File.open(fname)
48
- # `compile` will close file handle
49
- compile(f)
50
- end
44
+ if filenames.size > 1
45
+ threaded_compile_files(*filenames)
46
+ elsif filenames.size == 1
47
+ fname = filenames.first
48
+ f = File.open(fname)
49
+ # `compile` will close file handle
50
+ compile(f)
51
+ else
52
+ raise ArgumentError, "need filenames to compile"
51
53
  end
52
- threads.each {|t| t.join}
53
54
  end
54
55
 
55
56
  # checks syntax of `input` (lexes + parses) without going through ast rewriting or compilation
@@ -73,19 +74,31 @@ module Riml
73
74
  @source_path = path
74
75
  end
75
76
 
77
+ def self.warn(warning)
78
+ $stderr.puts "Warning: #{warning}"
79
+ end
80
+
76
81
  private
77
82
 
83
+ def self.threaded_compile_files(*filenames)
84
+ threads = []
85
+ filenames.each do |fname|
86
+ threads << Thread.new do
87
+ f = File.open(fname)
88
+ compile(f)
89
+ end
90
+ end
91
+ threads.each {|t| t.join}
92
+ end
93
+
78
94
  # This is for when another file is sourced within a file we're compiling.
79
- # We have to share the same `ClassMap`, thus we have a queue for the compiler,
80
- # and we process this queue after each source we compile. We pass the same
81
- # parser instance to share Class state, as this state belongs to the
82
- # AST_Rewriter's `ClassMap`.
83
95
  def self.process_compile_queue!(compiler)
84
- return true if compiler.compile_queue.empty?
85
-
86
- file_name = compiler.compile_queue.shift
87
- compile(File.open(File.join(Riml.source_path, file_name)), compiler.parser)
88
- process_compile_queue!(compiler)
96
+ while filename = compiler.compile_queue.shift
97
+ unless compiler.sourced_files_compiled.include?(filename)
98
+ compiler.sourced_files_compiled << filename
99
+ compile(File.open(File.join(Riml.source_path, filename)), compiler.parser, compiler)
100
+ end
101
+ end
89
102
  end
90
103
 
91
104
  FILE_HEADER = File.read(File.expand_path("../header.vim", __FILE__)) % VERSION.join('.')
data/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Riml
2
- # last changed: Mar. 2, 2013
3
- VERSION = [0,2,0]
2
+ # last changed: Apr. 1, 2013
3
+ VERSION = [0,2,1]
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-03 00:00:00.000000000 Z
12
+ date: 2013-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: racc