Skip to content

Commit

Permalink
Change into module
Browse files Browse the repository at this point in the history
  • Loading branch information
aothms committed Nov 14, 2024
1 parent 83de865 commit 3baaa7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
29 changes: 0 additions & 29 deletions main.py → __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
from dataclasses import dataclass
import itertools
import numbers
import time
import sys
import os
import traceback
import json
import re

from collections import defaultdict
import types
import typing

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


def create_step_entity(entity_tree):
entity = {}
t = T(visit_tokens=True).transform(entity_tree)

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

def open(fn) -> file:
return file(parse(filename=fn, with_tree=True, with_header=True))


if __name__ == "__main__":
args = [x for x in sys.argv[1:] if not x.startswith("-")]
flags = [x for x in sys.argv[1:] if x.startswith("-")]

fn = args[0]
start_time = time.time()

try:
parse(filename=fn, with_progress="--progress" in flags, with_tree=False)
if "--json" not in flags:
print("Valid", file=sys.stderr)
exit(0)
except ValidationError as exc:
if "--json" not in flags:
print(exc, file=sys.stderr)
else:
import sys
import json

json.dump(exc.asdict(), sys.stdout)
exit(1)
25 changes: 25 additions & 0 deletions __main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
import time
from . import parse, ValidationError

if __name__ == "__main__":
args = [x for x in sys.argv[1:] if not x.startswith("-")]
flags = [x for x in sys.argv[1:] if x.startswith("-")]

fn = args[0]
start_time = time.time()

try:
parse(filename=fn, with_progress="--progress" in flags, with_tree=False)
if "--json" not in flags:
print("Valid", file=sys.stderr)
exit(0)
except ValidationError as exc:
if "--json" not in flags:
print(exc, file=sys.stderr)
else:
import sys
import json

json.dump(exc.asdict(), sys.stdout)
exit(1)

0 comments on commit 3baaa7d

Please sign in to comment.