From e665d9725c4bb02f4c18d16527367f424cb880fa Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 20 Mar 2019 15:55:57 -0700 Subject: Auto-updated to 7.0.0 syntax and removed some shims. --- lib/tools/find.nom | 19 ++-- lib/tools/format.nom | 3 +- lib/tools/install.nom | 7 +- lib/tools/list.nom | 7 +- lib/tools/parse.nom | 11 ++- lib/tools/repl.nom | 17 ++-- lib/tools/replace.nom | 43 +++++---- lib/tools/test.nom | 11 ++- lib/tools/tutorial.nom | 246 ++++++++++++++++++++++++------------------------ lib/tools/uninstall.nom | 15 +-- lib/tools/upgrade.nom | 7 +- 11 files changed, 200 insertions(+), 186 deletions(-) (limited to 'lib/tools') diff --git a/lib/tools/find.nom b/lib/tools/find.nom index e28681a..45a51e5 100755 --- a/lib/tools/find.nom +++ b/lib/tools/find.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V6.15.13.8 -# +#!/usr/bin/env nomsu -V7.0.0 + +### This is a tool to find syntax trees matching a pattern. "*" is a wildcard that will match any subtree, and "**" is a wildcard that will match any 0 or more subtrees. "**" is greedy, so extra arguments after it will @@ -40,17 +41,19 @@ command line program with $args: ($tree.type == "Action"): if (($tree, get stub) != ($patt, get stub)): return (no) - for $ in 1 to (#$patt): + for $ in (1 to #$patt): if ($patt.$ is syntax tree): - if ($patt.$ == \$multi_wildcard): return (yes) + if ($patt.$ == ("Var" tree with "multi_wildcard")): return (yes) unless ($tree.$ matches $patt.$): return (no) ..else: unless ($tree.$ == $patt.$): return (no) - if ((#$tree) != (#$patt)): return (no) + if (#$tree != #$patt): + return (no) + return (yes) $filenames = ($args.extras, from 2 to -1) - if ((#$filenames) == 0): + if (#$filenames == 0): say (" Warning: searching stdin (ctrl-d to abort). To avoid this message, use nomsu -t find - ") @@ -60,7 +63,7 @@ command line program with $args: $file = (read file $filename) unless $file: fail "File does not exist: \$filename" - $code = (NomsuCode from ($Source $filename 1 (#$file)) $file) + $code = (NomsuCode from ($Source $filename 1 #$file) $file) try: $tree = ($code parsed) ..if it fails with $msg: @@ -91,7 +94,7 @@ command line program with $args: recurse $t on $sub if $args.l: - if ((#$results) > 0): + if (#$results > 0): say $filename ..else: sort $results by $ -> $.line diff --git a/lib/tools/format.nom b/lib/tools/format.nom index c8764a3..e20adbd 100755 --- a/lib/tools/format.nom +++ b/lib/tools/format.nom @@ -1,4 +1,5 @@ -#!/usr/bin/env nomsu -V7 +#!/usr/bin/env nomsu -V7.0.0 + ### Auto-format Nomsu code. Usage: nomsu -t format [-i] file1 file2... diff --git a/lib/tools/install.nom b/lib/tools/install.nom index 5eb9a3f..afd6069 100755 --- a/lib/tools/install.nom +++ b/lib/tools/install.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V6 -# +#!/usr/bin/env nomsu -V7.0.0 + +### A tool to install third party Nomsu packages Usage: @@ -56,4 +57,4 @@ command line program with $args: $cmd = ($filename, with $patt -> $action.cmd) run command $cmd do next $filename - fail "Not sure what to do with \$filename" + fail "Not sure what to do with \$filename" \ No newline at end of file diff --git a/lib/tools/list.nom b/lib/tools/list.nom index 8e7c3ac..77bb8a7 100644 --- a/lib/tools/list.nom +++ b/lib/tools/list.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V6 -# +#!/usr/bin/env nomsu -V7.0.0 + +### A tool to list installed third party Nomsu packages Usage: @@ -17,4 +18,4 @@ command line program with $args: for $f in ($packages, lines): if ($f != ""): $f = ($f, with "%.nom$" -> "") - say " * \$f" + say " * \$f" \ No newline at end of file diff --git a/lib/tools/parse.nom b/lib/tools/parse.nom index 89af6f6..7224901 100755 --- a/lib/tools/parse.nom +++ b/lib/tools/parse.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V6.15.13.8 -# +#!/usr/bin/env nomsu -V7.0.0 + +### Tool to print out a parse tree of files in an easy-to-read format. Usage: nomsu tools/parse.nom file1 file2 directory1 ... @@ -42,9 +43,9 @@ use "commandline" "a Syntax Tree": $body = ([: for $bit in $: add ($bit as xml)], joined with " ") if ($.type == "Action"): - return "\$body" + return "\($body)" ..else: - return "<\($.type)>\$body" + return "<\($.type)>\($body)" "Text": return @@ -73,7 +74,7 @@ command line program with $args: $file = (read file $filename) unless $file: fail "File does not exist: \$filename" - $nomsu = (NomsuCode from (Source $filename 1 (#$file)) $file) + $nomsu = (NomsuCode from (Source $filename 1 #$file) $file) $tree = ($nomsu parsed) when: ($args.x or $args.xml): diff --git a/lib/tools/repl.nom b/lib/tools/repl.nom index 76b35cb..2e0c7da 100755 --- a/lib/tools/repl.nom +++ b/lib/tools/repl.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V6.15.13.8 -# +#!/usr/bin/env nomsu -V7.0.0 + +### This file defines a Read-Evaluate-Print-Loop (REPL) for Nomsu use "consolecolor" @@ -30,12 +31,12 @@ command line program with $args: ") - # Best way I know of to detect the number of return values and only + ### Best way I know of to detect the number of return values and only print if it's >0: (say results of (*extra arguments*)) means: $N = (select "#" (*extra arguments*)) if ($N == 0): return - for $ in 1 to $N: + for $ in (1 to $N): $ret = (select $ (*extra arguments*)) if ($ret is "Text"): $ret = (quote $ret) @@ -49,15 +50,15 @@ command line program with $args: $line = ($io.read "*L") say (reset color) inline if (($line == "\n") or (not $line)): - if ((#$buff) > 0): - # clear the line + if (#$buff > 0): + ### clear the line if $(COLOR ENABLED): say "\027[1A\027[2K" inline go to (run buffer) $buff, add ($line, with "\t" -> " ") say (dim (yellow ".. ")) inline --- (run buffer) --- - if ((#$buff) == 0): stop + if (#$buff == 0): stop $buff = ($buff, joined) spoof file $buff try: @@ -82,7 +83,7 @@ command line program with $args: unless $lua: do next - # TODO: this is a bit hacky, it just defaults variables to global + ### TODO: this is a bit hacky, it just defaults variables to global so that stuff mostly works across multiple lines. It would be nicer if local variables actually worked. $lua, remove free vars diff --git a/lib/tools/replace.nom b/lib/tools/replace.nom index 3a56002..aea1b03 100755 --- a/lib/tools/replace.nom +++ b/lib/tools/replace.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V6.15.13.8 -# +#!/usr/bin/env nomsu -V7.0.0 + +### This is a tool to replace syntax trees with something new. Usage: @@ -22,7 +23,7 @@ use "commandline" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ command line program with $args: - if ((#$args.extras) < 2): + if (#$args.extras < 2): fail (" Usage: nomsu -t replace [--literal="$v1 $v2..."] file1 file2... ") @@ -38,19 +39,19 @@ command line program with $args: if (($pattern_tree.type == "Var") and (not $literal_vars.($pattern_tree.1))): fail "Pattern matches every part of the file." - $pattern_vars = { - : for $ in recursive $pattern_tree: + $pattern_vars = {: + for $ in recursive $pattern_tree: if (($.type == "Var") and (not $literal_vars.($.1))): add $.1 for $child in $: if ($child is "a Syntax Tree"): recurse $ on $child } - # TODO: support wildcards and unpacking + ### TODO: support wildcards and unpacking e.g. nomsu -t replace "test(: $test; *$more_tests)" "*$more_tests; *$test" ($tree matches $patt with $substitution_values) means: - # TODO: optimize - $substitution_values = {: for $k = $v in $substitution_values: add $k = $v} + ### TODO: optimize + $substitution_values = {: for ($k = $v) in $substitution_values: add $k = $v} when: (not ($tree is syntax tree)): return (no) (($patt.type == "Var") and $pattern_vars.($patt.1)): @@ -66,21 +67,23 @@ command line program with $args: ($tree.type == "Action"): if (($tree, get stub) != ($patt, get stub)): return (nil) - for $ in 1 to (#$patt): + for $ in (1 to #$patt): if ($patt.$ is syntax tree): $new_values = ($tree.$ matches $patt.$ with $substitution_values) unless $new_values: return (nil) - for $k = $v in $new_values: + for ($k = $v) in $new_values: $substitution_values.$k = $v ..else: unless ($tree.$ == $patt.$): return (nil) - if ((#$tree) != (#$patt)): return (nil) + if (#$tree != #$patt): + return (nil) + return $substitution_values $filenames = ($args.extras, from 3 to -1) - if ((#$filenames) == 0): + if (#$filenames == 0): say (" Warning: searching stdin (ctrl-d to abort). To avoid this message, use nomsu -t find - ") @@ -90,7 +93,7 @@ command line program with $args: $file = (read file $filename) unless $file: fail "File does not exist: \$filename" - $code = (NomsuCode from ($Source $filename 1 (#$file)) $file) + $code = (NomsuCode from ($Source $filename 1 #$file) $file) try: $tree = ($code parsed) ..if it fails with $msg: @@ -112,12 +115,12 @@ command line program with $args: $values = ($t matches $pattern_tree with {}) if $values: $matched.$t = (yes) - for $k = $v in $values: + for ($k = $v) in $values: $values.$k = ($v with replacements) - $ret = ($replacement_tree with vars $values) + $ret = ($replacement_tree, with $values) if ($args.i and (not $args.f)): if ($user_answers.$t == (nil)): - if ((#$user_answers) > 0): say "" + if (#$user_answers > 0): say "" $user_answers.$t = "n" say "\(bright)Should this:" say (" @@ -134,12 +137,12 @@ command line program with $args: return $ret $tree2 = ($tree with replacements) if $args.i: - if ((#$user_answers) > 0): say "" + if (#$user_answers > 0): say "" say (" - \(#$replaced)/\(#$matched) replacement\("" if ((#$replaced) == 1) else "s") in \$filename + \(#$replaced)/\(#$matched) replacement\("" if (#$replaced == 1) else "s") in \$filename ") - if ((#$replaced) > 0): + if (#$replaced > 0): write "\($tree2 as nomsu)" to file $filename ..else: - say ($tree2 as nomsu) \ No newline at end of file + say ($tree2 as nomsu) diff --git a/lib/tools/test.nom b/lib/tools/test.nom index 9aecd94..8244f70 100755 --- a/lib/tools/test.nom +++ b/lib/tools/test.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V6.15.13.8 -# +#!/usr/bin/env nomsu -V7.0.0 + +### 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 ... @@ -10,7 +11,7 @@ use "commandline" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ command line program with $args: - for $filename in $args.extras at $i: + for ($i = $filename) in $args.extras: $file = (read file $filename) unless $file: fail "Couldn't find \$filename" @@ -22,7 +23,7 @@ command line program with $args: ]* nomsu %-V[ ]*([%d.]*) ") $file_tests = [] - for $src = $test in (nomsu environment, Module $filename).TESTS: + for ($src = $test) in (nomsu environment, Module $filename).TESTS: if $version: $test = (" #!/usr/bin/env nomsu -V\$version @@ -64,4 +65,4 @@ command line program with $args: say (red (bright "FAIL")) ..else: say "\r[\(red (bright "FAIL"))" - say "\($failures, joined with "\n", indented)" + say "\($failures, joined with "\n", indented)" \ No newline at end of file diff --git a/lib/tools/tutorial.nom b/lib/tools/tutorial.nom index c74d088..0dda917 100755 --- a/lib/tools/tutorial.nom +++ b/lib/tools/tutorial.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V6.13.12.8 -# +#!/usr/bin/env nomsu -V7.0.0 + +### This is a Nomsu tutorial. use "filesystem" @@ -14,71 +15,71 @@ use "shell" ") [, ???] all compile to - \( - at ("Text" tree with "\((this tree).source)") fail - \("Incomplete code: This needs to be filled in.") + ( + "Action" tree with "at" ("Text" tree with "\((this tree).source)") "fail" + `"Incomplete code: This needs to be filled in." ) as lua ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $lessons = [ lesson "Variables": - # In Nomsu, variables have a "$" prefix, and you can just assign to them + ### In Nomsu, variables have a "$" prefix, and you can just assign to them without declaring them first: $x = 1 test that ($x == 1) - # Variables which have not yet been set have the value (nil) + ### Variables which have not yet been set have the value (nil) test that ($foobar == (nil)) - # Variables can be nameless: + ### Variables can be nameless: $ = 99 - # Or have spaces, if surrounded with parentheses: + ### Or have spaces, if surrounded with parentheses: $(my favorite number) = 23 - # Figure out what value $my_var should have: + ### Figure out what value $my_var should have: $my_var = 100 $my_var = ($my_var + $x + $(my favorite number)) test that ($my_var == (???)) lesson "Actions": - # Fix this action so the tests pass: + ### Fix this action so the tests pass: ($x doubled) means ((???) * $x) - # Tests: + ### Tests: test that ((2 doubled) == 4) test that ((-5 doubled) == -10) lesson "Blocks": - # When you need to do multiple things inside an action, use a block. - # Blocks are written with a colon followed by some indented code: + ### When you need to do multiple things inside an action, use a block. + ### Blocks are written with a colon followed by some indented code: ($x doubled then squared) means: $x = (2 * $x) $x = (???) return $x - # Blocks are also used for loops and conditionals: + ### Blocks are also used for loops and conditionals: for $num in [0, -1, 10, 4]: $correct_answer = (4 * ($num * $num)) if (($num doubled then squared) != $correct_answer): fail "Wrong answer for \($num)!" - + lesson "Text": - # Nomsu text is enclosed in double quotation marks: + ### Nomsu text is enclosed in double quotation marks: $text = "Hello" - # You can insert values into text using a backslash: + ### You can insert values into text using a backslash: test that ("two plus three is \(2 + 3)" == (???)) - # Variables don't require parentheses, but other expressions do: + ### Variables don't require parentheses, but other expressions do: $x = 99 test that ("$x is \$x" == (???)) - # This can be used to convert values to text: + ### This can be used to convert values to text: test that ("\$x" == (???)) - # Longer strings use '("' followed by an indented region: + ### Longer strings use '("' followed by an indented region: $long = (" line one line two with spaces at the front @@ -91,234 +92,231 @@ $lessons = [ ") lesson "Conditionals": - # Make this action return "big" if its argument - # is bigger than 99, otherwise return "small" + ### Make this action return "big" if its argument + ### is bigger than 99, otherwise return "small" (the size of $n) means: if (???): ..else: - # Tests: + ### Tests: for $big_number in [9999, 100]: test that ((the size of $big_number) == "big") - + for $small_number in [0, 1, -5, -999, 99]: test that ((the size of $small_number) == "small") lesson "Loops": - # Fix this action so the tests pass: + ### Fix this action so the tests pass: (the sum of $numbers) means: $sum = 0 - # You can loop over the values in a list like this: + ### You can loop over the values in a list like this: for $number in $numbers: - # Hint: math expressions may need parentheses + ### Hint: math expressions may need parentheses return $sum - # Tests: + ### Tests: test that ((the sum of [1, 2, 3, 4, 5]) == 15) test that ((the sum of [100, 200]) == 300) - # You can also loop over a number range like this: + ### You can also loop over a number range like this: $total = 0 - for $i in 1 to 3: + for $i in (1 to 3): $total = ($total + $i) test that ($total == (???)) lesson "Variable Scopes": - # Nomsu's variables are local by default, and actions have their own scopes: + ### Nomsu's variables are local by default, and actions have their own scopes: $x = 1 $y = 2 - # Define an action that sets a variable: + ### Define an action that sets a variable: (do something) means: - # The variable $y is never set in this action, so it has the same value + ### The variable $y is never set in this action, so it has the same value it has outside this action. test that ($y == (???)) - # $x is set inside this action, and actions have their own scopes. + ### $x is set inside this action, and actions have their own scopes. $x = $y - # What number should $x be here? + ### What number should $x be here? test that ($x == (???)) - # After running the action, what value should $x have? + ### After running the action, what value should $x have? do something test that ($x == (???)) lesson "More Variable Scopes": - # Loops and conditionals do *not* have their own scopes: + ### Loops and conditionals do *not* have their own scopes: $z = 1 if (1 == 1): - # Set $z inside a conditional: + ### Set $z inside a conditional: $z = 2 - # After assigning in a conditional, what should $z be? + ### After assigning in a conditional, what should $z be? test that ($z == (???)) - for $ in 1 to 1: - # Set $z inside a loop: + for $ in (1 to 1): + ### Set $z inside a loop: $z = 3 - # After assigning in a loop, what should $z be? + ### After assigning in a loop, what should $z be? test that ($z == (???)) lesson "Externals": - # The 'external' block lets you modify variables outside an action: + ### The 'external' block lets you modify variables outside an action: $x = 1 (do something) means: external: $x = 2 do something - # After running the action that sets $x in an 'external' block, what should $x be? + ### After running the action that sets $x in an 'external' block, what should $x be? test that ($x == (???)) lesson "Locals": - # The 'with' block lets you create a local scope for the variables you list: + ### The 'with' block lets you create a local scope for the variables you list: $y = 1 $z = 1 with [$y]: $y = 2 $z = 2 - # After setting $y and $z in the 'with [$y]' block, what should $y and $z be? + ### After setting $y and $z in the 'with [$y]' block, what should $y and $z be? test that ($y == (???)) test that ($z == (???)) lesson "Failure and Recovery": $what_happened = "nothing" - # In Nomsu, sometimes things fail, but you can recover from failures with 'try': + ### In Nomsu, sometimes things fail, but you can recover from failures with 'try': try: - # The 'fail' action triggers failure + ### The 'fail' action triggers failure fail "Oh no!" ..if it fails: $what_happened = "failure" ..if it succeeds: $what_happened = "success" - # What do you think happened? + ### What do you think happened? test that ($what_happened == (???)) - # Note: a 'try' block will silence failures, so this has no effect: + ### Note: a 'try' block will silence failures, so this has no effect: try: fail lesson "Indexing": - # Nomsu uses the "." operator to access things inside an object: + ### Nomsu uses the "." operator to access things inside an object: $dictionary = {.dog = "A lovable doofus", .cat = "An internet superstar"} test that ($dictionary.dog == "A lovable doofus") test that ($dictionary.cat == (???)) - # If you try to access a key that's not in an object, the result is (nil): + ### If you try to access a key that's not in an object, the result is (nil): test that ($dictionary.mimsy == (???)) - # $dictionary.dog is just a shorthand for $dictionary."dog". + ### $dictionary.dog is just a shorthand for $dictionary."dog". You may need to use the longer form for strings with spaces: $dictionary."guinea pig" = "A real-life tribble" - # Dictionaries are created with curly braces ({}) and can have + ### Dictionaries are created with curly braces ({}) and can have anything as a key or value, including numbers or other dictionaries: $dictionary.5 = "The number five" $dictionary.five = 5 $dictionary.myself = $dictionary test that ($dictionary.myself == (???)) - # Lists are similar, but use square brackets ([]) + ### Lists are similar, but use square brackets ([]) and can only have numbers as keys, starting at 1: $list = ["first", "second", 999] test that ($list.1 == "first") test that ($list.2 == (???)) test that ($list.3 == (???)) - # Hint: 4 should be a missing key + ### Hint: 4 should be a missing key test that ($list.4 == (???)) test that ($list.foobar == (???)) - # The "#" action gets the number of items inside something: - test that ((#$list) == (???)) - test that ((#{.x = 10, .y = 20}) == (???)) + ### The "#" action gets the number of items inside something: + test that (#$list == (???)) + test that (#{.x = 10, .y = 20} == (???)) lesson "Methods": - # The "," is used for method calls, which means calling an action + ### The "," is used for method calls, which means calling an action that's stored on an object (with the object as the first argument). - # Lists have an "add" method that puts new items at the end: + ### Lists have an "add" method that puts new items at the end: $list = [-4, -6, 5] $list, add 3 test that ($list == [-4, -6, 5, 3]) $list, add 7 test that ($list == [???]) - # Text also has some methods like: + ### Text also has some methods like: $name = "Harry Tuttle" test that (($name, from 7 to 12) == "Tuttle") test that (($name, with "Tuttle" -> "Buttle") == (???)) - # Methods can be chained too: + ### Methods can be chained too: test that (($name, with "Tuttle" -> "Buttle", from 7 to 12) == (???)) lesson "Object Oriented Programming": - # Object Oriented Programming deals with things that have + ### Object Oriented Programming deals with things that have associated values and behaviors. - # Here, we define a Buffer to be a thing that has a .bits value: + ### Here, we define a Buffer to be a thing that has a .bits value: (a Buffer) is (a thing) with [$bits]: - # And some methods: + ### And some methods: ($self, set up) means: - # This method runs when a new buffer is created + ### This method runs when a new buffer is created $bits = [] - # This method is used to add to a buffer + ### This method is used to add to a buffer ($self, add $bit) means: $bits, add $bit - - # ($list, joined) is a list method that concatenates the list items: + + ### ($list, joined) is a list method that concatenates the list items: ($self, as text) means ($bits, joined) - # Write a method called ($self, length) that returns the sum + ### Write a method called ($self, length) that returns the sum of the lengths of each bit in the buffer: - - # Create an instance of a Buffer: + + ### Create an instance of a Buffer: $b = (a Buffer) - test that ($b is "a Buffer") + test that ($b == "a Buffer") test that ((type of $b) == "a Buffer") $b, add "xx" $b, add "yyy" test that (($b, as text) == "xxyy") test that (($b, length) == 5) - - # You can define a thing that inherits the behaviors of another thing like this: + + ### You can define a thing that inherits the behaviors of another thing like this: (a Backwards Buffer) is (a Buffer) with [$bits]: - # ($list, reversed) is a method that returns a copy of $list with + ### ($list, reversed) is a method that returns a copy of $list with the order of the items reversed. ($self, as text) means ($bits, reversed, joined) - $bb = (a Backwards Buffer) $bb, add "one" $bb, add "two" test that (($bb, length) == (???)) test that (($bb, as text) == (???)) - + lesson "Files Part 1": - # Define an external action here: + ### Define an external action here: external: - # These will be used in the next lesson + ### These will be used in the next lesson $foobar = 23 ($x tripled) means: test that ((5 tripled) == 15) test that ((2 tripled) == 6) - + lesson "Files Part 2": - # 'use' is the action for importing from other files - # It takes the path to the file (without the .nom extension): + ### 'use' is the action for importing from other files + ### It takes the path to the file (without the .nom extension): use () test that ((10 tripled) == (???)) test that ($foobar == (???)) ] - $(ask normally) = $(ask) - command line program with $args: if ($args.help or $args.h): say (" @@ -334,18 +332,16 @@ command line program with $args: +------------------------------------+ ") - - # For this tutorial questions are hilighted in bold cyan: + + ### For this tutorial questions are hilighted in bold cyan: (ask $q) means (ask normally (bold (cyan $q))) - # Find the tutorial file directory: + ### Find the tutorial file directory: if ($args.extras is empty): $tutorial_dir = "./nomsu_tutorial" unless ($Files.exists $tutorial_dir): when - ask (" - The Nomsu tutorial files will be in \$tutorial_dir is that okay? [Y/n/exit] \; - ") + ask "The Nomsu tutorial files will be in \$tutorial_dir is that okay? [Y/n/exit] " ..is: "n" "N" "no": $tutorial_dir = (ask "Where do you want to put the tutorial? ") @@ -353,11 +349,11 @@ command line program with $args: ..else: $tutorial_dir = $args.extras.1 - # Set up the tutorial file directory: + ### Set up the tutorial file directory: if (not ($Files.exists $tutorial_dir)): make directory $tutorial_dir (filename of $i) means ("\($tutorial_dir)/lesson\$i.nom", with "//" -> "/") - for $lesson in $lessons at $i: + for ($i = $lesson) in $lessons: $filename = (filename of $i) unless ($Files.exists $filename): $lesson_text = @@ -365,7 +361,7 @@ command line program with $args: "\"\(filename of ($i - 1), with "%.nom$" -> "", with "^%./" -> "")\"" write $lesson_text to file $filename - # Display info about editing the tutorial files: + ### Display info about editing the tutorial files: if $args.x: say (" The tutorial files are located in \$tutorial_dir. @@ -381,7 +377,7 @@ command line program with $args: ..is: "n" "N" "no": $EDITOR = (nil) - + unless $EDITOR: say $EDITOR = @@ -390,22 +386,24 @@ command line program with $args: (leave blank if you want to edit on your own in a different window) > \; ") - if ($EDITOR == ""): $EDITOR = (nil) - + + if ($EDITOR == ""): + $EDITOR = (nil) + (run lesson $i) means: $filename = (filename of $i) $file = (read file $filename) - $file = ($NomsuCode, from (Source $filename 1 (#$file)) $file) + $file = ($NomsuCode, from (Source $filename 1 #$file) $file) $tree = ($file parsed) $tree = - $tree with $ ->: - if ($ == \()): - return ("Text" tree with (filename of ($i - 1), with "%.nom$" -> "")) + $tree, with + $ ->: + if ($ == `()): + return ("Text" tree with (filename of ($i - 1), with "%.nom$" -> "")) run $tree - - (get failures) means [ - : for $lesson in $lessons at $i: + (get failures) means [: + for ($i = $lesson) in $lessons: try: run lesson $i ..if it fails with $msg: @@ -429,7 +427,7 @@ command line program with $args: ") $failures = (get failures) - for $lesson in $lessons at $i: + for ($i = $lesson) in $lessons: for $f in $failures: if ($f.lesson_number == $i): say "\(red " - ")\(bold (red "\$i. \($lesson.name) [incomplete]"))" @@ -439,20 +437,18 @@ command line program with $args: if $(COLOR ENABLED): say (" - \(bold "Your progress:") \( - 20 wide (((#$lessons) - (#$failures)) / (#$lessons)) progress bar - ) + \(bold "Your progress:") \(20 wide ((#$lessons - #$failures) / #$lessons) progress bar) ") ..else: say - say (((#$lessons) - (#$failures)) / (#$lessons) progress bar) - + say ((#$lessons - #$failures) / #$lessons progress bar) + repeat until ($failures is empty): show first failure from $failures - # Have the user fix the first failure: + ### Have the user fix the first failure: unless $EDITOR: - # If the user is using an external editor, wait for the file to change + ### If the user is using an external editor, wait for the file to change $filename = (filename of $failures.1.lesson_number) say (" \(yellow "Waiting for you to fix ")\(bold $filename) \ @@ -460,10 +456,10 @@ command line program with $args: ") try: - $files = [: for $ in 1 to (#$lessons): add (read file (filename of $))] + $files = [: for $ in (1 to #$lessons): add (read file (filename of $))] repeat: sleep for 0.5 seconds - $new_files = [: for $ in 1 to (#$lessons): add (read file (filename of $))] + $new_files = [: for $ in (1 to #$lessons): add (read file (filename of $))] if ($new_files != $files): $files = $new_files stop @@ -471,13 +467,14 @@ command line program with $args: say "\nGoodbye." exit ..else: - # If the user is using $EDITOR, launch it so they can edit the file: + ### If the user is using $EDITOR, launch it so they can edit the file: $filename = (filename of $failures.1.lesson_number) --- (retry file) --- when (ask "Edit \$filename to get it to pass? [Y/n/exit] ") is: "q" "quit" "exit" "n" "N" "no": exit "c": write "# cheater!\n" to file $filename + "y" "Y" "yes" "": $f = (read file $filename) [$line, $col] = ($failures.1.failure, match ":(%d+),(%d+)") @@ -500,6 +497,7 @@ command line program with $args: else: say "Sorry, I don't understand that." go to (retry file) + try: run lesson $failures.1.lesson_number ..if it fails with $msg: @@ -509,29 +507,31 @@ command line program with $args: say ($msg, indented) say go to (retry file) - $prev_progress = (((#$lessons) - (#$failures)) / (#$lessons)) + $prev_progress = ((#$lessons - #$failures) / #$lessons) $failures = (get failures) - $progress = (((#$lessons) - (#$failures)) / (#$lessons)) + $progress = ((#$lessons - #$failures) / #$lessons) - # Update the progressbar if progess has changed: + ### Update the progressbar if progess has changed: if ($progress != $prev_progress): if ($progress > $prev_progress): say (bold (green "\nSuccess!\n")) ..else: say (bold (red "\nUh oh, that broke something.\n")) + if $(COLOR ENABLED): $N = 100 - for $ in 0 to $N: + for $ in (0 to $N): $k = (($ / $N) smoothed by 2) $p = ($prev_progress to $progress mixed by $k) say "\r\(bold "Your progress:") \(20 wide $p progress bar)" inline $io.flush() sleep for (1 / $N) seconds ..else: - say (((#$lessons) - (#$failures)) / (#$lessons) progress bar) + say ((#$lessons - #$failures) / #$lessons progress bar) + say - # All done, no more failures: + ### All done, no more failures: say (" \(bold "\(slow blink "Congratulations!")") diff --git a/lib/tools/uninstall.nom b/lib/tools/uninstall.nom index 90a8477..f5dbaa3 100755 --- a/lib/tools/uninstall.nom +++ b/lib/tools/uninstall.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V6 -# +#!/usr/bin/env nomsu -V7.0.0 + +### A tool to uninstall third party Nomsu packages (the inverse of the install tool) Usage: @@ -23,16 +24,16 @@ use "shell" command line program with $args: $searchpath = - [ - : for $ in ["?.lua", "?/init.lua", "?.nom", "?/init.nom"]: + [: + for $ in ["?.lua", "?/init.lua", "?.nom", "?/init.nom"]: add "\$(NOMSU PACKAGEPATH)\$" ], joined with ";" - + for $package_name in $args.extras: $path = ($package.searchpath $package_name $package.nomsupath "/") unless $path: say "Sorry, couldn't find \$package_name in \$(NOMSU PACKAGEPATH)" exit 1 $path = ($path, with "/init%.nom" -> "") - unless ((ask "Do you want to delete \$path? [Y/n] ") == "n"): - run command "rm -rv \$path" + unless ((ask "Do you want to delete \($path)? [Y/n] ") == "n"): + run command "rm -rv \$path" \ No newline at end of file diff --git a/lib/tools/upgrade.nom b/lib/tools/upgrade.nom index debce62..ae8c639 100755 --- a/lib/tools/upgrade.nom +++ b/lib/tools/upgrade.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V6.15.13.8 -# +#!/usr/bin/env nomsu -V7.0.0 + +### 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 @@ -27,7 +28,7 @@ command line program with $args: unless $file: fail "File does not exist: \$filename" $leading_indent = ($file, matching "\n*([ ]*)") - $code = (NomsuCode from (Source $filename 1 (#$file)) $file) + $code = (NomsuCode from (Source $filename 1 #$file) $file) $tree = ($code parsed $start_version) $uptree = $tree upgraded from ($start_version or ($tree.version or $(NOMSU VERSION))) to -- cgit v1.2.3