6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/precedent/treetop_patch.rb', line 6
def compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb'))
File.open(target_path, 'w') do |target_file|
generated_source = ruby_source(source_path)
first_line_break = generated_source.index("\n")
first_line = generated_source.slice(0..first_line_break)
if /(coding|encoding): (\S+)/.match(first_line)
target_file.write(first_line)
target_file.write(AUTOGENERATED+"\n\n")
target_file.write(generated_source.slice((first_line_break + 1)..-1))
else
target_file.write(AUTOGENERATED+"\n\n")
target_file.write(generated_source)
end
end
end
|