Auto-updated to 7.0.0 syntax and removed some shims.

This commit is contained in:
Bruce Hill 2019-03-20 15:55:57 -07:00
parent 606fd09000
commit e665d9725c
54 changed files with 763 additions and 704 deletions

View File

@ -1,38 +1,39 @@
#!/usr/bin/env nomsu -V6.15.13.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?
#!/usr/bin/env nomsu -V7.0.0
### How do I...
### Write a comment? Put a # and go till the end of the line
### How do I write a multi-line comment?
After a comment line, any indented text
is considered part of the comment
(including any deeper-level indented text)
The comment ends when the indentation ends
# How do I import a libarary?
### How do I import a libarary?
use "consolecolor"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# How do I print stuff?
### How do I print stuff?
say "Hello world!"
# How do I set a variable?
# Variables have "$" prefix:
### How do I set a variable?
### Variables have "$" prefix:
$foobar = 1
$text = "Hello world"
# Expressions that are more than just literal values require parentheses:
### Expressions that are more than just literal values require parentheses:
$foobar = (2 + 3)
$one_two = 12
say $one_two
# How do I modify a variable?
### How do I modify a variable?
$foobar = ($foobar + 1)
# Or, as a shorthand, you can do this to increment a variable:
### Or, as a shorthand, you can do this to increment a variable:
$foobar += 1
# How do I define a multi-line string?
# In Nomsu, the name "text" is used, rather than "string", and multi-line text looks like:
### How do I define a multi-line string?
### In Nomsu, the name "text" is used, rather than "string", and multi-line text looks like:
$multi_text = ("
Start with a quotation mark, then put indented lines below it. The indented
lines will not include the indentation, except when the lines are indented
@ -44,7 +45,7 @@ $multi_text = ("
indentation level.
")
# How do I put values inside text? (AKA string formatting, string interpolation)
### How do I put values inside text? (AKA string formatting, string interpolation)
say ("
Text can contain a backslash followed by a variable, list, dict, or parenthesized
expression. This escaped value will be converted to readable text, like so:
@ -67,40 +68,40 @@ say ("
")
say "Single-line text can contain escape sequences like \", \\, \000, and \n"
# How do I define a list?
### How do I define a list?
$my_list = ["first", "second", "third", 4]
# Really long lists can use [..] followed by a bunch of indented values delimited
### Really long lists can use [..] followed by a bunch of indented values delimited
by commas and/or newlines
$my_really_long_list = [
10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000
120000, 130000, 140000, 150000, 160000, 170000
]
# How do I use a list?
# Lists are 1-indexed because they're implemented as Lua tables, so this prints "first"
### How do I use a list?
### Lists are 1-indexed because they're implemented as Lua tables, so this prints "first"
say $my_list.1
# List entries can be modified like this:
### List entries can be modified like this:
$my_list.1 = "ONE!!!"
# Or appended to/removed from:
### Or appended to/removed from:
$my_list, add "extra item"
$my_list, pop
# How do I define a dictionary/hash map?
### How do I define a dictionary/hash map?
One-word text keys don't need quotes, otherwise the key is an expression.
If the expression is more complex than a literal, it needs parentheses:
$my_dict = {.x = 101, .y = 2, ."my value" = 99, .653 = 292, .(5 + 6) = 11}
# How do I use a dict?
# Dicts are also implemented as Lua tables, so they're accessed and modified the same way as lists
### How do I use a dict?
### Dicts are also implemented as Lua tables, so they're accessed and modified the same way as lists
say $my_dict.x
say $my_dict."how many bottles"
say $my_dict.653
$my_dict.x = 9999
# How do I do conditional branching?
### How do I do conditional branching?
if (1 < 10):
say "1 is indeed < 10"
@ -109,7 +110,7 @@ if (1 > 10):
..else:
say "this will print"
# There's no "elseif", so for longer conditionals, a "when" branch is the best option
### There's no "elseif", so for longer conditionals, a "when" branch is the best option
when:
(3 > 3):
say "this won't print"
@ -123,7 +124,7 @@ when:
else:
say "this is the default case"
# How do I do a switch statement?
### How do I do a switch statement?
if (1 + 2) is:
0 1:
say "this won't print"
@ -134,24 +135,24 @@ if (1 + 2) is:
else:
say "this won't print"
# How do I loop over a list (a foreach loop)?
### How do I loop over a list (a foreach loop)?
$list = [1, 2, 3]
for $x in $list:
say "For $x loop #\$x"
# How do I loop over a number range?
# This is inclusive, so it will loop over 1,2, and 3
for $i in 1 to 3:
### How do I loop over a number range?
### This is inclusive, so it will loop over 1,2, and 3
for $i in (1 to 3):
say "For $i in 1 to 3 loop #\$i"
# This will print 0,2, and 4
for $even in 0 to 5 by 2:
### This will print 0,2, and 4
for $even in (0 to 5 by 2):
say "Even #\$even"
for $backwards in 3 to 1 by -1:
for $backwards in (3 to 1 by -1):
say "Backwards #\$backwards"
# How do I do a 'while' loop?
### How do I do a 'while' loop?
$x = 1
repeat while ($x <= 3):
say "repeat while loop #\$x"
@ -161,14 +162,14 @@ repeat until ($x > 3):
say "repeat until loop #\$x"
$x += 1
# How do I do an infinite loop?
### How do I do an infinite loop?
$x = 1
repeat:
say "repeat loop #\$x"
$x += 1
if ($x > 3): stop
# How do I do a 'goto'?
### How do I do a 'goto'?
do:
$x = 1
--- (my loop) ---
@ -178,17 +179,17 @@ do:
go to (my loop)
say "finished going to"
# How do I define a function/method/procedure?
# In nomsu, they're called "action"s, and they can be declared like this:
### How do I define a function/method/procedure?
### In nomsu, they're called "action"s, and they can be declared like this:
(say both $first and also $second) means:
say $first
say $second
# Actions can have parts of the action's name spread throughout.
### Actions can have parts of the action's name spread throughout.
Everything that's not a literal value is treated as part of the action's name
say both "Hello" and also "world!"
# Actions can use "return" to return a value early
### Actions can use "return" to return a value early
(first fibonacci above $n) means:
$f1 = 0
$f2 = 1
@ -200,7 +201,7 @@ say both "Hello" and also "world!"
return $f2
say (first fibonacci above 10)
# Actions can have aliases, which may or may not have the arguments in different order
### Actions can have aliases, which may or may not have the arguments in different order
[
I hate $worse_things more than $better_things
I think $worse_things are worse than $better_things
@ -210,52 +211,54 @@ say (first fibonacci above 10)
I like "dogs" more than "cats"
I think "chihuahuas" are worse than "corgis"
# Actions can even start with a parameter
### Actions can even start with a parameter
($what_she_said is what she said) means:
say $what_she_said
say "-- she said"
"Howdy pardner" is what she said
# The language only reserves []{}().,:;$\ as special characters, so actions
### The language only reserves []{}().,:;$\ as special characters, so actions
and variables can use symbols freely:
(>> $(∐) @&' -->< $ @&_~-^ ⊗⊞√ $1 !) means:
say $(∐)
say $
say $1
>> "wow" @&' -->< "so flexible!" @&_~-^ ⊗⊞√ "even numbers can be variables!" !
# You can also use unicode in variable and action names:
>> "wow" @&' -->< "so flexible!" @&_~-^ ⊗⊞√
.."even numbers can be variables!" !
### You can also use unicode in variable and action names:
$こんにちは = "こんにちは"
($ と言う) means "\($)世界"
say ($こんにちは と言う)
# Math and logic operations are just treated the same as actions in the syntax
### Math and logic operations are just treated the same as actions in the syntax
say (2 + 3)
# So you can define your own operators, although they will need to be parenthesized to
### So you can define your own operators, although they will need to be parenthesized to
play nicely with other operators
($a ++ $b) means (2 * ($a + $b))
say (1 ++ (2 * 3))
# How do I do grouping?
# Expressions can be grouped by enclosing parentheses:
### How do I do grouping?
### Expressions can be grouped by enclosing parentheses:
say (2 + 3)
# Or by (..) followed by an indented region
### Or by (..) followed by an indented region
say (2 + 3)
# If you need to keep going after an indented region, you can start the next line with ".."
### If you need to keep going after an indented region, you can start the next line with ".."
say both "Very very very very long first argument that needs its own line"
..and also "short second arg"
(my favorite number) means (21 + 2)
# This can be nested:
### This can be nested:
say both (my favorite number) and also "foo"
# Object-oriented programming:
# How do I define a class?
### Object-oriented programming:
### How do I define a class?
(a Vec) is (a thing) with [$x, $y]:
($self, + $other) means (Vec ($x + $other.x) ($y + $other.y))
($self, +$other) means (Vec ($x + $other.x) ($y + $other.y))
($self, length) means (sqrt ($x * $x + $y * $y))
$(a Vec).is_a_vec = (yes)
(Vec $x $y) means (a Vec {.x = $x, .y = $y})
@ -263,21 +266,21 @@ $v1 = (Vec 1 2)
assume ($v1 + $v1) == (Vec 2 4)
say $v1
# Macros:
# The "lua>" and "=lua" macros can be used to write raw lua code:
### Macros:
### The "lua>" and "=lua" macros can be used to write raw lua code:
(say the time) means:
lua> "io.write(\"The OS time is: \", os.time(), \"\\n\");"
say the time
say "Math expression result is: \(=lua "(1 + 2*3 + 3*4)^2 % 5")"
# Variables can be accessed via \$var
### Variables can be accessed via \$var
(square root of $n) means (=lua "math.sqrt(\$n)")
say "The square root of 2 is \(square root of 2)"
# Macros can be defined to transform one bit of nomsu code into another using "parse $ as $":
### Macros can be defined to transform one bit of nomsu code into another using "parse $ as $":
(if $condition is untrue $body) parses as (if (not $condition) $body)
# Or to transform nomsu code into custom lua code using "compile $ to $"
### Or to transform nomsu code into custom lua code using "compile $ to $"
(debug only $body) compiles to:
if $DEBUG_ENABLED:
return
@ -289,15 +292,15 @@ say "The square root of 2 is \(square root of 2)"
return (Lua "-- (debug code removed for production)")
$DEBUG_ENABLED = (yes)
# Constants can be defined as macros
### Constants can be defined as macros
(TWENTY) parses as 20
# When they're invoked, they'll need parentheses just like a function call
### When they're invoked, they'll need parentheses just like a function call
(TWENTY ONE) parses as 21
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# If you need to use compile-time actions in the same file that they're defined in, you
### If you need to use compile-time actions in the same file that they're defined in, you
can add a line of tildes (3 or more), and the file will be split into chunks, and each
chunk will run before the next one compiles. (note that each chunk has its own scope)
if (1 > (TWENTY)) is untrue:
@ -307,8 +310,8 @@ if (1 > (TWENTY)) is untrue:
debug only:
say "Lua compiling macros work!"
# How do I use an action as a value?
# Well... it's always *possible* to fall back to Lua behavior for something like this:
### How do I use an action as a value?
### Well... it's always *possible* to fall back to Lua behavior for something like this:
(best of $items according to $key_fn) means:
[$best, $best_key] = [nil, nil]
for $item in $items:
@ -317,14 +320,14 @@ debug only:
[$best, $best_key] = [$item, $key]
return $best
# Function literals look like: $x -> ($x * $x)
### Function literals look like: $x -> ($x * $x)
say (best of [2, -3, 4, -8] according to ($x -> ($x * $x)))
# Or, you can surround an action with $(...) to refer to it:
### Or, you can surround an action with $(...) to refer to it:
($x squared) means ($x * $x)
say (best of [2, -3, 4, -8] according to $($ squared))
# However, nomsu was designed with flexible alternatives that are often better
### However, nomsu was designed with flexible alternatives that are often better
than passing functions. For example, instead of calling a key function on
every item, you could instead define a macro that will inline an expression
to produce faster code:
@ -341,7 +344,7 @@ say (best of [2, -3, 4, -8] according to $($ squared))
say (best of [2, -3, 4, -8] where $x has score ($x * $x))
# The line above expands to:
### The line above expands to:
say
result of:
[$best, $best_key] = [nil, nil]
@ -349,4 +352,4 @@ say
$key = ($x * $x)
if (($best == (nil)) or ($key > $best_key)):
[$best, $best_key] = [$x, $key]
return $best
return $best

View File

@ -1,16 +1,17 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines actions for encoding/decoding base 64, as specified in:
https://tools.ietf.org/html/rfc4648
$b64_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
$b64_chars = [: for $ in 1 to (#$b64_str): add ($b64_str, character $)]
$reverse_b64 = {: for $c in $b64_chars at $i: add $c = ($i - 1)}
$b64_chars = [: for $ in (1 to #$b64_str): add ($b64_str, character $)]
$reverse_b64 = {: for ($i = $c) in $b64_chars: add $c = ($i - 1)}
$reverse_b64."=" = 64
set $reverse_b64's metatable to {.__index = (-> 0)}
set $reverse_b64's metatable to {.__index = ->0}
test:
$cases = ["", "Zg==", "Zm8=", "Zm9v", "Zm9vYg==", "Zm9vYmE=", "Zm9vYmFy"]
for $len = $encoded in $cases:
for ($len = $encoded) in $cases:
$plain = ("foobar", from 1 to ($len - 1))
assume (base64 $plain) == $encoded
assume (base64 decode $encoded) == $plain
@ -18,10 +19,10 @@ test:
external:
[base64 $str, base64 encode $str, $str base64] all mean:
$chars = []
for $i in 1 to (#$str) via 3:
for $i in (1 to #$str by 3):
$bytes = [=lua "\$str:byte(\$i, \($i + 2))"]
$chars, add $b64_chars.((($bytes.1 & 252) >> 2) + 1)
if (#$bytes) is:
if #$bytes is:
3:
$chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1)
$chars, add $b64_chars.((($bytes.2 & 15) << 2) + (($bytes.3 & 192) >> 6) + 1)
@ -40,8 +41,8 @@ external:
(chr $) means (=lua "string.char(\$)")
[decode base64 $str, $str base64 decoded, base64 decode $str] all mean:
$chars = []
for $i in 1 to (#$str) via 4:
$indices = [: for $j in $i to ($i + 3): add $reverse_b64.($str, character $j)]
for $i in (1 to #$str by 4):
$indices = [: for $j in ($i to ($i + 3)): add $reverse_b64.($str, character $j)]
$chars, add (chr (($indices.1 << 2) + (($indices.2 & 48) >> 4)))
if (($str, character ($i + 2)) == "="): stop
$chars, add (chr ((($indices.2 & 15) << 4) + (($indices.3 & 60) >> 2)))

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6
#
#!/usr/bin/env nomsu -V7.0.0
###
A library defining some command line program functionality
external:
@ -10,4 +11,4 @@ external:
(usage $) means:
say "Usage: \$"
exit 1
exit 1

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <2.3 to Nomsu 2.3
use "compatibility/compatibility"
@ -7,7 +8,7 @@ use "compatibility/compatibility"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
upgrade action ($a = $b) to "2.3" as ($a == $b)
upgrade action (<- $) to "2.3" as (set $)
upgrade action <-$ to "2.3" as (set $)
upgrade action (assign $) to "2.3" as (set $)
upgrade action ($a <- $b) to "2.3" as ($a = $b)
upgrade action (external $a <- $b) to "2.3" as (external $a = $b)
@ -17,4 +18,4 @@ upgrade action ($a *<- $b) to "2.3" as ($a *= $b)
upgrade action ($a /<- $b) to "2.3" as ($a /= $b)
upgrade action ($a ^<- $b) to "2.3" as ($a ^= $b)
upgrade action ($a and<- $b) to "2.3" as ($a and= $b)
upgrade action ($a or<- $b) to "2.3" as ($a or= $b)
upgrade action ($a or<- $b) to "2.3" as ($a or= $b)

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <2.4 to Nomsu 2.4
use "compatibility/compatibility"
@ -10,7 +11,7 @@ upgrade $tree to "2.4" as:
unless ($tree is "Action" syntax tree): return
if $tree.stub is:
"when" "if":
if ((#$tree) == 3):
if (#$tree == 3):
return $tree
$conditions = []
$new_lines = []
@ -23,13 +24,13 @@ upgrade $tree to "2.4" as:
$new_lines, add $line
($line.stub == "*"):
if ((#$line) == 2):
if (#$line == 2):
$conditions, add $line.2
..else:
$new_lines, add $line
($line.stub == "* else"):
$new_lines, add (\(else $block) with vars {.block = $line.3})
$new_lines, add ("Action" tree with "else" $line.3)
else:
$conditions, add $line.2
@ -44,10 +45,8 @@ upgrade $tree to "2.4" as:
$conditions = []
return
\(when $body) with vars {
.body =
=lua "SyntaxTree{type='Block', source=\$tree[2].source, unpack(\$new_lines)}"
}
"Action" tree with "when"
"Block" tree from $tree.2.source with (unpack $new_lines)
"if 1 is ?" "if 1 = ?":
$values = []
@ -61,26 +60,24 @@ upgrade $tree to "2.4" as:
$new_lines, add $line
($line.stub == "*"):
if ((#$line) == 2):
if (#$line == 2):
$values, add $line.2
..else:
$new_lines, add $line
($line.stub == "* else"):
$new_lines, add (\(else $block) with vars {.block = $line.3})
$new_lines, add ("Action" tree with "else" $line.3)
else:
$values, add $line.2
$action = $line.3
unless ($action is "Block" syntax tree): $action = \(: $action)
unless ($action is "Block" syntax tree):
$action = ("Block" tree with $action)
$values, add $action
$new_lines, add
=lua "SyntaxTree{type='Action', source=\$values[1].source, unpack(\$values)}"
$values = []
return
\(if $var is $body) with vars {
.var = ($tree.2 upgraded)
.body =
=lua "SyntaxTree{type='Block', source=\$tree[5].source, unpack(\$new_lines)}"
}
"Action" tree with "if" ($tree.2 upgraded) "is"
"Block" tree from $tree.5.source with (unpack $new_lines)

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <2.5.5.5 to Nomsu 2.5.5.5
use "compatibility/compatibility"
@ -14,4 +15,4 @@ upgrade action [hash $, sha1 $] to "2.5.5.5" as
upgrade action [file with hash $] to "2.5.5.5" as
file with hash
base64
=lua "\$:gsub('..', function(xx) return string.char(tonumber(xx, 16)) end)"
=lua "\$:gsub('..', function(xx) return string.char(tonumber(xx, 16)) end)"

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <2.5 to Nomsu 2.5
use "compatibility/compatibility"
@ -10,4 +11,4 @@ upgrade action (for $1 where $2 matches $3 $4) to "2.5" as
for $1 in $2 matching $3 $4
upgrade action ($1 for $2 where $3 matches $4) to "2.5" as
$1 for $2 in $3 matching $4
$1 for $2 in $3 matching $4

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu 1 to Nomsu 2
use "compatibility/compatibility"
@ -11,15 +12,13 @@ upgrade $tree to "2" as:
if ($tree.stub == "if 1 2 else"):
$true_body = ($tree.3 upgraded)
unless ($true_body is "Block" syntax tree):
$true_body = \(: $true_body)
$true_body = ("Block" tree with $true_body)
$false_body = ($tree.5 upgraded)
unless ($false_body is "Block" syntax tree):
$false_body = (=lua "Block(\$false_body.source, \$false_body)")
return
\(if $cond $true_body else $false_body) with vars {
.cond = ($tree.2 upgraded), .true_body = $true_body, .false_body = $false_body
}
"Action" tree with "if" ($tree.2 upgraded) $true_body "else" $false_body
$need_blocks = [
"if", "unless", "for 1 in", "for 1 = 2 in", "repeat while 1", "repeat 1 times"
@ -34,4 +33,4 @@ upgrade $tree to "2" as:
unless (($bits, last) is "Block" syntax tree):
$body = ($bits, last)
$bits.(#$bits) = (=lua "SyntaxTree{type='Block', source=\$body.source, \$body}")
return (=lua "SyntaxTree{type='Action', source=\$tree.source, unpack(\$bits)}")
return (=lua "SyntaxTree{type='Action', source=\$tree.source, unpack(\$bits)}")

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <3.5.5.6 to Nomsu 3.5.5.6
use "compatibility/compatibility"
@ -8,4 +9,4 @@ use "compatibility/compatibility"
upgrade action "traceback" to "3.5.5.6" via
for $tree:
at $tree fail "Upgrade error: 'traceback' has been deprecated."
at $tree fail "Upgrade error: 'traceback' has been deprecated."

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <3.6 to 3.6
use "compatibility/compatibility"
@ -28,4 +29,4 @@ upgrade action [add free vars $vars to $lua] to "3.6" as
$lua, add free vars $vars
upgrade action [remove free vars $vars from $lua] to "3.6" as
$lua, remove free vars $vars
$lua, remove free vars $vars

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <3.7 to 3.7
use "compatibility/compatibility"
@ -38,4 +39,4 @@ upgrade action [
upgrade action [
number of keys in $list, len $list, || $list ||, length $list, length of $list
] to "3.7" as (size of $list)
] to "3.7" as (size of $list)

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <3.8 to 3.8 (Text method changes)
use "compatibility/compatibility"
@ -20,4 +21,4 @@ upgrade action [
$text s/ $patt / $sub
] to "3.8" as ($text, with $patt -> $sub)
upgrade action [$text matches $pattern] to "3.8" as ($text, matches $pattern)
upgrade action [$text matching $pattern] to "3.8" as ($text, matching $pattern).1
upgrade action [$text matching $pattern] to "3.8" as ($text, matching $pattern).1

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <=2 to Nomsu 3
use "compatibility/compatibility"
@ -14,4 +15,4 @@ upgrade action "as" to "3" via
at $tree fail ("
Upgrade error: Object API has changed and 'as' is no longer supported.
Hint: Use ($obj, action ...) instead of (as $obj: action ...)
")
")

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <4.10.12.7 to 4.10.12.7
use "compatibility/compatibility"
@ -22,10 +23,8 @@ upgrade action ($e for $i in $start to $stop by $step) to "4.10.12.7" as
upgrade action ($e for $i in $start to $stop via $step) to "4.10.12.7" as
[: for $i in $start to $stop by $step: add $e]
upgrade action ($k = $v for $ in $items) to "4.10.12.7" as {
: for $ in $items:
add $k = $v
}
upgrade action ($k = $v for $ in $items) to "4.10.12.7" as
{: for $ in $items: add $k = $v}
upgrade action ($k = $v for $k0 = $v0 in $items) to "4.10.12.7" as
{: for $k0 = $v0 in $items: add $k = $v}
@ -40,13 +39,13 @@ upgrade action ($k = $v for $i in $start to $stop via $step) to "4.10.12.7" as
{: for $i in $start to $stop by $step: add $k = $v}
upgrade action (parse $text from $filename) to "4.10.12.7" as
(NomsuCode from (Source $filename 1 (#$text)) $text) parsed
(NomsuCode from (Source $filename 1 #$text) $text) parsed
upgrade action ($ as lua statements) to "4.10.12.7" as ($ as lua)
upgrade action (compile error at $pos $err hint $hint) to "4.10.12.7" as
compile error at $pos $err $hint
# In old code, it was okay to have imports at the top of the file in the same chunk,
### In old code, it was okay to have imports at the top of the file in the same chunk,
but changes to the API now require imports to be in their own file chunk in order
for compilation to work properly.
upgrade $tree to "4.10.12.7" as:
@ -54,7 +53,7 @@ upgrade $tree to "4.10.12.7" as:
$first_chunk = $tree.1
$i = 1
$has_use = (no)
repeat while ($i <= (#$first_chunk)):
repeat while ($i <= #$first_chunk):
if (($first_chunk.$i.type == "Action") and ($first_chunk.$i.stub == "use")):
$has_use = (yes)
..else:
@ -66,13 +65,13 @@ upgrade $tree to "4.10.12.7" as:
[$chunk1, $chunk2] =
["Block" tree from $first_chunk.source, "Block" tree from $first_chunk.source]
for $j in 1 to ($i - 1):
for $j in (1 to ($i - 1)):
$chunk1.$j = $first_chunk.$j
for $j in $i to (#$first_chunk):
for $j in ($i to #$first_chunk):
$chunk2.($j - $i + 1) = $first_chunk.$j
$new_tree = ("FileChunks" tree from $tree.source with $chunk1 $chunk2)
for $i in 2 to (#$tree):
for $i in (2 to #$tree):
$new_tree.($i + 1) = $tree.$i
return $new_tree
return $new_tree

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <4.11 to Nomsu 4.11
(overhaul of function literals, deleting (if all of ...), etc. shorthand)
@ -7,22 +8,22 @@ use "compatibility/compatibility"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Overhaul of function literals:
### Overhaul of function literals:
upgrade action "call 1 with" to "4.11" via
for ($tree $end_version):
$tree2 = {.type = "Action", .source = $tree.source, .1 = $tree.2}
for $arg in $tree.4 at $i:
for ($i = $arg) in $tree.4:
$tree2.($i + 1) = $arg
return (SyntaxTree $tree2)
upgrade action (-> $yield_value) to "4.11" as (yield $yield_value)
upgrade action ->$yield_value to "4.11" as (yield $yield_value)
# Replace set {$x:1, $y:2} with [$x, $y] = [1, 2]
### Replace set {$x:1, $y:2} with [$x, $y] = [1, 2]
upgrade action "set" to "4.11" via
for ($tree $end_version):
[$lhs, $rhs] = [\[], \[]]
[$lhs, $rhs] = [`[], `[]]
$lhs.source = $tree.2.source
$rhs.source = $tree.2.source
for $entry in $tree.2 at $i:
for ($i = $entry) in $tree.2:
$lhs.$i = $entry.1
$rhs.$i = $entry.2
return ("Action" tree from $tree.source with $lhs "=" $rhs)
@ -34,7 +35,7 @@ upgrade action "1 with 2 ~>" to "4.11" via
Hint: Perhaps this could be use ($tree, map ...) instead.
")
# Changing filesystem API:
### Changing filesystem API:
upgrade action (for file $f in $path $body) to "4.11" as
for $f in (files for $path) $body
@ -45,7 +46,7 @@ upgrade action (line $n in $text) to "4.11" as ($text, line $n)
upgrade action (line number of $pos in $text) to "4.11" as
$text, line number at $pos
# Deduplicating goto labels:
### Deduplicating goto labels:
upgrade action [=== $label ===, *** $label ***] to "4.11" as (--- $label ---)
upgrade action [===stop $label ===, ***stop $label ***] to "4.11" as
---stop $label ---
@ -53,7 +54,7 @@ upgrade action [===stop $label ===, ***stop $label ***] to "4.11" as
upgrade action [===next $label ===, ***next $label ***] to "4.11" as
---next $label ---
# Deprecating shorthand functions:
### Deprecating shorthand functions:
upgrade action [if all of $items $body, if all of $items then $body] to "4.11" as
if (all of $items) $body

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <4.11 to Nomsu 4.11
(overhaul of function literals, deleting (if all of ...), etc. shorthand)
@ -19,4 +20,4 @@ upgrade action "stop repeating" to "4.12" via
at $tree fail ("
Upgrade error: This method has been deprecated.
Hint: Use either (stop) or (go to (label)) instead.
")
")

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <4.8.10 to 4.8.10 (renaming "action" -> "means")
use "compatibility/compatibility"
@ -11,13 +12,13 @@ upgrade action "local action" to "4.8.10" via
$body = $tree.4
if $spec.type is:
"List":
if ((#$spec) == 1):
return \($spec.1 means $body)
if (#$spec == 1):
return ("Action" tree with $spec.1 "means" $body)
..else:
return \($spec all mean $body)
return ("Action" tree with $spec "all" "mean" $body)
else:
return \($spec means $body)
return ("Action" tree with $spec "means" $body)
upgrade action "action" to "4.8.10" via
for ($tree $end_version):
@ -26,15 +27,15 @@ upgrade action "action" to "4.8.10" via
if $body:
if $spec.type is:
"List":
if ((#$spec) == 1):
return \(externally $spec.1 means $body)
if (#$spec == 1):
return ("Action" tree with "externally" $spec.1 "means" $body)
..else:
return \(externally $spec all mean $body)
return ("Action" tree with "externally" $spec "all" "mean" $body)
else:
return \(externally $spec means $body)
return ("Action" tree with "externally" $spec "means" $body)
..else:
return \($spec's meaning)
return ("Action" tree with $spec "'" "s" "meaning")
upgrade action "compile 1 to" to "4.8.10" via
for ($tree $end_version):
@ -42,13 +43,13 @@ upgrade action "compile 1 to" to "4.8.10" via
$body = $tree.4
if $spec.type is:
"List":
if ((#$spec) == 1):
return \($spec.1 compiles to $body)
if (#$spec == 1):
return ("Action" tree with $spec.1 "compiles" "to" $body)
..else:
return \($spec all compile to $body)
return ("Action" tree with $spec "all" "compile" "to" $body)
else:
return \($spec compiles to $body)
return ("Action" tree with $spec "compiles" "to" $body)
upgrade action "parse 1 as" to "4.8.10" via
for ($tree $end_version):
@ -56,13 +57,13 @@ upgrade action "parse 1 as" to "4.8.10" via
$body = $tree.4
if $spec.type is:
"List":
if ((#$spec) == 1):
return \($spec.1 parses as $body)
if (#$spec == 1):
return ("Action" tree with $spec.1 "parses" "as" $body)
..else:
return \($spec all parse as $body)
return ("Action" tree with $spec "all" "parse" "as" $body)
else:
return \($spec parse as $body)
return ("Action" tree with $spec "parse" "as" $body)
upgrade action (compile as $) to "4.8.10" as (what $ compiles to)
upgrade action (remove action $) to "4.8.10" as (($'s meaning) = (nil))

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <4.9 to 4.9
use "compatibility/compatibility"
@ -7,6 +8,6 @@ use "compatibility/compatibility"
upgrade action "if" to "4.9" via
for ($tree $end_version):
if ((#$tree) > 2):
if (#$tree > 2):
return $tree
return \(when $tree.2)
return ("Action" tree with "when" $tree.2)

View File

@ -1,20 +1,22 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <5.13 to 5.13
use "compatibility/compatibility"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
upgrade action (size of $) to "5.13" as (#$)
upgrade action (size of $) to "5.13" as #$
upgrade action "with" to "5.13" via
for $tree:
$assignments = $tree.2
$body = $tree.3
if ($assignments.type != "Dict"): return $tree
$new_assignments = \[]
for $a in $assignments at $i:
$new_assignments = `[]
for ($i = $a) in $assignments:
when:
(($a.type == "DictEntry") and ((#$a) == 1)): $a = $a.1
(all of [$a.type == "DictEntry", (#$a) == 2]): $a = \($a.1 = $a.2)
(($a.type == "DictEntry") and (#$a == 1)): $a = $a.1
(all of [$a.type == "DictEntry", #$a == 2]):
$a = ("Action" tree with $a.1 "=" $a.2)
$new_assignments.$i = $a
return \(with $new_assignments $body)
return ("Action" tree with "with" $new_assignments $body)

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <6.14 to 6.14
use "compatibility/compatibility"
@ -27,7 +28,7 @@ upgrade action (assume $assumption or barf $err) to "6.14" as
unless $assumption: fail $err
upgrade action (barf $msg) to "6.14" as (fail $msg)
upgrade action (\(1's meaning)).stub to "6.14" via
upgrade action ("Action" tree with 1 "'" "s" "meaning").stub to "6.14" via
$tree -> ("Var" tree from $tree.source with $tree.1)
upgrade action (log base $b of $n) to "6.14" as (log $n base $b)
upgrade action "use" to "6.14" via
@ -35,4 +36,4 @@ upgrade action "use" to "6.14" via
$path = $tree.2.1
$path = ($path, with "%.nom$" -> "")
$path = ($path, with "^lib/" -> "")
return \(use ("Text" tree from $tree.2.source with $path))
return ("Action" tree with "use" ("Text" tree from $tree.2.source with $path))

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.9
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <6.15.9 to 6.15.9
use "compatibility/compatibility"

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <6.15 to 6.15
use "compatibility/compatibility"
@ -11,8 +12,8 @@ upgrade action (externally $x means $y) to "6.15" as (external ($x means $y))
upgrade action (externally $x all mean $y) to "6.15" as
external ($x all mean $y)
upgrade action ($lists flattened) to "6.15" as [
: for $ in recursive $lists:
upgrade action ($lists flattened) to "6.15" as [:
for $ in recursive $lists:
if ($ is "a List"):
for $child in $:
recurse $ on $child
@ -29,4 +30,4 @@ upgrade action ($x is $y) to "6.15" as ($x == $y)
upgrade action [$a isn't $b, $a is not $b, $a not= $b] to "6.15" as ($a != $b)
upgrade action [$a is a $b, $a is an $b] to "6.15" as ($a is $b)
upgrade action [$a isn't a $b, $a isn't an $b, $a is not a $b, $a is not an $b]
..to "6.15" as ($a isn't $b)
..to "6.15" as ($a isn't $b)

View File

@ -1,4 +1,5 @@
#!/usr/bin/env nomsu -V7
#!/usr/bin/env nomsu -V7.0.0
###
This file defines upgrades from Nomsu <7 to 7
@ -33,10 +34,15 @@ upgrade action (for $var in $start to $stop $body) to "7" as
upgrade $tree to "7" as:
if ($tree.type == "EscapedNomsu"):
$t =
"Action" tree from $tree.source with ("Text" tree with $tree.1.type) "tree" "with"
"Action" tree from $tree.source with ("Text" tree with $tree.1.type) "tree"
"with"
for $tok in $tree.1:
if ($tok is "Text"): $t, add ("Text" tree with $tok)
..else: $t, add $tok
if ($tok is "Text"):
$t, add ("Text" tree with $tok)
..else:
$t, add $tok
return $t
upgrade action "Nomsu version" to "7" via ->(`$(NOMSU VERSION))
@ -47,4 +53,4 @@ upgrade action [
at $.source fail ("
Deprecation error: Actions for accessing specific parts of the version number have been deprecated.
Hint: Use $(NOMSU VERSION).1, etc. instead.
")
")

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file contains code for defining ways to upgrade code between different versions
of Nomsu.
@ -21,13 +22,13 @@ external:
(upgrade action $actions to $version as $body) compiles to:
if ($actions is "Action" syntax tree):
$actions = \[$actions]
$actions = ("List" tree with $actions)
$lua = (Lua "")
for $action in $actions:
$replacements = {}
for $i in 1 to (#$action):
for $i in (1 to #$action):
if ($action.$i is "Var" syntax tree):
$replacements.($action.$i.1) = "\(\$tree as lua id)[\$i]"
$replacements.($action.$i.1) = "\(`$tree as lua id)[\$i]"
define mangler
(make tree $t) means:
when:
@ -42,7 +43,7 @@ external:
($t is syntax tree):
$args = []
for $k = $v in $t:
for ($k = $v) in $t:
if ((type of $k) == "a Number"):
$args, add (make tree $v)
..else:
@ -59,7 +60,7 @@ external:
$lua, add
Lua ("
upgrade_action_1_to_2_via(\(quote $action.stub), \($version as lua expr), function(\
..\(\$tree as lua id))
..\(`$tree as lua id))
return \$retval
end)
")
@ -91,13 +92,15 @@ external:
assume $start.lib == $end.lib
$seen = {}
$versions = {}
for $v = $ in $UPGRADES:
for ($v = $) in $UPGRADES:
$versions.$v = (yes)
for $v = $ in $ACTION_UPGRADES:
for ($v = $) in $ACTION_UPGRADES:
$versions.$v = (yes)
$versions = [: for $v = $ in $versions: if ((Ver $v).lib == $start.lib): add $v]
$versions =
[: for ($v = $) in $versions: if ((Ver $v).lib == $start.lib): add $v]
sort $versions by $ -> ($ as version list)
for $ver in $versions:
if (($ver as version list) <= $start.version): do next $ver
@ -109,23 +112,20 @@ external:
if ($ is "Action" syntax tree):
$(upgrade 1 to 2) = $ACTION_UPGRADES.$ver.($.stub)
if $(upgrade 1 to 2):
$with_upgraded_args = {
: for $k = $v in $:
add $k = ($v upgraded from $start_version to $end_version)
}
$with_upgraded_args = {: for ($k = $v) in $: add $k = ($v upgraded from $start_version to $end_version)}
set $with_upgraded_args's metatable to ($'s metatable)
return (upgrade $with_upgraded_args to $end_version)
if $UPGRADES.$ver:
$with_upgraded_args = {
: for $k = $v in $tree:
$with_upgraded_args = {:
for ($k = $v) in $tree:
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 = (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"
@ -139,4 +139,4 @@ external:
$tree upgraded from ($tree.version or $(NOMSU VERSION)) to $end_version
($tree upgraded) means
$tree upgraded from ($tree.version or $(NOMSU VERSION)) to $(NOMSU VERSION)
$tree upgraded from ($tree.version or $(NOMSU VERSION)) to $(NOMSU VERSION)

View File

@ -1,4 +1,5 @@
#!/usr/bin/env nomsu -V6.15.13.8
#!/usr/bin/env nomsu -V7.0.0
export "compatibility/compatibility"
export "compatibility/2"
export "compatibility/2.3"
@ -19,4 +20,4 @@ export "compatibility/5.13"
export "compatibility/6.14"
export "compatibility/6.15"
export "compatibility/6.15.9"
export "compatibility/7"
export "compatibility/7"

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines actions for ANSI console color escape codes.
test:
@ -9,20 +10,21 @@ $colors = {
.normal = 0, ."reset color" = 0, .bright = 1, .bold = 1, .dim = 2, .italic = 3
.underscore = 4, ."slow blink" = 5, ."fast blink" = 6, .reverse = 7, .inverse = 7
.inverted = 7, .hidden = 8
# There's some other codes, but they're not currently implemented
### There's some other codes, but they're not currently implemented
.black = 30, .red = 31, .green = 32, .yellow = 33, .blue = 34, .magenta = 35
.cyan = 36, .white = 37, ."on black" = 40, ."on red" = 41, ."on green" = 42
."on yellow" = 43, ."on blue" = 44, ."on magenta" = 45, ."on cyan" = 46
."on white" = 47
}
for $name = $colornum in $colors:
for ($name = $colornum) in $colors:
(nomsu environment).($name, as lua id) =
for $text:
if $(COLOR ENABLED):
if $text:
return "\x1B[\($colornum)m\$text\x1b[0m"
return "\027[\($colornum)m\($text)\027[0m"
..else:
return "\x1B[\($colornum)m"
return "\027[\($colornum)m"
..else:
return ($text or "")
return ($text or "")

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file contains code that supports manipulating and using collections like lists
and dictionaries.
@ -9,11 +10,11 @@ use "core/operators"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# List functionality:
### List functionality:
test:
$list = [1, 2, 3, 4, 5]
$visited = {}
for $i = $x in $list:
for ($i = $x) in $list:
$visited.$i = (yes)
assume ($visited == {.1, .2, .3, .4, .5})
$visited = {}
@ -24,7 +25,7 @@ test:
assume (($list, first) == 1)
assume ($list, has 3)
assume (($list, index of 3) == 3)
assume ((#$list) == 5)
assume (#$list == 5)
$list, add 6
assume (($list, last) == 6)
$list, pop
@ -33,11 +34,11 @@ test:
assume (($list, first) == 2)
assume (([1, 2] + [3, 4]) == [1, 2, 3, 4])
# Dict functionality
### Dict functionality
test:
$dict = {.x = 1, .y = 2, .z = 3}
assume (#$dict) == 3
assume [: for $k = $v in {.x = 1}: add {.key = $k, .value = $v}] ==
assume #$dict == 3
assume [: for ($k = $v) in {.x = 1}: add {.key = $k, .value = $v}] ==
[{.key = "x", .value = 1}]
assume ({.x = 1, .y = 1} + {.y = 10, .z = 10}) == {.x = 1, .y = 11, .z = 10}
assume ({.x = 1, .y = 1} - {.y = 10, .z = 10}) == {.x = 1, .y = -9, .z = -10}
@ -45,54 +46,54 @@ test:
assume ({.x = 1, .y = 1} & {.y = 10, .z = 10}) == {.y = 1}
assume ({.x = 1, .y = 1} ~ {.y = 10, .z = 10}) == {.x = 1, .z = 10}
# Set compliments:
### Set compliments:
assume (~{.x}).y
assume ((~{.x}).x == (nil))
$sc = (~{.x, .y})
$sc = ~{.x, .y}
$sc.y = 99
# For now, whether $sc.y == 99 or $sc.y == (yes) is unspecified,
### For now, whether $sc.y == 99 or $sc.y == (yes) is unspecified,
(but the actual behavior is (yes))
assume ($sc.y and (not $sc.x))
assume ($sc == ((~{.x, .y}) | {.y = 99}))
assume ($sc == (~{.x, .y} | {.y = 99}))
# Both sets:
### Both sets:
assume (({.x, .y} & {.y, .z}) == {.y})
assume (({.x, .y} | {.y, .z}) == {.x, .y, .z})
assume (({.x, .y} ~ {.y, .z}) == {.z, .x})
# Mixed:
assume (({.x, .y} & (~{.y, .z})) == {.x})
assume (({.x, .y} | (~{.y, .z})) == (~{.z}))
assume (({.x, .y} ~ (~{.y, .z})) == (~{.x}))
### Mixed:
assume (({.x, .y} & ~{.y, .z}) == {.x})
assume (({.x, .y} | ~{.y, .z}) == ~{.z})
assume (({.x, .y} ~ ~{.y, .z}) == ~{.x})
# Mixed reversed:
assume (((~{.y, .z}) & {.x, .y}) == {.x})
assume (((~{.y, .z}) | {.x, .y}) == (~{.z}))
assume (((~{.y, .z}) ~ {.x, .y}) == (~{.x}))
### Mixed reversed:
assume ((~{.y, .z} & {.x, .y}) == {.x})
assume ((~{.y, .z} | {.x, .y}) == ~{.z})
assume ((~{.y, .z} ~ {.x, .y}) == ~{.x})
# Both set compliments:
assume (((~{.x, .y}) & (~{.y, .z})) == (~{.x, .y, .z}))
assume (((~{.x, .y}) | (~{.y, .z})) == (~{.y}))
assume (((~{.x, .y}) ~ (~{.y, .z})) == {.x, .z})
### Both set compliments:
assume ((~{.x, .y} & ~{.y, .z}) == ~{.x, .y, .z})
assume ((~{.x, .y} | ~{.y, .z}) == ~{.y})
assume ((~{.x, .y} ~ ~{.y, .z}) == {.x, .z})
test:
assume ((entries in {.x = 1}) == [{.key = "x", .value = 1}])
(entries in $dict) parses as [
: for $k = $v in $dict:
add {.key = $k, .value = $v}
]
(entries in $dict) parses as
[: for ($k = $v) in $dict: add {.key = $k, .value = $v}]
test:
assume ((keys in {.x = 1}) == ["x"])
[keys in $dict, keys of $dict] all parse as [: for $k = $v in $dict: add $k]
[keys in $dict, keys of $dict] all parse as [: for ($k = $v) in $dict: add $k]
test:
assume ((values in {.x = 1}) == [1])
[values in $dict, values of $dict] all parse as [: for $k = $v in $dict: add $v]
# Metatable stuff
[values in $dict, values of $dict] all parse as
[: for ($k = $v) in $dict: add $v]
### Metatable stuff
test:
$t = {}
set $t's metatable to {.__tostring = ($ -> "XXX")}
@ -118,12 +119,12 @@ test:
end)(\($dict as lua expr))
")
# Sorting
### Sorting
test:
$x = [3, 1, 2]
sort $x
assume ($x == [1, 2, 3])
sort $x by $ = (- $)
sort $x by $ = -$
assume ($x == [3, 2, 1])
$keys = {.1 = 999, .2 = 0, .3 = 50}
sort $x by $ = $keys.$
@ -164,13 +165,13 @@ external:
$seen.$ = (yes)
return $unique
# Ranges:
### Ranges:
test:
$r = (3 to 5)
assume ($r.2 == 4)
assume ($r is "a Range")
assume ((1 to 10, backwards) == (10 to 1 by -1))
assume ((#(1 to 10 by 2)) == 5)
assume (#(1 to 10 by 2) == 5)
$visited = []
for $ in (1 to 10 by 2):
$visited, add $
@ -211,7 +212,7 @@ $range_mt = {
($self.first == $other.first) and
($self.last == $other.last) and ($self.step == $other.step)
.backwards = (for $self ($self.last to $self.first by (- $self.step)))
.backwards = (for $self ($self.last to $self.first by -$self.step))
.__inext = $(inext), .__next = $(inext)
.as_text =
for $self:
@ -231,4 +232,4 @@ external:
setmetatable {.first = $first, .last = $last, .step = $step} $range_mt
($first to $last) means
setmetatable {.first = $first, .last = $last, .step = 1} $range_mt
setmetatable {.first = $first, .last = $last, .step = 1} $range_mt

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file contains compile-time actions that define basic control flow structures
like "if" statements and loops.
@ -8,12 +9,12 @@ use "core/operators"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# No-Op
### No-Op
test:
do nothing
(do nothing) compiles to ""
# Conditionals
### Conditionals
test:
if (no):
fail "conditional fail"
@ -48,8 +49,8 @@ test:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Conditional expression (ternary operator)
# Note: this uses a function instead of "(condition and if_expr or else_expr)"
### Conditional expression (ternary operator)
### Note: this uses a function instead of "(condition and if_expr or else_expr)"
because that breaks if $if_expr is falsey, e.g. "x < 5 and false or 99"
test:
assume ((1 if (yes) else 2) == 1)
@ -61,7 +62,7 @@ test:
$when_false_expr unless $condition else $when_true_expr
$when_false_expr unless $condition then $when_true_expr
] all compile to:
# If $when_true_expr is guaranteed to be truthy, we can use Lua's idiomatic
### If $when_true_expr is guaranteed to be truthy, we can use Lua's idiomatic
equivalent of a conditional expression: (cond and if_true or if_false)
if {.Text, .List, .Dict, .Number}.($when_true_expr.type):
return Lua ("
@ -69,7 +70,7 @@ test:
..\($when_false_expr as lua expr))
")
..else:
# Otherwise, need to do an anonymous inline function (yuck, too bad lua
### Otherwise, need to do an anonymous inline function (yuck, too bad lua
doesn't have a proper ternary operator!)
To see why this is necessary consider: (random()<.5 and false or 99)
return Lua ("
@ -84,7 +85,7 @@ test:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# GOTOs
### GOTOs
test:
$i = 0
--- $loop ---
@ -112,7 +113,7 @@ test:
)
")
# Basic loop control
### Basic loop control
(stop $var) compiles to:
if $var:
return Lua "goto stop_\($var as lua identifier)"
@ -128,7 +129,7 @@ test:
(---stop $var ---) compiles to "::stop_\($var as lua identifier)::"
(---next $var ---) compiles to "::continue_\($var as lua identifier)::"
# While loops
### While loops
test:
$x = 0
repeat while ($x < 10): $x += 1
@ -149,7 +150,7 @@ test:
\($body as lua)
")
if ($body has subtree \(do next)):
if ($body, contains `(do next)):
$lua, add "\n ::continue::"
$lua, add "\nend --while-loop"
@ -160,12 +161,12 @@ test:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# For-each loop (lua's "ipairs()")
### For-each loop (lua's "ipairs()")
(for $var in $iterable $body) compiles to:
unless $var:
at (this tree) fail "No var here"
# This uses Lua's approach of only allowing loop-scoped variables in a loop
### This uses Lua's approach of only allowing loop-scoped variables in a loop
if (($var.type == "Action") and ($var.stub == "1 =")):
[$key, $value] = [$var.1, $var.3]
..else:
@ -174,7 +175,7 @@ test:
unless $value:
at (this tree) fail "No value here"
# Numeric loop:
### Numeric loop:
if (($iterable.type == "Action") and (($iterable, get stub) == "1 to")):
[$start, $stop] = [$iterable.1, $iterable.3]
$loop =
@ -191,7 +192,7 @@ test:
go to (loop set)
# Numeric loop with step:
### Numeric loop with step:
if (($iterable.type == "Action") and (($iterable, get stub) == "1 to 2 by")):
[$start, $stop, $step] = [$iterable.1, $iterable.3, $iterable.5]
$loop =
@ -208,21 +209,19 @@ test:
go to (loop set)
# for $ in (...):
### for $ in (...):
if $key:
$loop =
Lua ("
for \($key as lua identifier),\($value as lua identifier) in pairs(\($iterable as lua expr)) do
for \($key as lua identifier),\($value as lua identifier) in pairs(\
..\($iterable as lua expr)) do
")
..else:
$loop =
Lua ("
for _i,\($value as lua identifier) in _ipairs(\($iterable as lua expr)) do
")
Lua "for _i,\($value as lua identifier) in _ipairs(\($iterable as lua expr)) do"
--- (loop set) ---
# TODO: don't always wrap in block
### TODO: don't always wrap in block
$lua =
Lua ("
do -- for-loop
@ -230,37 +229,31 @@ test:
\;
")
$lua, add ($body as lua)
if ($body has subtree \(do next)):
if ($body, contains `(do next)):
$lua, add "\n ::continue::"
if ($key and ($body has subtree \(do next $key))):
$lua, add "\n " (\(---next $key ---) as lua)
if ($key and ($body, contains ("Action" tree with "do" "next" $key))):
$lua, add "\n " (("Action" tree with "---" "next" $key "---") as lua)
if ($body has subtree \(do next $value)):
$lua, add "\n " (\(---next $value ---) as lua)
if ($body, contains ("Action" tree with "do" "next" $value)):
$lua, add "\n " (("Action" tree with "---" "next" $value "---") as lua)
$lua, add "\n end"
if ($key and ($body has subtree \(stop $key))):
$lua, add "\n " (\(---stop $key ---) as lua)
if ($key and ($body, contains ("Action" tree with "stop" $key))):
$lua, add "\n " (("Action" tree with "---" "stop" $key "---") as lua)
if ($body has subtree \(stop $value)):
$lua, add "\n " (\(---stop $value ---) as lua)
if ($body, contains ("Action" tree with "stop" $value)):
$lua, add "\n " (("Action" tree with "---" "stop" $value "---") as lua)
$lua, add "\nend -- for-loop"
$lua, remove free vars [($value as lua identifier, text), $key and ($key as lua identifier, text)]
$lua, remove free vars
[($value as lua identifier, text), $key and ($key as lua identifier, text)]
return $lua
# TODO: remove these shims:
(for $var in $iterable at $i $body) parses as
for ($i = $var) in $iterable $body
(for $k = $v in $iterable $body) parses as
for ($k = $v) in $iterable $body
test:
$d = {.a = 10, .b = 20, .c = 30, .d = 40, .e = 50}
$result = []
for $k = $v in $d:
for ($k = $v) in $d:
if ($k == "a"):
do next $k
@ -270,7 +263,7 @@ test:
$result, add "\$k = \$v"
assume (($result sorted) == ["c = 30", "d = 40", "e = 50"])
# Numeric range for loops
### Numeric range for loops
test:
assume ([: for $ in (1 to 5): add $] == [1, 2, 3, 4, 5])
assume ([: for $ in (1 to 5 by 2): add $] == [1, 3, 5])
@ -286,16 +279,7 @@ test:
stop $outer
assume ($nums == [1, -2, 3, -2, 3, 4, 3, 4, 5])
# TODO: These are shims, and should be phased out:
[
for $var in $start to $stop by $step $body
for $var in $start to $stop via $step $body
] all parse as (for $var in ($start to $stop by $step) $body)
(for $var in $start to $stop $body) parses as
for $var in ($start to $stop) $body
# repeat $n times is a shorthand:
### repeat $n times is a shorthand:
test:
$x = 0
repeat 5 times:
@ -319,7 +303,7 @@ test:
else:
fail "bad conditional"
# Multi-branch conditional (if..elseif..else)
### Multi-branch conditional (if..elseif..else)
(when $body) compiles to:
$code = (Lua "")
$clause = "if"
@ -332,7 +316,7 @@ test:
for $line in $body:
unless
(($line.type == "Action") and ((#$line) >= 2)) and
(($line.type == "Action") and (#$line >= 2)) and
$line.(#$line) is "Block" syntax tree
..:
at $line fail ("
@ -341,14 +325,14 @@ test:
..or "else" followed by a block.
")
$action = $line.(#$line)
if (($line.1 == "else") and ((#$line) == 2)):
if (($line.1 == "else") and (#$line == 2)):
unless $else_allowed:
at $line fail ("
Compile error: You can't have two 'else' blocks.
Hint: Merge all of the 'else' blocks together.
")
unless ((#"\$code") > 0):
unless (#"\$code" > 0):
at $line fail ("
Compile error: You can't have an 'else' block without a preceding condition.
Hint: If you want the code in this block to always execute, you don't need a conditional \
@ -359,14 +343,14 @@ test:
$else_allowed = (no)
..else:
$code, add $clause " "
for $i in 1 to ((#$line) - 1):
for $i in (1 to (#$line - 1)):
if ($i > 1):
$code, add " or "
$code, add ($line.$i as lua expr)
$code, add " then\n " ($action as lua)
$clause = "\nelseif"
if ((#"\$code") == 0):
if (#"\$code" == 0):
at $body fail ("
Compile error: 'if' block has an empty body.
Hint: This means nothing would happen, so the 'if' block should be deleted.
@ -389,7 +373,7 @@ test:
else:
fail "bad switch statement"
# Switch statement
### Switch statement
[if $branch_value is $body, when $branch_value is $body] all compile to:
$code = (Lua "")
$clause = "if"
@ -403,7 +387,7 @@ test:
for $line in $body:
unless
(($line.type == "Action") and ((#$line) >= 2)) and
(($line.type == "Action") and (#$line >= 2)) and
$line.(#$line) is "Block" syntax tree
..:
at $line fail ("
@ -411,14 +395,14 @@ test:
Hint: Each line should contain expressions followed by a block, or "else" followed by a block.
")
$action = $line.(#$line)
if (($line.1 == "else") and ((#$line) == 2)):
if (($line.1 == "else") and (#$line == 2)):
unless $else_allowed:
at $line fail ("
Compile error: You can't have two 'else' blocks.
Hint: Merge all of the 'else' blocks together.
")
unless ((#"\$code") > 0):
unless (#"\$code" > 0):
at $line fail ("
Compile error: You can't have an 'else' block without a preceding condition.
Hint: If you want the code in this block to always execute, you don't need a conditional \
@ -429,14 +413,14 @@ test:
$else_allowed = (no)
..else:
$code, add $clause " "
for $i in 1 to ((#$line) - 1):
for $i in (1 to (#$line - 1)):
if ($i > 1):
$code, add " or "
$code, add "\(mangle "branch value") == " ($line.$i as lua expr)
$code, add " then\n " ($action as lua)
$clause = "\nelseif"
if ((#"\$code") == 0):
if (#"\$code" == 0):
at $body fail ("
Compile error: 'if' block has an empty body.
Hint: This means nothing would happen, so the 'if' block should be deleted.
@ -450,7 +434,7 @@ test:
end -- if $ is...
")
# Do/finally
### Do/finally
(do $action) compiles to ("
do
\($action as lua)
@ -460,8 +444,8 @@ test:
test:
assume ((result of: return 99) == 99)
# Inline thunk:
(result of $body) compiles to "\(\(-> $body) as lua)()"
### Inline thunk:
(result of $body) compiles to "\(("Action" tree with "->" $body) as lua)()"
test:
$t = [1, [2, [[3], 4], 5, [[[6]]]]]
$flat = []
@ -473,7 +457,7 @@ test:
$flat, add $
assume (sorted $flat) == [1, 2, 3, 4, 5, 6]
# Recurion control flow
### Recurion control flow
(recurse $v on $x) compiles to
Lua "table.insert(_stack_\($v as lua expr), \($x as lua expr))"
@ -487,14 +471,14 @@ test:
\($body as lua)
")
if ($body has subtree \(do next)):
if ($body, contains `(do next)):
$lua, add "\n ::continue::"
if ($body has subtree \(do next $var)):
$lua, add "\n \(\(---next $var ---) as lua)"
if ($body, contains ("Action" tree with "do" "next" $var)):
$lua, add "\n \(("Action" tree with "---" "next" $var "---") as lua)"
$lua, add "\n end -- Recursive loop"
if ($body has subtree \(stop $var)):
$lua, add "\n \(\(---stop $var ---) as lua)"
if ($body, contains ("Action" tree with "stop" $var)):
$lua, add "\n \(("Action" tree with "---" "stop" $var "---") as lua)"
$lua, add "\nend -- Recursive scope"
return $lua

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines the code that creates and manipulates coroutines
use "core/metaprogramming"
@ -16,11 +17,8 @@ test:
repeat 3 times:
yield 6
$nums = []
for $ in (coroutine from $fn):
$nums, add $
for $ in (coroutine from $fn): $nums, add $
assume ($nums == [4, 5, 6, 6, 6])
$d = {.x = 0}
$co =
coroutine:
@ -35,7 +33,6 @@ test:
[$ok, $val] = (co)
assume ($ok == (yes))
assume ($val == 5)
$t = []
$i = 1
for $ in
@ -47,8 +44,7 @@ test:
..:
$t.$i = $
$i += 1
assume ($t == [4,5,nil,6])
assume ($t == [4, 5, nil, 6])
$t = []
for ($k = $) in
coroutine:
@ -58,11 +54,11 @@ test:
yield 6
..:
$t, add {.key = $k, .value = $}
assume $t == [
{.key = 1, .value = 4}, {.key = 2, .value = 5}, {.key = 3}, {.key = 4, .value = 6}
]
(coroutine $body) parses as (coroutine from (-> $body))
(coroutine $body) parses as (coroutine from ->$body)
external:
($ is a dead coroutine) means
((lua type of $) == "thread") and ((coroutine status of $) == "dead")
((lua type of $) == "thread") and ((coroutine status of $) == "dead")

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file contains basic error reporting code
use "core/metaprogramming"
@ -63,8 +64,7 @@ use "core/control_flow"
if not _1_is(_a, _b) then
_a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
at_1_fail(\(quote "\($condition.1.source)"),
"Assumption failed: This value (".._a..") was expected to be "..\
.._b..", but wasn't.")
"Assumption failed: This value (".._a..") was expected to be ".._b..", but wasn't.")
end
end
")
@ -76,8 +76,7 @@ use "core/control_flow"
if _1_is(_a, _b) then
_a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
at_1_fail(\(quote "\($condition.1.source)"),
"Assumption failed: This value (".._a..") was expected to not be \
..".._b..", but it was.")
"Assumption failed: This value (".._a..") was expected to not be ".._b..", but it was.")
end
end
")
@ -104,21 +103,21 @@ test:
unless $worked:
fail "'try' failed to recover from failure"
# Try/except
### Try/except
[
try $action if it succeeds $success if it fails with $msg $fallback
try $action if it fails with $msg $fallback if it succeeds $success
] all compile to:
$success_lua = ($success as lua)
if ((#"\$success_lua") > 0):
if (#"\$success_lua" > 0):
$success_lua, add "\n"
$success_lua, prepend "-- Success:\n"
$success_lua,
add "if not _fell_through then return table.unpack(_result, 2) end"
$fallback_lua = ($fallback as lua)
if ((#"\$fallback_lua") > 0):
if (#"\$fallback_lua" > 0):
$msg_lua = ($msg as lua expr)
if ((#"\$msg_lua") > 0):
if (#"\$msg_lua" > 0):
$fallback_lua, prepend "\n\$msg_lua = _result[2]\n"
if ($msg_lua, text, is lua id):
$fallback_lua, add free vars [($msg_lua, text)]
@ -181,4 +180,4 @@ test:
if not _results[1] then error(_results[2], 0) end
if not _fell_through then return table.unpack(_results, 2) end
end
")
")

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
A simple UUID function based on RFC 4122: http://www.ietf.org/rfc/rfc4122.txt
use "core/metaprogramming"
@ -35,27 +36,29 @@ set $id_by_obj's metatable to {
external:
(uuid) means:
# Set all the other bits to randomly (or pseudo-randomly) chosen values.
### Set all the other bits to randomly (or pseudo-randomly) chosen values.
$bytes = [
# time-low, time-mid, time-high-and-version
### time-low, time-mid, time-high-and-version
randint (2 ^ (4 * 8)), randint (2 ^ (2 * 8)), randint (2 ^ (2 * 8 - 4))
# clock-seq-and-reserved, clock-seq-low
### clock-seq-and-reserved, clock-seq-low
randint (2 ^ (1 * 8 - 2)), randint (2 ^ (1 * 8)), randint (2 ^ (3 * 8))
# node
### node
randint (2 ^ (3 * 8))
]
# Set the four most significant bits (bits 12 through 15) of the
# time_hi_and_version field to the 4-bit version number from
# Section 4.1.3.
### Set the four most significant bits (bits 12 through 15) of the
### time_hi_and_version field to the 4-bit version number from
### Section 4.1.3.
$bytes.3 += 0x4000
# Set the two most significant bits (bits 6 and 7) of the
# clock_seq_hi_and_reserved to zero and one, respectively.
### Set the two most significant bits (bits 6 and 7) of the
### clock_seq_hi_and_reserved to zero and one, respectively.
$bytes.4 += 0xC0
return (=lua "('%08x-%04x-%04x-%02x%02x-%6x%6x'):format(unpack(\$bytes))")
# For strict identity checking, use ($x's id) == ($y's id)
### For strict identity checking, use ($x's id) == ($y's id)
test:
assume (([] == []) and ((id of []) != (id of [])))
seed random with 0
@ -64,4 +67,4 @@ external:
seed random with 0
assume ((id of $x) != (id of []))
seed random
[id of $, $'s id, $'id] all mean $id_by_obj.$
[id of $, $'s id, $'id] all mean $id_by_obj.$

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
# Export everything
#!/usr/bin/env nomsu -V7.0.0
### Export everything
export "core/metaprogramming"
export "core/operators"
export "core/control_flow"
@ -11,4 +12,4 @@ export "core/id"
export "core/io"
export "core/text"
export "core/things"
export "core/time"
export "core/time"

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file contains basic input/output code
use "core/metaprogramming"
@ -10,14 +11,12 @@ use "core/control_flow"
external:
(say (*extra arguments*)) means:
for $ in 1 to (select "#" (*extra arguments*)):
for $ in (1 to (select "#" (*extra arguments*))):
$arg = (select $ (*extra arguments*))
$io.write ($arg as text)
$io.write "\n"
$io.flush()
(say $message inline) means ($io.write $message)
(ask $prompt) means:
$io.write $prompt
return ($io.read())
return ($io.read())

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines some common math literals and functions
use "core/metaprogramming"
@ -11,7 +12,7 @@ use "core/collections"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external:
# Literals:
### Literals:
test:
unless (all of [inf, NaN, pi, tau, golden ratio, e]):
fail "math constants failed"
@ -25,7 +26,7 @@ external:
(golden ratio) compiles to "((1+math.sqrt(5))/2)"
(e) compiles to "math.exp(1)"
# Functions:
### Functions:
test:
assume (("5" as a number) == 5)
$($ as a number) = $(tonumber $)
@ -33,7 +34,7 @@ external:
test:
unless
all of [
abs 5, | 5 |, sqrt 5, √ 5, sine 5, cosine 5, tangent 5, arc sine 5, arc cosine 5
abs 5, | 5 |, sqrt 5, √5, sine 5, cosine 5, tangent 5, arc sine 5, arc cosine 5
arc tangent 5, arc tangent 5 / 10, hyperbolic sine 5, hyperbolic cosine 5
hyperbolic tangent 5, e^ 5, ln 5, log 5 base 2, floor 5, ceiling 5, round 5
]
@ -43,7 +44,7 @@ external:
[$(absolute value $), $(absolute value of $), $(| $ |), $(abs $)] =
[$math.abs, $math.abs, $math.abs, $math.abs]
[$(square root $), $(square root of $), $(√ $), $(sqrt $)] =
[$(square root $), $(square root of $), $(√$), $(sqrt $)] =
[$math.sqrt, $math.sqrt, $math.sqrt, $math.sqrt]
[$(sine $), $(sin $)] = [$math.sin, $math.sin]
@ -67,7 +68,7 @@ external:
unless ((2.6 to the nearest 0.25) == 2.5): fail "rounding failed"
($n to the nearest $rounder) means ($rounder * (floor ($n / $rounder + 0.5)))
# Any/all
### Any/all
[all of $items, all $items] all mean:
for $ in $items:
unless $:
@ -81,7 +82,7 @@ external:
return (no)
[none of $items, none $items] all parse as (not (any of $items))
# Sum/product
### Sum/product
[sum of $items, sum $items] all mean:
$total = 0
for $ in $items:
@ -94,9 +95,9 @@ external:
$prod *= $
return $prod
[avg of $items, average of $items] all mean ((sum of $items) / (#$items))
[avg of $items, average of $items] all mean ((sum of $items) / #$items)
# Min/max
### Min/max
[min of $items, smallest of $items, lowest of $items] all mean:
$best = (nil)
for $ in $items:
@ -186,13 +187,13 @@ external:
($nums mixed by $amount) means:
$ = ($amount clamped between 0 and 1)
$i = (1 + ($ * ((#$nums) - 1)))
if ((floor $i) == (#$nums)):
$i = (1 + ($ * (#$nums - 1)))
if ((floor $i) == #$nums):
return $nums.(floor $i)
[$lo, $hi] = [$nums.(floor $i), $nums.(floor ($i + 1))]
return ($lo to $hi mixed by ($i mod 1))
# Random functions
### Random functions
(seed random with $) means:
lua> ("
math.randomseed(\$);

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This File contains actions for making actions and compile-time actions and some helper
functions to make that easier.
@ -55,6 +56,28 @@ lua> ("
end
COMPILE_RULES["->"] = COMPILE_RULES["1 ->"]
COMPILE_RULES["for"] = COMPILE_RULES["1 ->"]
COMPILE_RULES["`"] = function(\(nomsu environment), _tree, escaped)
local function escape(t)
if t.type == "Action" and t:get_stub() == "`" and #t == 2 then
return \(nomsu environment):compile(t[2])
else
local bits = {}
table.insert(bits, "type="..t.type:as_lua())
if t.source then
table.insert(bits, "source="..t.source:as_lua())
end
for i,b in ipairs(t) do
table.insert(bits, lua_type_of(b) == 'string' and b:as_lua() or escape(b))
end
local lua = LuaCode:from(t.source, "SyntaxTree{")
lua:concat_add(bits, ", ")
lua:add("}")
return lua
end
end
return escape(escaped)
end
")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -95,7 +118,8 @@ lua> ("
(\$action.type == "EscapedNomsu" and \$action[1].type == "Action") or
\$action.type == "MethodCall") then
at_1_fail(\$action.source, "Compile error: "..
"This first argument to (* compiles to *) is neither an action nor an escaped action (it's a "..\$action.type.."). "..
"This first argument to (* compiles to *) is neither an action nor an escaped \
..action (it's a "..\$action.type.."). "..
"Hint: This should probably be an action like:\\n"
.."(foo $x) compiles to \\"(\\\\($x as lua) + 1)\\"")
end
@ -104,25 +128,23 @@ lua> ("
if a.type == "EscapedNomsu" then \$args:add(a[1]) end
end
return LuaCode("COMPILE_RULES[", \($action as lua), ":get_stub()] = ",
\(\($args -> $body) as lua))
\(`(`$args -> `$body) as lua))
else
for _,a in ipairs(\$action:get_args()) do \$args:add(a) end
return LuaCode("COMPILE_RULES[", \$action:get_stub():as_lua(),
"] = ", \(\($args -> $body) as lua))
"] = ", \(`(`$args -> `$body) as lua))
end
end
")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(` $) compiles to (Lua (=lua "\$ or SyntaxTree{type='Action'}", as lua))
($actions all compile to $body) compiles to:
lua> ("
if \$actions.type ~= "List" then
at_1_fail(\$actions, "Compile error: This should be a list of actions.")
end
local lua = \(\($actions.1 compiles to $body) as lua)
local lua = \(`(`$actions.1 compiles to `$body) as lua)
local \$args = a_List{"\(nomsu environment)", "\(this tree)", unpack(\$actions[1]:get_args())}
local \$compiled_args = a_List{"\(nomsu environment)", "\(this tree)"};
for i=3,#\$args do \$compiled_args[i] = \(nomsu environment):compile(\$args[i]) end
@ -165,7 +187,6 @@ test:
($action means $body) compiles to:
lua> ("
local lua = LuaCode()
if \$action.type == "MethodCall" then
lua:add(\(nomsu environment):compile(\$action[1]), ".", \$action[2]:get_stub():as_lua_id())
@ -175,15 +196,16 @@ test:
else
at_1_fail(\$action, "Compile error: This is not an action or method call.")
end
lua:add(" = ", \(\($action -> $body) as lua), ";")
lua:add(" = ", \(`(`$action -> `$body) as lua), ";")
return lua
")
($actions all mean $body) compiles to:
lua> ("
local lua = \(\($actions.1 means $body) as lua)
local lua = \(`(`$actions.1 means `$body) as lua)
local first_def = (\$actions[1].type == "MethodCall"
and LuaCode(\(nomsu environment):compile(\$actions[1][1]), ".", \$actions[1][2]:get_stub():as_lua_id())
and LuaCode(\(nomsu environment):compile(\$actions[1][1]), ".", \$actions[1][2]:get_\
..stub():as_lua_id())
or LuaCode(\$actions[1]:get_stub():as_lua_id()))
local \$args = a_List(\$actions[1]:get_args())
for i=2,#\$actions do
@ -199,7 +221,7 @@ test:
if \$args == \$alias_args then
lua:add(" = ", first_def, ";")
else
lua:add(" = ", \(\($alias_args -> $actions.1) as lua), ";")
lua:add(" = ", \(`(`$alias_args -> `$actions.1) as lua), ";")
end
end
return lua
@ -301,15 +323,13 @@ test:
local \$new_body = LuaCode:from(\$body.source,
"local mangle = mangler()",
"\\nreturn ", make_tree(\$body))
local ret = \(\($actions all compile to $new_body) as lua)
return ret
return \(`(`$actions all compile to `$new_body) as lua)
")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[$action parses as $body] all parse as ([$action] all parse as $body)
((nomsu environment), $tree as lua expr) means:
(nomsu environment, $tree as lua expr) means:
lua> ("
local tree_lua = \(nomsu environment):compile(\$tree)
if \$tree.type == 'Block' and #\$tree > 1 then
@ -318,9 +338,8 @@ test:
return tree_lua
")
# Need to make sure the proper environment is used for compilation (i.e. the caller's environment)
($tree as lua expr) compiles to
=lua "SyntaxTree{type='MethodCall', \(\(nomsu environment)), \(\($tree as lua expr))}"
### Need to make sure the proper environment is used for compilation (i.e. the caller's environment)
($tree as lua expr) compiles to `((nomsu environment), `$tree as lua expr)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -337,11 +356,11 @@ external:
")
test:
(num args (*extra arguments*)) means (#(*extra arguments*))
(num args (*extra arguments*)) means #(*extra arguments*)
assume (num args 1 2 3) == 3
(extra args (*extra arguments*)) means [*extra arguments*]
assume (extra args 1 2 3) == [1, 2, 3]
(third arg (*extra arguments*)) means ((*extra arguments*).3)
(third arg (*extra arguments*)) means (*extra arguments*).3
assume (third arg 5 6 7 8) == 7
(*extra arguments*) compiles to "..."
@ -405,7 +424,7 @@ external:
local lua_type = \(lua type of $)
return 'a '..lua_type:capitalized()
")
($ is $type) means:
lua> ("
local class = getmetatable(\$)
@ -425,13 +444,15 @@ external:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test:
assume ("Action" tree with "foo" ("Var" tree with "x")) == \(foo \$x)
assume ("Action" tree with "foo" ("Var" tree with "x")) == `(foo $x)
external:
($type tree with (*extra arguments*)) means
SyntaxTree (=lua "{type=\$type, ...}")
($type tree from $source) means
SyntaxTree (=lua "{type=\$type, source=\$source}")
($type tree from $source with (*extra arguments*)) means
SyntaxTree (=lua "{type=\$type, source=\$source, ...}")
@ -440,7 +461,7 @@ test:
return 100 200 300
assume (select 2 (foo)) == 200
# Return statement is wrapped in a do..end block because Lua is unhappy if you
### Return statement is wrapped in a do..end block because Lua is unhappy if you
put code after a return statement, unless you wrap it in a block.
(return (*extra arguments*)) compiles to:
lua> ("
@ -453,10 +474,10 @@ test:
return lua
")
# Convenience helper:
(return Lua (*extra arguments*)) compiles to \(return \(Lua (*extra arguments*)))
### Convenience helper:
(return Lua (*extra arguments*)) compiles to `(return (Lua `(*extra arguments*)))
# Literals
### Literals
(yes) compiles to "(true)"
(no) compiles to "(false)"
[nothing, nil, null] all compile to "(nil)"
@ -466,7 +487,7 @@ test:
(at compilation $expr) compiles to:
lua> ("
local value = \(nomsu environment):run(\(\(return $expr)))
local value = \(nomsu environment):run(\(`(return `$expr)))
if lua_type_of(value) == 'table' or lua_type_of(value) == 'string' and value.as_lua then
return LuaCode(value:as_lua())
else
@ -490,8 +511,9 @@ test:
return lua
")
~~~~
# TODO: Remove shim
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### TODO: Remove shim
($tree with $t -> $replacement) parses as
$tree, with ($t -> $replacement)

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file contains definitions of operators like "+" and "and".
use "core/metaprogramming"
@ -9,7 +10,7 @@ use "core/metaprogramming"
test:
assume (all [1 < 2, 2 > 1, 1 <= 2, 2 >= 1, 1 == 1, 1 != 2])
# Comparison Operators
### Comparison Operators
($x < $y) compiles to "(\($x as lua expr) < \($y as lua expr))"
($x > $y) compiles to "(\($x as lua expr) > \($y as lua expr))"
($x <= $y) compiles to "(\($x as lua expr) <= \($y as lua expr))"
@ -33,7 +34,7 @@ test:
unless (($x == 4) and ($y == 5)):
fail "unpacking failed"
# Variable assignment operator
### Variable assignment operator
($var = $value) compiles to:
lua> ("
local lua = LuaCode()
@ -113,7 +114,7 @@ test:
end -- 'with' block
")
# Math Operators
### Math Operators
test:
unless ((5 wrapped around 2) == 1):
fail "mod not working"
@ -121,8 +122,8 @@ test:
[$x wrapped around $y, $x mod $y, $x % $y] all compile to
"((\($x as lua expr)) % (\($y as lua expr)))"
# 3-part chained comparisons
# (uses a lambda to avoid re-evaluating middle value, while still being an expression)
### 3-part chained comparisons
### (uses a lambda to avoid re-evaluating middle value, while still being an expression)
test:
$calls = 0
(one) means:
@ -144,8 +145,8 @@ test:
($x > $y >= $z) parses as ((($a $b $c) -> (($a > $b) and ($b >= $c))) $x $y $z)
($x >= $y >= $z) parses as ((($a $b $c) -> (($a >= $b) and ($b >= $c))) $x $y $z)
# TODO: optimize for common case where x,y,z are all either variables or number literals
# Boolean Operators
### TODO: optimize for common case where x,y,z are all either variables or number literals
### Boolean Operators
test:
(barfer) means (fail "short circuiting failed")
assume (((no) and (barfer)) == (no))
@ -156,8 +157,8 @@ test:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Bitwise Operators
# These can break if running the precompiled code from another Lua version:
### Bitwise Operators
### These can break if running the precompiled code from another Lua version:
lua> ("
if \(at compilation $(LUA VERSION)) ~= \$(LUA VERSION) then
\(
@ -169,19 +170,19 @@ lua> ("
end
")
# TODO: implement OR, XOR, AND for multiple operands?
### TODO: implement OR, XOR, AND for multiple operands?
test:
assume ((~ (~ 5)) == 5)
assume (~(~5) == 5)
assume ((1 | 4) == 5)
assume ((1 ~ 3) == 2)
assume ((1 & 3) == 1)
assume ((1 << 2) == 4)
assume ((4 >> 2) == 1)
# Lua 5.3 introduced bit operators like | and &. Use them when possible, otherwise
### Lua 5.3 introduced bit operators like | and &. Use them when possible, otherwise
fall back to bit.bor(), bit.band(), etc.
lua> "if \((is jit) or ($(LUA API) == "Lua 5.2")) then"
[NOT $, ~ $] all compile to "Bit.bnot(\($ as lua expr))"
[NOT $, ~$] all compile to "Bit.bnot(\($ as lua expr))"
[$x OR $y, $x | $y] all compile to
"Bit.bor(\($x as lua expr), \($y as lua expr))"
@ -198,7 +199,7 @@ lua> "if \((is jit) or ($(LUA API) == "Lua 5.2")) then"
"Bit.rshift(\($x as lua expr), \($shift as lua expr))"
lua> "else"
[NOT $, ~ $] all compile to "(~(\($ as lua expr)))"
[NOT $, ~$] all compile to "(~(\($ as lua expr)))"
[$x OR $y, $x | $y] all compile to "(\($x as lua expr) | \($y as lua expr))"
[$x XOR $y, $x ~ $y] all compile to "(\($x as lua expr) ~ \($y as lua expr))"
[$x AND $y, $x & $y] all compile to "(\($x as lua expr) & \($y as lua expr))"
@ -210,16 +211,17 @@ lua> "else"
lua> "end"
# Unary operators
### Unary operators
test:
assume ((- 5) == -5)
assume (-(5) == -5)
assume ((not (yes)) == (no))
(- $) compiles to "(-(\($ as lua expr)))"
-$ compiles to "(-(\($ as lua expr)))"
(not $) compiles to "(not \($ as lua expr))"
test:
assume ((size of [1, 2, 3]) == 3)
assume ((#[1, 2, 3]) == 3)
# Length
assume (#[1, 2, 3] == 3)
### Length
[#$list, size of $list] all compile to:
lua> ("
local list_lua = \($list as lua expr)
@ -228,11 +230,11 @@ test:
end
return LuaCode("(#", list_lua, ")")
")
($list is empty) parses as ((#$list) == 0)
($list is empty) parses as (#$list == 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Update operators
### Update operators
test:
$x = 1
$x += 1

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file contains some definitions of text escape sequences, including ANSI console
color codes.
@ -62,17 +63,17 @@ test:
external:
($num as hex) means:
if ($num < 0):
return ("-0x%X", formatted with (- $num))
return ("-0x%X", formatted with -$num)
..else:
return ("0x%X", formatted with $num)
# Text literals
### Text literals
$escapes = {
.nl = "\n", .newline = "\n", .tab = "\t", .bell = "\a", .cr = "\r"
."carriage return" = "\r", .backspace = "\b", ."form feed" = "\f"
.formfeed = "\f", ."vertical tab" = "\v"
}
for $name = $str in $escapes:
for ($name = $str) in $escapes:
with [$lua = (Lua (quote $str))]:
$(COMPILE RULES).$name = (-> $lua)
$(COMPILE RULES).$name = ->$lua

View File

@ -1,7 +1,8 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
A library for simple object oriented programming.
#!/usr/bin/env nomsu -V7.0.0
###
A library for simple object oriented programming.
use "core/metaprogramming"
use "core/operators"
use "core/control_flow"
@ -34,7 +35,7 @@ test:
assume $b != (a Buffer {.bits = []})
(a Comma Buffer) is (a Buffer) with [$bits]:
($self, as text) means ($bits, joined with ",")
($self, number of commas) means ((#$bits) - 1)
($self, number of commas) means (#$bits - 1)
$csv = (a Comma Buffer)
assume $csv.is_a_buffer
assume ($csv is "a Comma Buffer")
@ -45,7 +46,7 @@ test:
assume "\$csv" == "x,y"
assume ($csv, number of commas) == 1
(a Vec) is (a thing) with [$x, $y]:
($self, + $other) means (Vec ($x + $other.x) ($y + $other.y))
($self, +$other) means (Vec ($x + $other.x) ($y + $other.y))
($self, length) means (sqrt ($x * $x + $y * $y))
(Vec $x $y) means (a Vec {.x = $x, .y = $y})
assume ((Vec 1 2) + (Vec 10 10)) == (Vec 11 12)
@ -70,7 +71,6 @@ external:
$class.__tostring = ($ -> "\($.__type) \($ as text like a dict)")
$class.__eq = ({}'s metatable).__eq
$class.__len = ({}'s metatable).__len
set $class's metatable to {
.__index = $parent, .__tostring = ($class -> $class.__type)
.__call =
@ -84,19 +84,15 @@ external:
if $(initialize $):
initialize $class
for $stub = $metamethod in $METAMETHOD_MAP:
for ($stub = $metamethod) in $METAMETHOD_MAP:
if $class.($stub, as lua id):
$class.$metamethod = $class.($stub, as lua id)
return $class
$(a thing) = ((nil) class named "thing")
($classname is $parent with $vars $class_body) compiles to:
unless ($vars.type == "List"):
at $vars fail ("
Compile error: This is not a list of variables.
")
at $vars fail "Compile error: This is not a list of variables."
$class_id = ($classname.stub, as lua id)
$class_body and=
$class_body, with
@ -106,9 +102,10 @@ external:
return
"IndexChain" tree with ("Var" tree with "self")
"Index" tree with ("Text" tree with $v.1)
if ($parent.type == "Action"):
$parent = ("Var" tree with $parent)
$lua =
Lua ("
\$class_id = _1_class_named(\($parent as lua id), \(quote $classname.stub)\(
@ -122,5 +119,6 @@ external:
) if $class_body else ""
))
")
$lua, add free vars [$class_id]
return $lua
return $lua

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines time-related actions.
use "core/metaprogramming"
@ -14,23 +15,23 @@ external:
(a Time) is (a thing) with [
$year, $month, $day, $hour, $min, $sec, $wday, $yday, $isdst
]:
($self, + $other) means:
($self, +$other) means:
if (($self is "a Time") and ($other is "a Time")):
fail ("
Type error: Cannot add two times together.
Hint: One of these two should be a number, not a time.
")
if ($other is not "a Number"):
if ($other isn'tt "a Number"):
$other = ($os.time $other)
if ($self is not "a Number"):
if ($self isn't "a Number"):
$self = ($os.time $self)
return (a Time ($os.date "*t" ($self + $other, rounded)))
($self, - $other) means:
if ($self is not "a Time"):
($self, -$other) means:
if ($self isn't "a Time"):
fail "Type error: Cannot subtract a Time from something that isn't a Time."
$self = ($os.time $self)
if ($other is "a Time"):
@ -45,7 +46,7 @@ external:
return (a Time ($os.date "*t"))
[sleep for $t seconds, sleep for $t second] all mean:
# Lua does not come with a sleep() function, only an os.clock() function,
### Lua does not come with a sleep() function, only an os.clock() function,
so this busy-loop is necessary for cross-platform compatibility.
$deadline = (($os.clock()) + $t)
repeat while (($os.clock()) < $deadline): do nothing

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines some actions for hashing files and looking up files by hash.
use "filesystem"
@ -37,7 +38,7 @@ if $use_sha1:
$hash = (=lua "\$hashlib.new('sha1'):final(\$)")
return (base64 $hash)
..else:
# TODO: remove warning?
### TODO: remove warning?
say ("
\027[31;1mWARNING: OpenSSL module not found. Defaulting to a non-cryptographically secure \
..hash function.\027[0m
@ -47,9 +48,9 @@ if $use_sha1:
(hash $) means:
$bytes = ($, bytes)
$hash = ($bytes.1 << 7)
for $i in 2 to (#$bytes):
for $i in (2 to #$bytes):
$hash = ((1000003 * $hash) ~ $bytes.$i)
$hash = ($hash ~ (#$bytes))
$hash = ($hash ~ #$bytes)
return "\$hash"
external:

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
#
#!/usr/bin/env nomsu -V7.0.0
###
This file defines some actions that interact with the filesystem.
external:
@ -26,12 +27,13 @@ external:
$source = ($tree.source if ($tree is syntax tree) else $tree)
$file = (read file $source.filename)
return
[
: for $ in ($file, line number at $source.start) to
$file, line number at $source.stop
..: add ($file, line $)
[:
for $ in
($file, line number at $source.start) to ($file, line number at $source.stop)
..:
add ($file, line $)
], joined with "\n"
$(spoof file $text) = $Files.spoof
$(spoof file $filename = $text) = $Files.spoof
$(make directory $path) = $Files.make_directory
$(make directory $path) = $Files.make_directory

View File

@ -1,5 +1,6 @@
#!/usr/bin/env nomsu -V6.15.13.8
# A progress bar
#!/usr/bin/env nomsu -V7.0.0
### A progress bar
use "consolecolor"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -13,13 +14,12 @@ external:
$x = ($x clamped between 0 and $w)
if $(COLOR ENABLED):
$bits = [" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"]
$middle = ("" if ($x == $w) else $bits.(1 + (floor ((#$bits) * ($x mod 1)))))
$middle = ("" if ($x == $w) else $bits.(1 + (floor (#$bits * ($x mod 1)))))
return ("
\(reset color)[\(green)\($bits, last, rep (floor $x))\$middle\(" ", rep ($w - ((floor $x) + 1)))\(reset color)]
\(reset color)[\(green)\($bits, last, rep (floor $x))\$middle\
..\(" ", rep ($w - ((floor $x) + 1)))\(reset color)]
")
..else:
# Probably not unicode support either:
return ("
[\("#", rep ($x, rounded down))\("-", rep ($w - ($x, rounded down)))]
")
($w wide $ progress bar) means (($ * $w) / $w progress bar)
### Probably not unicode support either:
return "[\("#", rep ($x, rounded down))\("-", rep ($w - ($x, rounded down)))]"
($w wide $ progress bar) means (($ * $w) / $w progress bar)

View File

@ -1,7 +1,8 @@
#!/usr/bin/env nomsu -V6
#
This file defines some actions for running shell commands.
#!/usr/bin/env nomsu -V7.0.0
###
This file defines some actions for running shell commands.
external:
(at $callsite =sh $cmd) means:
$f = ($io.popen $cmd)
@ -9,19 +10,26 @@ external:
[$ok, $return_type, $return] = ($f, close)
unless $ok:
if ($return_type == "exit"):
at $callsite fail "Command failure: Command `\$cmd` failed with exit code \$return"
at $callsite fail
"Command failure: Command `\($cmd)` failed with exit code \$return"
..else:
at $callsite fail "Command failure: Command `\$cmd` was terminated by signal \$return"
at $callsite fail
"Command failure: Command `\($cmd)` was terminated by signal \$return"
return $contents
(at $callsite sh> $cmd) means:
[$ok, $return_type, $return] = ($os.execute $cmd)
unless $ok:
if ($return_type == "exit"):
at $callsite fail "Command failure: Command `\$cmd` failed with exit code \$return"
at $callsite fail
"Command failure: Command `\($cmd)` failed with exit code \$return"
..else:
at $callsite fail "Command failure: Command `\$cmd` was terminated by signal \$return"
# Attach callsite information for better error reporting
(=sh $cmd) compiles to (\(at ("Text" tree with "\($cmd.source)") =sh $cmd) as lua)
(sh> $cmd) compiles to (\(at ("Text" tree with "\($cmd.source)") sh> $cmd) as lua)
at $callsite fail
"Command failure: Command `\($cmd)` was terminated by signal \$return"
### Attach callsite information for better error reporting
(=sh $cmd) compiles to
("Action" tree with "at" ("Text" tree with "\($cmd.source)") "=" "sh" $cmd) as lua
(sh> $cmd) compiles to
("Action" tree with "at" ("Text" tree with "\($cmd.source)") "sh" ">" $cmd) as lua

View File

@ -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

View File

@ -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...

View File

@ -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"

View File

@ -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"

View File

@ -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 "<Action name=\"\(($, get stub) as xml)\">\$body</Action>"
return "<Action name=\"\(($, get stub) as xml)\">\($body)</Action>"
..else:
return "<\($.type)>\$body</\($.type)>"
return "<\($.type)>\($body)</\($.type)>"
"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):

View File

@ -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

View File

@ -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..."] <pattern> <replacement> 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)
say ($tree2 as nomsu)

View File

@ -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)"

View File

@ -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"
")
[<your code here>, ???] 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 (???):
<your code here>
..else:
<your code here>
# 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
<your code here>
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:
<your code here>
# 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:
<your code here>
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 (<prev lesson>)
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 ($ == \(<prev lesson>)):
return ("Text" tree with (filename of ($i - 1), with "%.nom$" -> ""))
$tree, with
$ ->:
if ($ == `(<prev lesson>)):
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!")")

View File

@ -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"

View File

@ -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