First commit
This commit is contained in:
27
ruby-grammar-editor/script.rb
Normal file
27
ruby-grammar-editor/script.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
#! /bin/ruby
|
||||
|
||||
lines = File.readlines("input")
|
||||
|
||||
File.open("output", "w") { |file|
|
||||
#file.write("adding first line of text")
|
||||
lines.each do |line|
|
||||
if line.length == 1 then
|
||||
file.puts()
|
||||
else
|
||||
start = line.index('\'')+1
|
||||
finish = (line.length) - 4
|
||||
subs = line[start..finish].to_s
|
||||
newSubs = subs.gsub(/(.{1})(?=.)/, '\1 \2')
|
||||
newSubs2 = ''
|
||||
newSubs.split('').each do |ch|
|
||||
if ((ch >= 'A' and ch <= 'Z') or (ch>= 'a' and ch<= 'z') or (ch == ' ')) then
|
||||
newSubs2 = newSubs2 + ch
|
||||
else
|
||||
newSubs2 = newSubs2 + '\'' + ch + '\''
|
||||
end
|
||||
end
|
||||
newLine = line[0..start-2] + newSubs2 + ';'
|
||||
file.puts(newLine)
|
||||
end
|
||||
end
|
||||
}
|
||||
Reference in New Issue
Block a user