diff options
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/autoformat.nom | 7 | ||||
| -rwxr-xr-x | tools/find_action.nom | 19 | ||||
| -rwxr-xr-x | tools/parse.nom | 9 | ||||
| -rw-r--r-- | tools/repl.nom | 22 | ||||
| -rwxr-xr-x | tools/replace.nom | 9 | ||||
| -rwxr-xr-x | tools/test.nom | 12 | ||||
| -rwxr-xr-x | tools/upgrade.nom | 11 |
7 files changed, 48 insertions, 41 deletions
diff --git a/tools/autoformat.nom b/tools/autoformat.nom index fed611d..f236ca4 100755 --- a/tools/autoformat.nom +++ b/tools/autoformat.nom @@ -1,10 +1,10 @@ -#!/usr/bin/env nomsu -V4.8.10 +#!/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" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -24,4 +24,5 @@ for %path in %args: if %inplace: write %formatted to file %filename - ..else: say %formatted + ..else: + say %formatted diff --git a/tools/find_action.nom b/tools/find_action.nom index 5885793..a6be84f 100755 --- a/tools/find_action.nom +++ b/tools/find_action.nom @@ -3,7 +3,7 @@ Find an action by its stub. Usage: nomsu tools/find_action.nom "foo %" file1 file2 directory1 ... Will print all the code locations and code that uses the stub. - + use "lib/os.nom" use "lib/consolecolor.nom" @@ -22,19 +22,20 @@ for %path in %files: ..and if it barfs %msg: say (red "\%filename failed to parse:\n\%msg") %tree = (nil) - unless %tree: do next %filename + + unless %tree: + do next %filename + %results = [] for %t in recursive %tree: if ((%t is "Action" syntax tree) and (%t.stub is %stub)): %line_num = (line number of %t.source.start in %file) %results::add {..} - line: %line_num - text: "\ - ..\(blue "\%filename:\%line_num:") - \(yellow (source lines of %t))" + line: %line_num, text: "\(blue "\%filename:\%line_num:")\n\(yellow (source lines of %t))" if (%t is syntax tree): - for %sub in %t: recurse %t on %sub - + for %sub in %t: + recurse %t on %sub sort %results by % -> %.line - for % in %results: say %.text + for % in %results: + say %.text diff --git a/tools/parse.nom b/tools/parse.nom index 1465bb3..6f88179 100755 --- a/tools/parse.nom +++ b/tools/parse.nom @@ -1,8 +1,8 @@ -#!/usr/bin/env nomsu -V4.8.10 +#!/usr/bin/env nomsu -V4.10.12.7 # Tool to print out a parse tree of files in an easy-to-read format. Usage: nomsu tools/parse.nom file1 file2 directory1 ... - + use "lib/os.nom" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -21,14 +21,17 @@ externally (print tree %t at indent %indent) means: "Number": say "\%indent\(%t.1)" + "Var": say "\(%indent)%\(%t.1)" + else: say "\%indent\(%t.type):" for %arg in %t: - if: + when: (%arg is syntax tree): print tree %arg at indent "\%indent " + else: say "\%indent \(quote %arg)" diff --git a/tools/repl.nom b/tools/repl.nom index 00efd77..9d9e88d 100644 --- a/tools/repl.nom +++ b/tools/repl.nom @@ -1,12 +1,13 @@ -#!/usr/bin/env nomsu -V4 +#!/usr/bin/env nomsu -V4.10.12.7 use "lib/consolecolor.nom" use "lib/os.nom" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -[quit, exit] all mean: lua> "os.exit(0)" +externally [quit, exit] all mean: + lua> "os.exit(0)" -(help) means: +externally (help) means: say "\ ..This is the Nomsu v\(Nomsu version) interactive console. You can type in Nomsu code here and hit 'enter' twice to run it. @@ -15,7 +16,7 @@ use "lib/os.nom" say "\ .. \(bright)\(underscore)Welcome to the Nomsu v\(Nomsu version) interactive console!\(reset color) - press 'enter' twice to run a command + press 'enter' twice to run a command " %repl_line = 0 @@ -33,29 +34,28 @@ repeat: go to (run buffer) %buff::add (%line::with "\t" -> " ") %io.write (dim (yellow ".. ")) - === (run buffer) === - if ((size of %buff) == 0): - stop - + if ((size of %buff) == 0): stop %buff = (%buff::joined) - + # TODO: support local variables spoof file %buff try: %ret = (run %buff) - ..and if it barfs %err: - say %err + ..and if it barfs %err: say %err ..or if it succeeds: if (type of %ret) is: "nil": do nothing + "boolean": say "= \("yes" if %ret else "no")" + "table": if %ret.as_nomsu: say "= \(%ret::as nomsu)" ..else: say "= \%ret" + else: say "= \%ret" diff --git a/tools/replace.nom b/tools/replace.nom index a0391d6..ffd96c1 100755 --- a/tools/replace.nom +++ b/tools/replace.nom @@ -1,10 +1,10 @@ -#!/usr/bin/env nomsu -V4.8.10 +#!/usr/bin/env nomsu -V4.10.12.7 # Tool to find and replace one tree with another. nomsu tools/replace.nom [-i] tree_to_replace replacement file1 file2 directory1 ... If "-i" is the first argument, replacements will be performed in-place. Otherwise, the upgraded code will be printed. - + use "lib/os.nom" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -35,9 +35,10 @@ for %path in %args: ..#!/usr/bin/env nomsu -V\(%tree.version or (Nomsu version)) \(%tree2 as nomsu)" - if: + when: %inplace: say "Replaced in \%filename" write %text to file %filename - else: say %text + else: + say %text diff --git a/tools/test.nom b/tools/test.nom index 6e74aa6..f9ed2cb 100755 --- a/tools/test.nom +++ b/tools/test.nom @@ -1,8 +1,8 @@ -#!/usr/bin/env nomsu -V4.8.10 +#!/usr/bin/env nomsu -V4.10.12.7 # Tool to run all tests in a file (i.e. the code block inside a call to 'test %'). Usage: nomsu tools/test.nom file1 file2 directory1 ... - + use "lib/os.nom" use "lib/consolecolor.nom" @@ -17,16 +17,15 @@ if (%args.1 == "-v"): for %path in (command line args): for file %filename in %path: if (%filename::matches "%.nom$"): use %filename - for %path in (command line args): use %path -%tests = ((=lua "Source:from_string(\%s)") = %t for %s = %t in (tests)) +%tests = {: for %s = %t in (tests): add (=lua "Source:from_string(\%s)") = %t} for %path in (command line args): for file %filename in %path: unless (%filename::matches "%.nom$"): do next %filename %file_tests = [] for %src = %test in %tests: if (%src.filename == %filename): - %file_tests::add {test:%test, source:%src} + %file_tests::add {test: %test, source: %src} unless (%file_tests is empty): sort %file_tests by % -> %.source @@ -37,6 +36,7 @@ for %path in (command line args): say " \(yellow (%.test::with "\n" -> "\n "))" run %.test - if %verbose: say (green "PASS") + if %verbose: + say (green "PASS") ..else: say "\r[\(green "PASS")" diff --git a/tools/upgrade.nom b/tools/upgrade.nom index 88057eb..469a127 100755 --- a/tools/upgrade.nom +++ b/tools/upgrade.nom @@ -1,10 +1,10 @@ -#!/usr/bin/env nomsu -V4.8.10 +#!/usr/bin/env nomsu -V4.10.12.7 # Tool to automatically update code from old versions of Nomsu. Usage: nomsu tools/upgrade.nom [-i] file1 file2 directory1 ... If "-i" is the first argument, upgrades will be performed in-place. Otherwise, the upgraded code will be printed. - + use "compatibility" use "lib/os.nom" @@ -44,9 +44,9 @@ for %path in %args: %code = (%NomsuCode::from (%Source %filename 1 (size of %file)) %file) %tree = (%code parsed) %uptree = (..) - %tree upgraded from (%start_version or (%tree.version or (Nomsu version))) to %version + %tree upgraded from (%start_version or (%tree.version or (Nomsu version))) to \ + ..%version %text = ((%uptree as nomsu)::text) - when: %inplace: say "Upgraded \%filename" @@ -58,4 +58,5 @@ for %path in %args: ..else: say (bright "\%filename will be changed") - else: say %text + else: + say %text |
