Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #169 from Jaseci-Labs/format_work
Browse files Browse the repository at this point in the history
feat: cli formatter added
  • Loading branch information
marsninja authored Jan 26, 2024
2 parents 091ec0d + 69b23e7 commit c39f682
Show file tree
Hide file tree
Showing 8 changed files with 756 additions and 63 deletions.
25 changes: 25 additions & 0 deletions jaclang/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,37 @@
from jaclang import jac_import as __jac_import__
from jaclang.cli.cmdreg import CommandRegistry, CommandShell
from jaclang.compiler.constant import Constants
from jaclang.compiler.passes.tool.schedules import format_pass
from jaclang.compiler.transpiler import jac_file_to_pass
from jaclang.utils.lang_tools import AstTool


cmd_registry = CommandRegistry()


@cmd_registry.register
def format(filename: str, outfile: str = "") -> None:
"""Run the specified .jac file.
:param filename: The path to the .jac file.
:param main: If True, use '__main__' as the module name, else use the actual module name.
"""
if filename.endswith(".jac"):
if os.path.exists(filename):
code_gen_format = jac_file_to_pass(filename, schedule=format_pass)
if code_gen_format.errors_had:
print("Errors occurred while formatting the file.")
else:
if outfile:
with open(outfile, "w") as f:
f.write(code_gen_format.ir.gen.jac)
else:
with open(filename, "w") as f:
f.write(code_gen_format.ir.gen.jac)
else:
print("Not a .jac file.")


@cmd_registry.register
def run(filename: str, main: bool = True) -> None:
"""Run the specified .jac file.
Expand Down
177 changes: 128 additions & 49 deletions jaclang/compiler/passes/tool/jac_formatter_pass.py

Large diffs are not rendered by default.

File renamed without changes.
Loading

0 comments on commit c39f682

Please sign in to comment.