forked from RubyMotionJP/SublimeRubyMotionBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrubymotion_syntax_generator.rb
68 lines (48 loc) · 1.63 KB
/
rubymotion_syntax_generator.rb
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env ruby -wKU
require "stringio"
DebugEnabled = true
ignore_files = [
"RubyMotion.tmLanguage",
"Default.sublime-commands",
"Default.sublime-keymap",
"RubyMotion.sublime-build",
"RubyMotion.sublime-settings"
]
Dir.foreach("../Ruby") do |file_name|
src_file_name = "../Ruby/" + file_name
if FileTest.file?(src_file_name)
# skip cache files
ext = File.extname(file_name)
next if ext == ".cache"
# Ruby.* rename to RubyMotion.*
base = File.basename(file_name, ext)
base = "RubyMotion" if base == "Ruby"
# skip ignore file
next if ignore_files.include?(base + ext)
dst_file_name = base + ext
STDERR.puts "Creating: #{dst_file_name}" if DebugEnabled
uuid = ">#{`uuidgen`.chomp}<"
iobuf = StringIO.open
begin
File.open(src_file_name, "r") do |in_file|
skip = false
in_file.each do |line|
# ignore lines
skip = false if skip and line =~ /<key>/
skip = true if line =~ />(fileTypes|firstLineMatch)</
next if skip
line = line.gsub(/>Ruby</, ">RubyMotion<")
line = line.gsub(/source\.ruby([< ])/, "source.rubymotion\\1")
line = line.gsub(/>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}</, uuid)
iobuf.puts line
end # in_file.each
end # File.open of in_file
File.open(dst_file_name, "w") do |out_file|
out_file.puts iobuf.string
end # File.open of out_file
rescue
STDERR.puts " -> FAILED: #{$!.backtrace.first} : #{$!}" if DebugEnabled
end
iobuf.close
end # file_name is file?
end # Dir.foreach