forked from osak/ICFPC2014
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcc_parse.rb
executable file
·45 lines (39 loc) · 1.02 KB
/
gcc_parse.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
#!/usr/bin/env ruby
cur = nil
last_section = nil
instructions = []
$<.each_line do |line|
line.chomp!
case line
when /\A\s/
if last_section == :effect
cur[last_section] += "\n#{line.chomp}"
else
cur[last_section] += "\n #{line.strip}"
end
when /\A(\w+) - (.*)\z/
instructions << cur if cur
cur = {}
cur[:mnemonic] = $1
cur[:desc] = $2.strip
when /\A(\w+):(.*)\z/
section = $1.downcase.to_sym
cur[section] = $2.strip
last_section = section
end
end
instructions << cur
#instructions.each do |inst|
#tag = "#{inst[:mnemonic].downcase}---#{inst[:desc].downcase.gsub(' ', '-')}"
#puts "- [#{inst[:mnemonic]} - #{inst[:desc]}](##{tag})"
#end
puts ""
instructions.each do |inst|
puts "## #{inst[:mnemonic]} - #{inst[:desc]}"
puts "- Synopsis: #{inst[:synopsis]}"
puts "- Syntax: `#{inst[:syntax]}`"
puts "- Example: `#{inst[:example]}`" if inst[:example]
puts "- Effect:\n~~~#{inst[:effect]}\n~~~"
puts "- Notes: #{inst[:notes]}" if inst[:notes]
puts ""
end