riml 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/Rakefile +8 -1
- data/bin/riml +3 -0
- data/lib/ast_rewriter.rb +73 -7
- data/lib/compiler.rb +44 -5
- data/lib/constants.rb +18 -1
- data/lib/errors.rb +4 -0
- data/lib/grammar.y +10 -0
- data/lib/lexer.rb +11 -2
- data/lib/nodes.rb +78 -18
- data/lib/parser.rb +1064 -984
- data/lib/repl.rb +9 -1
- data/lib/riml.rb +30 -17
- data/version.rb +2 -2
- metadata +2 -2
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
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
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.
|
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-
|
12
|
+
date: 2013-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: racc
|