-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ocaml-types.py
48 lines (40 loc) · 1.12 KB
/
Ocaml-types.py
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
import sublime, sublime_plugin
import re
class OcamlTypesParser():
def search(self,filename,offset):
try:
f = open(filename.rsplit( ".", 1 )[ 0 ]+".annot")
except IOError:
return "Couldn't open .annot file. Remember compiling with -annot"
lineM = re.compile('^\\\"[^\\\"]*\\\"\s\d+\s\d+\s(\d+)\s\\\"[^\\\"]*\\\"\s\d+\s\d+\s(\d+)$');
endM = re.compile('^\\)$')
typeDescr = "Not found"
line = f.readline()
while line:
result = re.match(lineM,line)
if result == None:
line = f.readline()
continue
elif int(result.group(1)) > offset:
break
elif int(result.group(2)) < offset:
line = f.readline()
continue
line = f.readline() # type line
typeDescr = "";
line = f.readline()
while (line):
if re.match(endM,line):
break
typeDescr += line
line = f.readline()
break
f.close()
print typeDescr
return typeDescr
class OcamlTypesCommand(sublime_plugin.TextCommand):
def run(self, edit):
pos = self.view.sel()[0].begin()
parser = OcamlTypesParser()
result = parser.search(self.view.file_name(),pos)
self.view.set_status("ocaml-types","Type: " + result)