Skip to content

Commit 3baaa7d

Browse files
committed
Change into module
1 parent 83de865 commit 3baaa7d

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

main.py __init__.py

-29
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22
from dataclasses import dataclass
33
import itertools
44
import numbers
5-
import time
65
import sys
7-
import os
8-
import traceback
9-
import json
106
import re
117

128
from collections import defaultdict
139
import types
14-
import typing
1510

1611
from lark import Lark, Transformer, Tree, Token
1712
from lark.exceptions import UnexpectedToken, UnexpectedCharacters
@@ -260,7 +255,6 @@ def __repr__(self):
260255

261256

262257
def create_step_entity(entity_tree):
263-
entity = {}
264258
t = T(visit_tokens=True).transform(entity_tree)
265259

266260
def get_line_number(t):
@@ -473,26 +467,3 @@ def by_type(self, type: str) -> list[entity_instance]:
473467

474468
def open(fn) -> file:
475469
return file(parse(filename=fn, with_tree=True, with_header=True))
476-
477-
478-
if __name__ == "__main__":
479-
args = [x for x in sys.argv[1:] if not x.startswith("-")]
480-
flags = [x for x in sys.argv[1:] if x.startswith("-")]
481-
482-
fn = args[0]
483-
start_time = time.time()
484-
485-
try:
486-
parse(filename=fn, with_progress="--progress" in flags, with_tree=False)
487-
if "--json" not in flags:
488-
print("Valid", file=sys.stderr)
489-
exit(0)
490-
except ValidationError as exc:
491-
if "--json" not in flags:
492-
print(exc, file=sys.stderr)
493-
else:
494-
import sys
495-
import json
496-
497-
json.dump(exc.asdict(), sys.stdout)
498-
exit(1)

__main__.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
import time
3+
from . import parse, ValidationError
4+
5+
if __name__ == "__main__":
6+
args = [x for x in sys.argv[1:] if not x.startswith("-")]
7+
flags = [x for x in sys.argv[1:] if x.startswith("-")]
8+
9+
fn = args[0]
10+
start_time = time.time()
11+
12+
try:
13+
parse(filename=fn, with_progress="--progress" in flags, with_tree=False)
14+
if "--json" not in flags:
15+
print("Valid", file=sys.stderr)
16+
exit(0)
17+
except ValidationError as exc:
18+
if "--json" not in flags:
19+
print(exc, file=sys.stderr)
20+
else:
21+
import sys
22+
import json
23+
24+
json.dump(exc.asdict(), sys.stdout)
25+
exit(1)

0 commit comments

Comments
 (0)