forked from jrh13/hol-light
-
Notifications
You must be signed in to change notification settings - Fork 12
/
match_quotes.rb
48 lines (46 loc) · 933 Bytes
/
match_quotes.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
def next_nonspace(s, i)
while i < s.size and s[i] =~ /\s/ do
i += 1
end
return i
end
def find_closing_quote(s, i)
start = i
escaped = false
while i < s.size do
if s[i] == "\\" then
escaped = !escaped
else
if s[i] == "\"" and !escaped then
return i
end
escaped = false
end
i += 1
end
raise "Unterminated quote."
end
ARGV.each do |fname|
s = IO.read(fname)
system("cp #{fname} #{fname}.bak6")
last = 0
File.open(fname + ".out", "w") do |f|
s.to_enum(:scan,/[^"]CONV_TAC|GEN_REWRITE_TAC/).map do |m,|
match = $`
index = match.size
start = index + m.size
p = next_nonspace(s, start)
c = start
if s[p] != "\"" then
start += 1
c = start
else
c = find_closing_quote(s, p+1) + 1
end
ss = s[last...start]
f.print ss
last = c
end
f.puts s[last..-1]
end
end