riml 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/riml +15 -6
- data/lib/ast_rewriter.rb +2 -3
- data/lib/compiler.rb +4 -5
- data/lib/nodes.rb +20 -8
- data/lib/riml.rb +55 -13
- data/version.rb +2 -2
- metadata +2 -2
data/bin/riml
CHANGED
@@ -38,11 +38,19 @@ module Riml
|
|
38
38
|
append_filenames_to_list_if_all_exist(options.check_syntax_files, *filenames)
|
39
39
|
end
|
40
40
|
|
41
|
-
opts.on("-
|
42
|
-
|
41
|
+
opts.on("-S", "--source-path PATH", "Colon-separated path riml uses to find files for `riml_source`. Defaults to pwd.") do |path|
|
42
|
+
begin
|
43
43
|
Riml.source_path = path
|
44
|
-
|
45
|
-
abort
|
44
|
+
rescue UserArgumentError => e
|
45
|
+
abort e.message
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on("-I", "--include-path PATH", "Colon-separated path riml uses to find files for `riml_include`. Defaults to pwd.") do |path|
|
50
|
+
begin
|
51
|
+
Riml.include_path = path
|
52
|
+
rescue UserArgumentError => e
|
53
|
+
abort e.message
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
@@ -72,10 +80,11 @@ module Riml
|
|
72
80
|
|
73
81
|
def self.append_filenames_to_list_if_all_exist(list, *filenames)
|
74
82
|
filenames.each do |fname|
|
75
|
-
|
83
|
+
expanded = File.expand_path(fname)
|
84
|
+
if File.exists?(expanded)
|
76
85
|
list << fname
|
77
86
|
else
|
78
|
-
|
87
|
+
raise UserArgumentError, "Couldn't find file #{fname.inspect}."
|
79
88
|
end
|
80
89
|
end
|
81
90
|
end
|
data/lib/ast_rewriter.rb
CHANGED
@@ -68,7 +68,7 @@ module Riml
|
|
68
68
|
old_ast = ast
|
69
69
|
ast.children.each do |node|
|
70
70
|
next unless RimlCommandNode === node && node.name == 'riml_include'
|
71
|
-
node.each_existing_file! do |file|
|
71
|
+
node.each_existing_file! do |file, fullpath|
|
72
72
|
if from_file && @included_file_refs[file] == from_file
|
73
73
|
msg = "#{from_file.inspect} can't include #{file.inspect}, as " \
|
74
74
|
" #{file.inspect} already included #{from_file.inspect}"
|
@@ -77,8 +77,7 @@ module Riml
|
|
77
77
|
raise UserArgumentError, "#{file.inspect} can't include itself"
|
78
78
|
end
|
79
79
|
@included_file_refs[from_file] = file
|
80
|
-
|
81
|
-
riml_src = File.read(full_path)
|
80
|
+
riml_src = File.read(fullpath)
|
82
81
|
# recursively parse included files with this ast_rewriter in order
|
83
82
|
# to pick up any classes that are defined there
|
84
83
|
rewritten_ast = Parser.new.parse(riml_src, self, file)
|
data/lib/compiler.rb
CHANGED
@@ -557,8 +557,8 @@ module Riml
|
|
557
557
|
def compile(node)
|
558
558
|
if node.name == 'riml_source'
|
559
559
|
node.name = 'source'
|
560
|
-
node.each_existing_file! do |
|
561
|
-
root_node(node).current_compiler.compile_queue <<
|
560
|
+
node.each_existing_file! do |basename, full_path|
|
561
|
+
root_node(node).current_compiler.compile_queue << full_path
|
562
562
|
end
|
563
563
|
elsif node.name == 'riml_include'
|
564
564
|
# riml_include has to be top-level
|
@@ -566,10 +566,9 @@ module Riml
|
|
566
566
|
error_msg = %Q(riml_include error, has to be called at top-level)
|
567
567
|
raise IncludeNotTopLevel, error_msg
|
568
568
|
end
|
569
|
-
node.each_existing_file! do |
|
570
|
-
full_path = File.join(Riml.source_path, file)
|
569
|
+
node.each_existing_file! do |basename, full_path|
|
571
570
|
riml_src = File.read(full_path)
|
572
|
-
node.compiled_output << root_node(node).current_compiler.compile_include(riml_src,
|
571
|
+
node.compiled_output << root_node(node).current_compiler.compile_include(riml_src, basename)
|
573
572
|
end
|
574
573
|
return node.compiled_output
|
575
574
|
end
|
data/lib/nodes.rb
CHANGED
@@ -355,26 +355,38 @@ module Riml
|
|
355
355
|
end
|
356
356
|
end
|
357
357
|
|
358
|
+
# yields full file path for each existing file found in Riml.source_path
|
358
359
|
def each_existing_file!
|
359
|
-
files =
|
360
|
+
files = {}
|
360
361
|
arguments.map(&:value).each do |file|
|
361
|
-
if
|
362
|
-
|
362
|
+
if base_path = paths.detect do |path|
|
363
|
+
full = File.join(path, file)
|
364
|
+
File.exists?(full)
|
365
|
+
end
|
366
|
+
files[file] = File.join(base_path, file)
|
363
367
|
else
|
364
368
|
raise Riml::FileNotFound, "#{file.inspect} could not be found in " \
|
365
|
-
"
|
369
|
+
"#{name.upcase}_PATH (#{paths.join(':').inspect})"
|
366
370
|
end
|
367
371
|
end
|
368
|
-
return unless block_given?
|
372
|
+
return files.values unless block_given?
|
369
373
|
# all files exist
|
370
|
-
files.each do |
|
374
|
+
files.each do |basename, full_path|
|
371
375
|
begin
|
372
|
-
yield
|
376
|
+
yield basename, full_path
|
373
377
|
rescue Riml::IncludeFileLoop
|
374
|
-
arguments.delete_if { |arg| arg.value ==
|
378
|
+
arguments.delete_if { |arg| arg.value == basename }
|
375
379
|
end
|
376
380
|
end
|
377
381
|
end
|
382
|
+
|
383
|
+
def paths
|
384
|
+
if name == 'riml_include'
|
385
|
+
Riml.include_path
|
386
|
+
else
|
387
|
+
Riml.source_path
|
388
|
+
end
|
389
|
+
end
|
378
390
|
end
|
379
391
|
|
380
392
|
class OperatorNode < Struct.new(:operator, :operands)
|
data/lib/riml.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
require File.expand_path('../environment', __FILE__)
|
2
4
|
require 'nodes'
|
3
5
|
require 'lexer'
|
@@ -12,11 +14,11 @@ module Riml
|
|
12
14
|
end
|
13
15
|
|
14
16
|
# parse code (or tokens) into nodes
|
15
|
-
def self.parse(input, ast_rewriter = AST_Rewriter.new)
|
17
|
+
def self.parse(input, ast_rewriter = AST_Rewriter.new, filename = nil)
|
16
18
|
unless input.is_a?(Array) || input.is_a?(String)
|
17
19
|
raise ArgumentError, "input must be tokens or code, is #{input.class}"
|
18
20
|
end
|
19
|
-
Parser.new.parse(input, ast_rewriter)
|
21
|
+
Parser.new.parse(input, ast_rewriter, filename)
|
20
22
|
end
|
21
23
|
|
22
24
|
# compile nodes (or tokens or code or file) into output code
|
@@ -27,7 +29,7 @@ module Riml
|
|
27
29
|
nodes = parser.parse(input)
|
28
30
|
elsif input.is_a?(File)
|
29
31
|
source = input.read
|
30
|
-
nodes = parser.parse(source)
|
32
|
+
nodes = parser.parse(source, AST_Rewriter.new, input.path)
|
31
33
|
else
|
32
34
|
raise ArgumentError, "input must be nodes, tokens, code or file, is #{input.class}"
|
33
35
|
end
|
@@ -74,10 +76,19 @@ module Riml
|
|
74
76
|
end
|
75
77
|
|
76
78
|
def self.source_path
|
77
|
-
|
79
|
+
get_path(:source_path)
|
78
80
|
end
|
81
|
+
|
79
82
|
def self.source_path=(path)
|
80
|
-
|
83
|
+
set_path(:source_path, path)
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.include_path
|
87
|
+
get_path(:include_path)
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.include_path=(path)
|
91
|
+
set_path(:include_path, path)
|
81
92
|
end
|
82
93
|
|
83
94
|
def self.warn(warning)
|
@@ -103,6 +114,32 @@ module Riml
|
|
103
114
|
@warning_buffer ||= WarningBuffer.new
|
104
115
|
end
|
105
116
|
|
117
|
+
def self.set_path(name, path)
|
118
|
+
return instance_variable_set("@#{name}", nil) if path.nil?
|
119
|
+
path = path.split(':') if path.is_a?(String)
|
120
|
+
path.each do |dir|
|
121
|
+
unless Dir.exists?(dir)
|
122
|
+
raise UserArgumentError, "Error trying to set #{name.to_s}. " \
|
123
|
+
"Directory #{dir.inspect} doesn't exist"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
instance_variable_set("@#{name}", path)
|
127
|
+
end
|
128
|
+
self.source_path = nil # eliminate ivar warnings
|
129
|
+
self.include_path = nil # eliminate ivar warnings
|
130
|
+
|
131
|
+
def self.get_path(name)
|
132
|
+
ivar = instance_variable_get("@#{name}")
|
133
|
+
return ivar if ivar
|
134
|
+
# RIML_INCLUDE_PATH or RIML_SOURCE_PATH
|
135
|
+
val = if (path = ENV["RIML_#{name.to_s.upcase}"])
|
136
|
+
path
|
137
|
+
else
|
138
|
+
[Dir.getwd]
|
139
|
+
end
|
140
|
+
set_path(name, val)
|
141
|
+
end
|
142
|
+
|
106
143
|
def self.threaded_compile_files(*filenames)
|
107
144
|
threads = []
|
108
145
|
filenames.each do |fname|
|
@@ -116,10 +153,10 @@ module Riml
|
|
116
153
|
|
117
154
|
# This is for when another file is sourced within a file we're compiling.
|
118
155
|
def self.process_compile_queue!(compiler)
|
119
|
-
while
|
120
|
-
unless compiler.sourced_files_compiled.include?(
|
121
|
-
compiler.sourced_files_compiled <<
|
122
|
-
compile(File.open(
|
156
|
+
while full_path = compiler.compile_queue.shift
|
157
|
+
unless compiler.sourced_files_compiled.include?(full_path)
|
158
|
+
compiler.sourced_files_compiled << full_path
|
159
|
+
compile(File.open(full_path), compiler.parser, compiler)
|
123
160
|
end
|
124
161
|
end
|
125
162
|
end
|
@@ -128,11 +165,16 @@ module Riml
|
|
128
165
|
INCLUDE_COMMENT_FMT = File.read(File.expand_path("../included.vim", __FILE__))
|
129
166
|
|
130
167
|
def self.write_file(output, fname)
|
131
|
-
|
132
|
-
|
133
|
-
|
168
|
+
# absolute path, output into same directory as file
|
169
|
+
dir = if fname[0] == File::SEPARATOR
|
170
|
+
Pathname.new(fname).parent.to_s
|
171
|
+
# relative path, output into current working directory
|
172
|
+
else
|
173
|
+
Dir.getwd
|
134
174
|
end
|
135
|
-
File.
|
175
|
+
basename_without_riml_ext = File.basename(fname).sub(/\.riml\Z/i, '')
|
176
|
+
full_path = File.join(dir, "#{basename_without_riml_ext}.vim")
|
177
|
+
File.open(full_path, 'w') do |f|
|
136
178
|
f.write FILE_HEADER + output
|
137
179
|
end
|
138
180
|
end
|
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.5
|
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-
|
12
|
+
date: 2013-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: racc
|