-
Notifications
You must be signed in to change notification settings - Fork 0
/
pats-whatis
executable file
·52 lines (36 loc) · 1.19 KB
/
pats-whatis
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
#!/usr/bin/env python3
# -*- mode:python3 -*-
""" Nested spans from text position.
From a point defined as a file name, line and column, get the list
of nested span from outer to innest span including the text position.
The stack of nested spans gives location in the corresponding file with
a readable name for the ATS2 constructs corresponding to the spans.
The result is displayed on `stdout`, from inner to outest span.
File name is handled the same way as with `pats-which`.
"""
import os
import sys
from postiats import nested_spans
def perror(message):
""" Shorthand to print to `stderr`. """
print(message, file=sys.stderr)
def error(message):
""" `perror` and `sys.exit(1)`. """
perror(message)
sys.exit(1)
def main():
""" Main. """
my_name = os.path.split(sys.argv[0])[1]
if len(sys.argv) != 4:
error("Usage: %s file-name line column." % my_name)
path = sys.argv[1]
try:
line = int(sys.argv[2])
col = int(sys.argv[3])
except ValueError:
error("Line and column must be integer.")
result = nested_spans.main(path, line, col)
for text_line in result:
print(text_line)
if __name__ == "__main__":
main()