Skip to content

Instantly share code, notes, and snippets.

@krtx
Created November 9, 2012 08:03
Show Gist options
  • Save krtx/4044366 to your computer and use it in GitHub Desktop.
Save krtx/4044366 to your computer and use it in GitHub Desktop.
le4a-typeinfernantoka
# coding: utf-8
require 'mechanize'
require 'pp'
agent = Mechanize.new
page = agent.get('http://www.fos.kuis.kyoto-u.ac.jp/~t-sekiym/classes/isle4/testcases.html')
number = 1
examples = page.search("table:eq(#{number}) tr")[1..-1]
def make_test(statement, type)
if type == "型エラー"
"(fun () -> typing_exp_emp \"#{statement} ;;\") *=> type_error"
else
"typing_exp_emp \"#{statement} ;;\" => \"#{type}\""
end
end
puts "let examples#{number} = \"Examples1\" >::: ["
idx = 0
examples.each do |tr|
next if tr.children.length == 1
statement = tr.search('td:eq(1)').text.strip.gsub("\n", "")
if tr.search('td:eq(1)')[0]['rowspan'] == '2'
type1 = tr.search('td:eq(2)').text.strip.gsub("\n", "")
type2 = tr.next_sibling.search('td:eq(1)').text.strip.gsub("\n", "")
puts <<-EOS
"test#{idx}" >::
(fun () -> if polymorphism then #{make_test(statement, type1)}
else #{make_test(statement, type2)});
EOS
else
type = tr.search('td:eq(2)').text.strip.gsub("\n", "")
puts "\"test#{idx}\" >:: (fun () -> #{make_test(statement, type)});"
end
idx += 1
end
puts "]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment