nomsu/tools/autoformat.nom
Bruce Hill 7f47d42040 In-progress (but working) overhaul of some elements including: function
calls, lib/thing.nom API, multi-assignments, varargs, etc.
2018-11-17 14:39:08 -08:00

30 lines
989 B
Plaintext
Executable File

#!/usr/bin/env nomsu -V4.10.12.7
#
Auto-format Nomsu code. Usage:
nomsu tools/autoformat.nom [-i] file1 file2 directory1 ...
If the first argument is "-i", modifications will be performed in-place. Otherwise,
the formatted code will be printed.
use "lib/os.nom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%args = (command line args)
%inplace = (no)
if (%args.1 is "-i"):
%inplace = (yes)
%args::remove index 1
for %path in %args:
if (%path == "-"): %path = "stdin"
for file %filename in %path:
unless ((%filename::matches "%.nom$") or (%filename == "stdin")): do next %filename
%contents = (read file %filename)
%code = (NomsuCode from (Source %filename 1 (size of %contents)) %contents)
%tree = (%code parsed)
%formatted = ((%tree as nomsu)::text)
if %inplace:
write %formatted to file %filename
..else:
say %formatted inline