-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
51 lines (42 loc) · 1.26 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rake/extensiontask'
Rake::TestTask.new do |t|
t.ruby_opts = ["-rpatch_helper"]
t.libs = %w(lib/ test/ vendor/parser/test/ vendor/parser/lib/)
t.test_files = %w(vendor/parser/test/test_lexer.rb vendor/parser/test/test_parser.rb)
t.warning = false
end
Rake::ExtensionTask.new('lexer')
namespace :ruby_parser do
desc "'rake generate' in the Ruby Parser"
task :generate do
sh 'cd vendor/parser && rake generate'
end
desc "'rake clean' in the Ruby Parser"
task :clean do
sh 'cd vendor/parser && rake clean'
end
end
namespace :c_lexer do
desc 'Generate lexer.c from lexer.rl'
task :generate do
source = 'ext/lexer/lexer.rl'
target = 'ext/lexer/lexer.c'
sh "ragel -F1 #{source} -o #{target}"
# Ragel likes to use int variables where a #define would do
src = File.read(target)
src.gsub!(/^static const int (\w+) = (\d+);/, '#define \1 \2')
File.open(target, 'w') { |f| f.write(src) }
end
end
task :clean do
sh 'rm -rf tmp'
sh 'rm -f lib/lexer.*'
sh 'rm -f ext/lexer/lexer.c'
sh 'cd vendor/parser && rake clean'
end
task generate: ['ruby_parser:generate', 'c_lexer:generate']
task test: [:generate, :compile]
task build: :generate
task default: :test