riml 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/riml.rb CHANGED
@@ -3,6 +3,7 @@ require 'nodes'
3
3
  require 'lexer'
4
4
  require 'parser'
5
5
  require 'compiler'
6
+ require 'warning_buffer'
6
7
 
7
8
  module Riml
8
9
  # lex code into tokens
@@ -32,8 +33,11 @@ module Riml
32
33
  end
33
34
  compiler.parser = parser
34
35
  output = compiler.compile(nodes)
35
- return output unless input.is_a?(File)
36
- write_file(output, input.path)
36
+ if input.is_a?(File)
37
+ write_file(output, input.path)
38
+ else
39
+ output
40
+ end
37
41
  ensure
38
42
  input.close if input.is_a?(File)
39
43
  process_compile_queue!(compiler)
@@ -51,6 +55,8 @@ module Riml
51
55
  else
52
56
  raise ArgumentError, "need filenames to compile"
53
57
  end
58
+ ensure
59
+ flush_warnings
54
60
  end
55
61
 
56
62
  # checks syntax of `input` (lexes + parses) without going through ast rewriting or compilation
@@ -75,11 +81,28 @@ module Riml
75
81
  end
76
82
 
77
83
  def self.warn(warning)
78
- $stderr.puts "Warning: #{warning}"
84
+ warning_buffer << warning
79
85
  end
80
86
 
87
+ class << self
88
+ attr_accessor :warnings
89
+ end
90
+ self.warnings = true
91
+
81
92
  private
82
93
 
94
+ def self.flush_warnings
95
+ if warnings
96
+ warning_buffer.flush
97
+ else
98
+ warning_buffer.clear
99
+ end
100
+ end
101
+
102
+ def self.warning_buffer
103
+ @warning_buffer ||= WarningBuffer.new
104
+ end
105
+
83
106
  def self.threaded_compile_files(*filenames)
84
107
  threads = []
85
108
  filenames.each do |fname|
@@ -0,0 +1,42 @@
1
+ module Riml
2
+ class WarningBuffer
3
+ BUFFER_WRITE_LOCK = Mutex.new
4
+ WARNING_FMT = "Warning: %s"
5
+
6
+ class << self
7
+ def stream=(stream)
8
+ BUFFER_WRITE_LOCK.synchronize { @stream = stream }
9
+ end
10
+ attr_reader :stream
11
+ end
12
+
13
+ # default stream
14
+ self.stream = $stderr
15
+
16
+ attr_reader :buffer
17
+
18
+ def initialize(*warnings)
19
+ @buffer = []
20
+ buffer.concat warnings
21
+ end
22
+
23
+ def <<(warning)
24
+ BUFFER_WRITE_LOCK.synchronize { buffer << warning }
25
+ end
26
+ alias push <<
27
+
28
+ def flush
29
+ BUFFER_WRITE_LOCK.synchronize do
30
+ stream = self.class.stream
31
+ buffer.each { |w| stream.puts WARNING_FMT % w }
32
+ buffer.clear
33
+ stream.flush
34
+ end
35
+ end
36
+
37
+ def clear
38
+ BUFFER_WRITE_LOCK.synchronize { buffer.clear }
39
+ end
40
+
41
+ end
42
+ end
data/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Riml
2
- # last changed: Apr. 14, 2013
3
- VERSION = [0,2,3]
2
+ # last changed: Apr. 21, 2013
3
+ VERSION = [0,2,4]
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.3
4
+ version: 0.2.4
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-04-15 00:00:00.000000000 Z
12
+ date: 2013-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: racc
@@ -41,6 +41,7 @@ files:
41
41
  - version.rb
42
42
  - lib/parser.rb
43
43
  - lib/walker.rb
44
+ - lib/warning_buffer.rb
44
45
  - lib/class_map.rb
45
46
  - lib/included.vim
46
47
  - lib/constants.rb