forked from jrh13/hol-light
-
Notifications
You must be signed in to change notification settings - Fork 12
/
conv_tac_params.rb
52 lines (48 loc) · 923 Bytes
/
conv_tac_params.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
def next_nonspace(s, i)
while i < s.size and s[i] =~ /\s/ do
i += 1
end
return i
end
def find_closing_paren (s, i)
count = 0
while i < s.size
if s[i] == "("
count += 1
elsif s[i] == ")"
count -= 1
end
if count <= 0 then
return i
end
i += 1
end
end
def match_nonalnum(s, i)
while i < s.size
if s[i] =~ /\w/ then
i += 1
else
return i
end
end
end
counts = {}
ARGV.each do |fname|
s = IO.read(fname)
s.to_enum(:scan,/CONV_TAC/).map do |m,|
index = $`.size
start = index + m.size
p = next_nonspace(s, start)
# puts "#{index} #{start} #{s[p]} #{p}"
c = start
if s[p] == "(" then
# puts "A"
c = find_closing_paren(s, p)
puts(s[p+1...c].gsub(/\s+/, " ") + " " + fname)
elsif s[0] =~ /\w/ then
c = match_nonalnum(s, p)
puts(s[p...c] + " " + fname)
end
end
end