-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyrs.py
38 lines (31 loc) · 1018 Bytes
/
pyrs.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
import sys
from parser import ParserError
from purescript.lexer import NiceLexerError
from purescript.parser import module_parser, lexer, compiled_module_parser, to_ast
def entry_point(argv):
files_to_parse = argv[1:]
for file_to_parse in files_to_parse:
print "parsing file:", file_to_parse
with open(file_to_parse) as f:
source = f.read()
try:
tokens = lexer.tokenize_with_name(file_to_parse, source)
except NiceLexerError as e:
print e
return 1
try:
tree = compiled_module_parser.parse(tokens)
except ParserError as e:
print e
return 1
ast = to_ast.visit_module(tree)[0]
module_name = ast.children[0]
parts = []
for child in module_name.children:
parts.append(child.token.source)
print ".".join(parts)
return 0
def target(*args):
return entry_point, None
if __name__ == "__main__":
entry_point(sys.argv)