From 5027bd4f0f2c6dcebf667a6924c50b0ca3df235f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 26 Nov 2018 16:28:06 -0800 Subject: [PATCH] Upgraded/autoformatted. --- compatibility/2.3.nom | 2 +- compatibility/2.4.nom | 2 +- compatibility/2.5.5.5.nom | 2 +- compatibility/2.5.nom | 2 +- compatibility/2.nom | 2 +- compatibility/3.5.5.6.nom | 2 +- compatibility/3.6.nom | 2 +- compatibility/3.7.nom | 2 +- compatibility/3.8.nom | 2 +- compatibility/3.nom | 2 +- compatibility/4.10.12.7.nom | 2 +- compatibility/4.11.nom | 9 ++++++--- compatibility/4.12.nom | 2 +- compatibility/4.8.10.nom | 2 +- compatibility/4.9.nom | 2 +- compatibility/compatibility.nom | 4 +++- core/collections.nom | 2 +- core/control_flow.nom | 29 ++++++++++++++++++----------- core/coroutines.nom | 2 +- core/errors.nom | 2 +- core/id.nom | 2 +- core/io.nom | 2 +- core/math.nom | 2 +- core/metaprogramming.nom | 5 +++-- core/operators.nom | 2 +- core/text.nom | 2 +- examples/how_do_i.nom | 5 ++--- lib/base64.nom | 2 +- lib/consolecolor.nom | 2 +- lib/file_hash.nom | 2 +- lib/object.nom | 2 +- lib/os.nom | 3 +-- lib/things.nom | 2 +- tools/autoformat.nom | 2 +- tools/find_action.nom | 2 +- tools/parse.nom | 2 +- tools/repl.nom | 2 +- tools/replace.nom | 22 +++++++++------------- tools/test.nom | 6 ++---- tools/upgrade.nom | 2 +- 40 files changed, 76 insertions(+), 71 deletions(-) diff --git a/compatibility/2.3.nom b/compatibility/2.3.nom index 1664429..21eb2f2 100644 --- a/compatibility/2.3.nom +++ b/compatibility/2.3.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <2.3 to Nomsu 2.3 diff --git a/compatibility/2.4.nom b/compatibility/2.4.nom index dbc6517..edc9f38 100644 --- a/compatibility/2.4.nom +++ b/compatibility/2.4.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <2.4 to Nomsu 2.4 diff --git a/compatibility/2.5.5.5.nom b/compatibility/2.5.5.5.nom index 6da70d4..34bc513 100644 --- a/compatibility/2.5.5.5.nom +++ b/compatibility/2.5.5.5.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <2.5.5.5 to Nomsu 2.5.5.5 diff --git a/compatibility/2.5.nom b/compatibility/2.5.nom index a1a33b7..3e11a85 100644 --- a/compatibility/2.5.nom +++ b/compatibility/2.5.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <2.5 to Nomsu 2.5 diff --git a/compatibility/2.nom b/compatibility/2.nom index 311002d..8004e42 100644 --- a/compatibility/2.nom +++ b/compatibility/2.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu 1 to Nomsu 2 diff --git a/compatibility/3.5.5.6.nom b/compatibility/3.5.5.6.nom index c428b0d..7131d5e 100644 --- a/compatibility/3.5.5.6.nom +++ b/compatibility/3.5.5.6.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <3.5.5.6 to Nomsu 3.5.5.6 diff --git a/compatibility/3.6.nom b/compatibility/3.6.nom index fad8a32..bd08455 100644 --- a/compatibility/3.6.nom +++ b/compatibility/3.6.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <3.6 to 3.6 diff --git a/compatibility/3.7.nom b/compatibility/3.7.nom index 26b643f..9bbc4ba 100644 --- a/compatibility/3.7.nom +++ b/compatibility/3.7.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <3.7 to 3.7 diff --git a/compatibility/3.8.nom b/compatibility/3.8.nom index d70e6e8..12d656e 100644 --- a/compatibility/3.8.nom +++ b/compatibility/3.8.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <3.8 to 3.8 (Text method changes) diff --git a/compatibility/3.nom b/compatibility/3.nom index 87f5c0c..cad5de9 100644 --- a/compatibility/3.nom +++ b/compatibility/3.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <=2 to Nomsu 3 diff --git a/compatibility/4.10.12.7.nom b/compatibility/4.10.12.7.nom index 28c07af..5887684 100644 --- a/compatibility/4.10.12.7.nom +++ b/compatibility/4.10.12.7.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <4.10.12.7 to 4.10.12.7 use "compatibility/compatibility.nom" diff --git a/compatibility/4.11.nom b/compatibility/4.11.nom index 8021be3..5226895 100644 --- a/compatibility/4.11.nom +++ b/compatibility/4.11.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <4.11 to Nomsu 4.11 (overhaul of function literals, deleting (if all of ...), etc. shorthand) @@ -45,8 +45,11 @@ upgrade action (line number of %pos in %text) to "4.11" as (..) # Deduplicating goto labels: upgrade action [=== %label ===, *** %label ***] to "4.11" as (--- %label ---) -upgrade action [===stop %label ===, ***stop %label ***] to "4.11" as (---stop %label ---) -upgrade action [===next %label ===, ***next %label ***] to "4.11" as (---next %label ---) +upgrade action [===stop %label ===, ***stop %label ***] to "4.11" as (..) + ---stop %label --- + +upgrade action [===next %label ===, ***next %label ***] to "4.11" as (..) + ---next %label --- # Deprecating shorthand functions: upgrade action [if all of %items %body, if all of %items then %body] to "4.11" as (..) diff --git a/compatibility/4.12.nom b/compatibility/4.12.nom index 17d90ff..24809ab 100644 --- a/compatibility/4.12.nom +++ b/compatibility/4.12.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.12 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <4.11 to Nomsu 4.11 (overhaul of function literals, deleting (if all of ...), etc. shorthand) diff --git a/compatibility/4.8.10.nom b/compatibility/4.8.10.nom index f20886f..78ef6a6 100644 --- a/compatibility/4.8.10.nom +++ b/compatibility/4.8.10.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <4.8.10 to 4.8.10 (renaming "action" -> "means") use "compatibility/compatibility.nom" diff --git a/compatibility/4.9.nom b/compatibility/4.9.nom index 5dc0d29..acfbc29 100644 --- a/compatibility/4.9.nom +++ b/compatibility/4.9.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines upgrades from Nomsu <4.9 to 4.9 use "compatibility/compatibility.nom" diff --git a/compatibility/compatibility.nom b/compatibility/compatibility.nom index 4d96d89..56a3b2c 100644 --- a/compatibility/compatibility.nom +++ b/compatibility/compatibility.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file contains code for defining ways to upgrade code between different versions of Nomsu. @@ -92,11 +92,13 @@ externally [..] add %k = (%v upgraded from %start_version to %end_version) set %with_upgraded_args's metatable to (%tree's metatable) %tree = (%UPGRADES.%ver %with_upgraded_args %end_version) + if (%tree.version != %end_version): %tree = (SyntaxTree {: for %k = %v in %tree: add %k = %v}) %tree.version = %end_version if %tree.shebang: %tree.shebang = "#!/usr/bin/env nomsu -V\%end_version\n" + return %tree externally (%tree upgraded from %start_version) means (..) diff --git a/core/collections.nom b/core/collections.nom index 9272d13..c34e8bc 100644 --- a/core/collections.nom +++ b/core/collections.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file contains code that supports manipulating and using collections like lists and dictionaries. diff --git a/core/control_flow.nom b/core/control_flow.nom index 4fe94e4..6cc2599 100644 --- a/core/control_flow.nom +++ b/core/control_flow.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file contains compile-time actions that define basic control flow structures like "if" statements and loops. @@ -87,10 +87,16 @@ test: assume (%i == 0) (--- %label ---) compiles to "\ - ..::label_\((%label.stub::as lua id) if (%label.type == "Action") else (%label as lua identifier))::" + ..::label_\(..) + (%label.stub::as lua id) if (%label.type == "Action") else (..) + %label as lua identifier + ..::" (go to %label) compiles to "\ - ..goto label_\((%label.stub::as lua id) if (%label.type == "Action") else (%label as lua identifier))" + ..goto label_\(..) + (%label.stub::as lua id) if (%label.type == "Action") else (..) + %label as lua identifier + .." # Basic loop control (stop %var) compiles to: @@ -105,11 +111,8 @@ test: ..else: return (Lua "goto continue") -(---stop %var ---) compiles to "\ - ..::stop_\(%var as lua identifier)::" - -(---next %var ---) compiles to "\ - ..::continue_\(%var as lua identifier)::" +(---stop %var ---) compiles to "::stop_\(%var as lua identifier)::" +(---next %var ---) compiles to "::continue_\(%var as lua identifier)::" # While loops test: @@ -124,12 +127,14 @@ test: do next barf "Failed to 'do next'" assume (%x == 20) + (repeat while %condition %body) compiles to: %lua = (Lua "while \(%condition as lua expr) do\n \(%body as lua)") if (%body has subtree \(do next)): %lua::append "\n ::continue::" %lua::append "\nend --while-loop" return %lua + (repeat %body) parses as (repeat while (yes) %body) (repeat until %condition %body) parses as (repeat while (not %condition) %body) @@ -185,10 +190,11 @@ test: test: %x = 0 - repeat 5 times: %x += 1 + repeat 5 times: + %x += 1 assume %x == 5 -(repeat %n times %body) parses as (for (=lua "_XXX_") in 1 to %n %body) +(repeat %n times %body) parses as (for (=lua "_XXX_") in 1 to %n %body) test: %a = [10, 20, 30, 40, 50] %b = [] @@ -229,7 +235,8 @@ test: %lua::append "\nend -- end of scope for stopping for-loop" return %lua -(for %var in %iterable %body) parses as (for %var in %iterable at (=lua "__") %body) +(for %var in %iterable %body) parses as (..) + for %var in %iterable at (=lua "__") %body test: %d = {a: 10, b: 20, c: 30, d: 40, e: 50} diff --git a/core/coroutines.nom b/core/coroutines.nom index 73b6854..f34f0c9 100644 --- a/core/coroutines.nom +++ b/core/coroutines.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines the code that creates and manipulates coroutines diff --git a/core/errors.nom b/core/errors.nom index aa5346b..a7e4cff 100644 --- a/core/errors.nom +++ b/core/errors.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file contains basic error reporting code diff --git a/core/id.nom b/core/id.nom index 9ee961d..78af96c 100644 --- a/core/id.nom +++ b/core/id.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # A simple UUID function based on RFC 4122: http://www.ietf.org/rfc/rfc4122.txt diff --git a/core/io.nom b/core/io.nom index 04efb91..8f22b07 100644 --- a/core/io.nom +++ b/core/io.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file contains basic input/output code diff --git a/core/math.nom b/core/math.nom index ae01620..bef6bbb 100644 --- a/core/math.nom +++ b/core/math.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines some common math literals and functions diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom index 420c62d..99488c7 100644 --- a/core/metaprogramming.nom +++ b/core/metaprogramming.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This File contains actions for making actions and compile-time actions and some helper functions to make that easier. @@ -373,7 +373,8 @@ externally (type of %) means: test: assume ((run "return (2 + 99)") == 101) %x = 0 - externally (set to %) means: external %x = % + externally (set to %) means: + external %x = % run "set to 1" assume %x == 1 assume (run \(return \(\(5) + \(5)))) == 10 diff --git a/core/operators.nom b/core/operators.nom index 1a28a6a..9997a47 100644 --- a/core/operators.nom +++ b/core/operators.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file contains definitions of operators like "+" and "and". diff --git a/core/text.nom b/core/text.nom index 1245235..fcdf678 100644 --- a/core/text.nom +++ b/core/text.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file contains some definitions of text escape sequences, including ANSI console color codes. diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom index bd868be..a8725e8 100644 --- a/examples/how_do_i.nom +++ b/examples/how_do_i.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # How do I... # Write a comment? Put a # and go till the end of the line # How do I write a multi-line comment? @@ -166,8 +166,7 @@ repeat until (%x > 3): repeat: say "repeat loop #\%x" %x += 1 - if (%x > 3): - stop repeating + if (%x > 3): stop # How do I do a 'goto'? do: diff --git a/lib/base64.nom b/lib/base64.nom index 04003a2..c48b42a 100644 --- a/lib/base64.nom +++ b/lib/base64.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines actions for encoding/decoding base 64, as specified in: https://tools.ietf.org/html/rfc4648 diff --git a/lib/consolecolor.nom b/lib/consolecolor.nom index 2c3665a..31d4789 100644 --- a/lib/consolecolor.nom +++ b/lib/consolecolor.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines actions for ANSI console color escape codes. diff --git a/lib/file_hash.nom b/lib/file_hash.nom index bda79d5..32c7209 100644 --- a/lib/file_hash.nom +++ b/lib/file_hash.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines some actions for hashing files and looking up files by hash. diff --git a/lib/object.nom b/lib/object.nom index 94ca9f0..551512f 100644 --- a/lib/object.nom +++ b/lib/object.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file contains the implementation of an Object-Oriented programming system. diff --git a/lib/os.nom b/lib/os.nom index 9f9f637..14ae82c 100644 --- a/lib/os.nom +++ b/lib/os.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines some actions that interact with the operating system and filesystem. @@ -28,7 +28,6 @@ test: read file "lib/os.nom" externally (read file %filename) means (=lua "Files.read(\%filename)") - externally [..] write to file %filename %text, to file %filename write %text write %text to file %filename diff --git a/lib/things.nom b/lib/things.nom index 2562815..c7ff2d6 100644 --- a/lib/things.nom +++ b/lib/things.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # A library for simple object oriented programming. diff --git a/tools/autoformat.nom b/tools/autoformat.nom index 5661145..44d91e3 100755 --- a/tools/autoformat.nom +++ b/tools/autoformat.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # Auto-format Nomsu code. Usage: nomsu tools/autoformat.nom [-i] file1 file2 directory1 ... diff --git a/tools/find_action.nom b/tools/find_action.nom index 6b85ad3..bcc80ac 100755 --- a/tools/find_action.nom +++ b/tools/find_action.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # Find an action by its stub. Usage: nomsu tools/find_action.nom "foo %" file1 file2 directory1 ... diff --git a/tools/parse.nom b/tools/parse.nom index cb367ab..4e61473 100755 --- a/tools/parse.nom +++ b/tools/parse.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # Tool to print out a parse tree of files in an easy-to-read format. Usage: nomsu tools/parse.nom file1 file2 directory1 ... diff --git a/tools/repl.nom b/tools/repl.nom index ac61242..8f9d013 100644 --- a/tools/repl.nom +++ b/tools/repl.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # This file defines a Read-Evaluate-Print-Loop (REPL) for Nomsu diff --git a/tools/replace.nom b/tools/replace.nom index 66ca690..3ce2411 100755 --- a/tools/replace.nom +++ b/tools/replace.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # Tool to find and replace one tree with another. nomsu tools/replace.nom [-i] tree_to_replace replacement file1 file2 directory1 ... @@ -10,29 +10,25 @@ use "lib/os.nom" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ barf "Deprecated." - if ((size of %args.extra_args) < 3): say "Usage: nomsu tools/replace.nom [-i] tree_to_replace replacement files..." lua> "os.exit(1)" - -%pattern = ((%args.extra_args.1) parsed) -%replacement = ((%args.extra_args.2) parsed) +%pattern = (%args.extra_args.1 parsed) +%replacement = (%args.extra_args.2 parsed) for %filename in %args.extra_args at %i: - if (%i < 3): do next %i + if (%i < 3): + do next %i %file = (read file %filename) - unless %file: barf "File does not exist: \%filename" + unless %file: + barf "File does not exist: \%filename" %nomsu = (NomsuCode from (Source %filename 1 (size of %file)) %file) %tree = (%nomsu parsed) + # TODO: fix this to use variable substitution - %tree2 = (..) - %tree::map (..) - for %subtree: - if (%subtree == %pattern): - return %replacement + %tree2 = (%tree::map (for %subtree: if (%subtree == %pattern): return %replacement)) if (%tree2 == %tree): say "No changes in \%filename" do next %filename - %text = ((%tree2 as nomsu)::text) when: %args."-i": diff --git a/tools/test.nom b/tools/test.nom index 1fd5ee3..bcbd289 100755 --- a/tools/test.nom +++ b/tools/test.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # 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 ... @@ -18,9 +18,7 @@ for %filename in (command line args).extra_args: for %src = %test in %tests: if (%src.filename == %filename): if %version: - %test = "\ - ..#!/usr/bin/env nomsu -V\(%version) - \%test" + %test = "#!/usr/bin/env nomsu -V\%version\n\%test" %file_tests::add {test: %test, source: %src} unless (%file_tests is empty): diff --git a/tools/upgrade.nom b/tools/upgrade.nom index 781e71b..0512134 100755 --- a/tools/upgrade.nom +++ b/tools/upgrade.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.11.12.8 +#!/usr/bin/env nomsu -V4.12.12.8 # Tool to automatically update code from old versions of Nomsu. Usage: nomsu tools/upgrade.nom [-i] file1 file2 directory1 ...