Auto-upgraded code.
This commit is contained in:
parent
ec69ee6f62
commit
5059c081ac
@ -37,12 +37,15 @@ upgrade $tree to "2.4" as:
|
|||||||
$action = (=lua "SyntaxTree{type='Block', source=\$action.source, \$action}")
|
$action = (=lua "SyntaxTree{type='Block', source=\$action.source, \$action}")
|
||||||
$conditions, add $action
|
$conditions, add $action
|
||||||
$new_lines, add
|
$new_lines, add
|
||||||
=lua "SyntaxTree{type='Action', source=\$conditions[1].source, unpack(\$conditions)}"
|
=lua ("
|
||||||
|
SyntaxTree{type='Action', source=\$conditions[1].source, unpack(\$conditions)}
|
||||||
|
")
|
||||||
$conditions = []
|
$conditions = []
|
||||||
|
|
||||||
return
|
return
|
||||||
\(when $body) with vars {
|
\(when $body) with vars {
|
||||||
.body = (=lua "SyntaxTree{type='Block', source=\$tree[2].source, unpack(\$new_lines)}")
|
.body =
|
||||||
|
=lua "SyntaxTree{type='Block', source=\$tree[2].source, unpack(\$new_lines)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
"if 1 is ?" "if 1 = ?":
|
"if 1 is ?" "if 1 = ?":
|
||||||
@ -70,11 +73,13 @@ upgrade $tree to "2.4" as:
|
|||||||
$action = $line.3
|
$action = $line.3
|
||||||
unless ($action is "Block" syntax tree): $action = \(: $action)
|
unless ($action is "Block" syntax tree): $action = \(: $action)
|
||||||
$values, add $action
|
$values, add $action
|
||||||
$new_lines,
|
$new_lines, add
|
||||||
add (=lua "SyntaxTree{type='Action', source=\$values[1].source, unpack(\$values)}")
|
=lua "SyntaxTree{type='Action', source=\$values[1].source, unpack(\$values)}"
|
||||||
$values = []
|
$values = []
|
||||||
|
|
||||||
return
|
return
|
||||||
\(if $var is $body) with vars {
|
\(if $var is $body) with vars {
|
||||||
.var = ($tree.2 upgraded), .body = (=lua "SyntaxTree{type='Block', source=\$tree[5].source, unpack(\$new_lines)}")
|
.var = ($tree.2 upgraded)
|
||||||
|
.body =
|
||||||
|
=lua "SyntaxTree{type='Block', source=\$tree[5].source, unpack(\$new_lines)}"
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,9 @@ use "compatibility/compatibility.nom"
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
upgrade action [hash $, sha1 $] to "2.5.5.5" as
|
upgrade action [hash $, sha1 $] to "2.5.5.5" as
|
||||||
=lua "\(base64 decode (hash $)):gsub('.', function(c) return ('%x02'):format(c) end)"
|
=lua ("
|
||||||
|
\(base64 decode (hash $)):gsub('.', function(c) return ('%x02'):format(c) end)
|
||||||
|
")
|
||||||
|
|
||||||
upgrade action [file with hash $] to "2.5.5.5" as
|
upgrade action [file with hash $] to "2.5.5.5" as
|
||||||
file with hash
|
file with hash
|
||||||
|
@ -18,10 +18,8 @@ upgrade action [remove index $index from $list] to "3.6" as
|
|||||||
$list, remove index $index
|
$list, remove index $index
|
||||||
upgrade action [to $1 write $2, $1 <-write $2] to "3.6" as ($1, add $2)
|
upgrade action [to $1 write $2, $1 <-write $2] to "3.6" as ($1, add $2)
|
||||||
upgrade action [to $1 write $2 joined by $3] to "3.6" as
|
upgrade action [to $1 write $2 joined by $3] to "3.6" as
|
||||||
..($1, add $2 joined by $3)
|
$1, add $2 joined by $3
|
||||||
|
|
||||||
upgrade action [declare locals in $lua] to "3.6" as ($lua, declare locals)
|
upgrade action [declare locals in $lua] to "3.6" as ($lua, declare locals)
|
||||||
|
|
||||||
upgrade action [declare locals $locs in $lua] to "3.6" as
|
upgrade action [declare locals $locs in $lua] to "3.6" as
|
||||||
$lua, declare locals $locs
|
$lua, declare locals $locs
|
||||||
|
|
||||||
|
@ -7,19 +7,18 @@ use "compatibility/compatibility.nom"
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
upgrade action [$index st to last in $list] to "3.7" as
|
upgrade action [$index st to last in $list] to "3.7" as
|
||||||
..($list, $index st to last)
|
$list, $index st to last
|
||||||
|
|
||||||
upgrade action [$index nd to last in $list] to "3.7" as
|
upgrade action [$index nd to last in $list] to "3.7" as
|
||||||
..($list, $index nd to last)
|
$list, $index nd to last
|
||||||
|
|
||||||
upgrade action [$index rd to last in $list] to "3.7" as
|
upgrade action [$index rd to last in $list] to "3.7" as
|
||||||
..($list, $index rd to last)
|
$list, $index rd to last
|
||||||
|
|
||||||
upgrade action [$index th to last in $list] to "3.7" as
|
upgrade action [$index th to last in $list] to "3.7" as
|
||||||
..($list, $index rd th last)
|
$list, $index rd th last
|
||||||
|
|
||||||
upgrade action [last in $list] to "3.7" as ($list, last)
|
upgrade action [last in $list] to "3.7" as ($list, last)
|
||||||
|
|
||||||
upgrade action [first in $list] to "3.7" as ($list, first)
|
upgrade action [first in $list] to "3.7" as ($list, first)
|
||||||
upgrade action [$item is in $list, $list contains $item, $list has $item] to
|
upgrade action [$item is in $list, $list contains $item, $list has $item] to
|
||||||
.."3.7" as ($list, has $item)
|
.."3.7" as ($list, has $item)
|
||||||
|
@ -12,4 +12,4 @@ upgrade action (@) to "3" as $me
|
|||||||
upgrade action "as" to "3" via
|
upgrade action "as" to "3" via
|
||||||
for $tree:
|
for $tree:
|
||||||
compile error at $tree "Object API has changed and 'as' is no longer supported."
|
compile error at $tree "Object API has changed and 'as' is no longer supported."
|
||||||
.."Use (%obj::action ...) instead of (as %obj: action ...)"
|
"Use (%obj::action ...) instead of (as %obj: action ...)"
|
||||||
|
@ -12,41 +12,32 @@ upgrade action ($ as lua return) to "4.10.12.7" as
|
|||||||
upgrade action (Lua value $) to "4.10.12.7" as (Lua $)
|
upgrade action (Lua value $) to "4.10.12.7" as (Lua $)
|
||||||
|
|
||||||
upgrade action ($e for $ in $items) to "4.10.12.7" as [: for $ in $items: add $e]
|
upgrade action ($e for $ in $items) to "4.10.12.7" as [: for $ in $items: add $e]
|
||||||
upgrade action ($e for $k = $v in $items) to "4.10.12.7" as [
|
upgrade action ($e for $k = $v in $items) to "4.10.12.7" as
|
||||||
: for $k = $v in $items: add $e
|
[: for $k = $v in $items: add $e]
|
||||||
]
|
|
||||||
|
|
||||||
upgrade action ($e for $i in $start to $stop) to "4.10.12.7" as [
|
upgrade action ($e for $i in $start to $stop) to "4.10.12.7" as
|
||||||
: for $i in $start to $stop: add $e
|
[: for $i in $start to $stop: add $e]
|
||||||
]
|
|
||||||
|
|
||||||
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 by $step) to "4.10.12.7" as
|
||||||
: for $i in $start to $stop by $step: add $e
|
[: for $i in $start to $stop by $step: add $e]
|
||||||
]
|
|
||||||
|
|
||||||
upgrade action ($e for $i in $start to $stop via $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
|
[: for $i in $start to $stop by $step: add $e]
|
||||||
]
|
|
||||||
|
|
||||||
upgrade action ($k = $v for $ in $items) to "4.10.12.7" as {
|
upgrade action ($k = $v for $ in $items) to "4.10.12.7" as
|
||||||
: for $ in $items: add $k = $v
|
{: for $ in $items: add $k = $v}
|
||||||
}
|
|
||||||
|
|
||||||
upgrade action ($k = $v for $k0 = $v0 in $items) to "4.10.12.7" as {
|
upgrade action ($k = $v for $k0 = $v0 in $items) to "4.10.12.7" as
|
||||||
: for $k0 = $v0 in $items: add $k = $v
|
{: for $k0 = $v0 in $items: add $k = $v}
|
||||||
}
|
|
||||||
|
|
||||||
upgrade action ($k = $v for $i in $start to $stop) to "4.10.12.7" as {
|
upgrade action ($k = $v for $i in $start to $stop) to "4.10.12.7" as
|
||||||
: for $i in $start to $stop: add $k = $v
|
{: for $i in $start to $stop: add $k = $v}
|
||||||
}
|
|
||||||
|
|
||||||
upgrade action ($k = $v for $i in $start to $stop by $step) to "4.10.12.7" as {
|
upgrade action ($k = $v for $i in $start to $stop by $step) to "4.10.12.7" as
|
||||||
: for $i in $start to $stop by $step: add $k = $v
|
{: for $i in $start to $stop by $step: add $k = $v}
|
||||||
}
|
|
||||||
|
|
||||||
upgrade action ($k = $v for $i in $start to $stop via $step) to "4.10.12.7" as {
|
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
|
{: for $i in $start to $stop by $step: add $k = $v}
|
||||||
}
|
|
||||||
|
|
||||||
upgrade action (parse $text from $filename) to "4.10.12.7" as
|
upgrade action (parse $text from $filename) to "4.10.12.7" as
|
||||||
(NomsuCode from (Source $filename 1 (size of $text)) $text) parsed
|
(NomsuCode from (Source $filename 1 (size of $text)) $text) parsed
|
||||||
@ -84,9 +75,8 @@ upgrade $tree to "4.10.12.7" as:
|
|||||||
$chunk2.($j - $i + 1) = $first_chunk.$j
|
$chunk2.($j - $i + 1) = $first_chunk.$j
|
||||||
|
|
||||||
$new_tree =
|
$new_tree =
|
||||||
SyntaxTree {
|
SyntaxTree
|
||||||
.source = $tree.source, .type = "FileChunks", .1 = $chunk1, .2 = $chunk2
|
{.source = $tree.source, .type = "FileChunks", .1 = $chunk1, .2 = $chunk2}
|
||||||
}
|
|
||||||
|
|
||||||
for $i in 2 to (size of $tree):
|
for $i in 2 to (size of $tree):
|
||||||
$new_tree.($i + 1) = $tree.$i
|
$new_tree.($i + 1) = $tree.$i
|
||||||
|
@ -27,22 +27,20 @@ upgrade action "set" to "4.11" via
|
|||||||
$rhs.$i = $entry.2
|
$rhs.$i = $entry.2
|
||||||
|
|
||||||
return
|
return
|
||||||
SyntaxTree {
|
SyntaxTree
|
||||||
.type = "Action", .source = $tree.source, .1 = $lhs, .2 = "=", .3 = $rhs
|
{.type = "Action", .source = $tree.source, .1 = $lhs, .2 = "=", .3 = $rhs}
|
||||||
}
|
|
||||||
|
|
||||||
upgrade action "1 with 2 ~>" to "4.11" via
|
upgrade action "1 with 2 ~>" to "4.11" via
|
||||||
for $tree:
|
for $tree:
|
||||||
compile error at $tree "This method has been deprecated."
|
compile error at $tree "This method has been deprecated."
|
||||||
.."Perhaps this could be use %tree::map instead."
|
"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
|
upgrade action (for file $f in $path $body) to "4.11" as
|
||||||
for $f in (files for $path) $body
|
for $f in (files for $path) $body
|
||||||
|
|
||||||
upgrade action ($expr for file $f in $path) to "4.11" as [
|
upgrade action ($expr for file $f in $path) to "4.11" as
|
||||||
: for $f in (files for $path): add $expr
|
[: for $f in (files for $path): add $expr]
|
||||||
]
|
|
||||||
|
|
||||||
upgrade action (line $n in $text) to "4.11" as ($text, line $n)
|
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
|
upgrade action (line number of $pos in $text) to "4.11" as
|
||||||
|
@ -10,9 +10,9 @@ use "compatibility/compatibility.nom"
|
|||||||
upgrade action "do next repeat" to "4.12" via
|
upgrade action "do next repeat" to "4.12" via
|
||||||
for $tree:
|
for $tree:
|
||||||
compile error at $tree "This method has been deprecated."
|
compile error at $tree "This method has been deprecated."
|
||||||
.."Use either (do next) or (go to (label)) instead."
|
"Use either (do next) or (go to (label)) instead."
|
||||||
|
|
||||||
upgrade action "stop repeating" to "4.12" via
|
upgrade action "stop repeating" to "4.12" via
|
||||||
for $tree:
|
for $tree:
|
||||||
compile error at $tree "This method has been deprecated."
|
compile error at $tree "This method has been deprecated."
|
||||||
.."Use either (stop) or (go to (label)) instead."
|
"Use either (stop) or (go to (label)) instead."
|
||||||
|
@ -34,7 +34,9 @@ externally (upgrade action $stub to $version via $upgrade_fn) means:
|
|||||||
return $replacements.($t.1)
|
return $replacements.($t.1)
|
||||||
..else:
|
..else:
|
||||||
external $needs_mangle = (yes)
|
external $needs_mangle = (yes)
|
||||||
return "SyntaxTree{type=\(quote $t.type), source=\(quote "\($t.source)"), \(quote (mangle $t.1))}"
|
return ("
|
||||||
|
SyntaxTree{type=\(quote $t.type), source=\(quote "\($t.source)"), \(quote (mangle $t.1))}
|
||||||
|
")
|
||||||
|
|
||||||
($t is syntax tree):
|
($t is syntax tree):
|
||||||
$args = []
|
$args = []
|
||||||
@ -54,7 +56,8 @@ externally (upgrade action $stub to $version via $upgrade_fn) means:
|
|||||||
$retval = (make tree $body)
|
$retval = (make tree $body)
|
||||||
$lua, add
|
$lua, add
|
||||||
Lua ("
|
Lua ("
|
||||||
upgrade_action_1_to_2_via(\(quote $action.stub), \($version as lua expr), function(\(\$tree as lua id))
|
upgrade_action_1_to_2_via(\(quote $action.stub), \($version as lua expr), function(\
|
||||||
|
..\(\$tree as lua id))
|
||||||
return \$retval
|
return \$retval
|
||||||
end)
|
end)
|
||||||
")
|
")
|
||||||
|
@ -38,9 +38,8 @@ test:
|
|||||||
$dict = {.x = 1, .y = 2, .z = 3}
|
$dict = {.x = 1, .y = 2, .z = 3}
|
||||||
assume (size of $dict) == 3
|
assume (size of $dict) == 3
|
||||||
assume [: for $ in {.x = 1}: add $] == [{.key = "x", .value = 1}]
|
assume [: for $ in {.x = 1}: add $] == [{.key = "x", .value = 1}]
|
||||||
assume [: for $k = $v in {.x = 1}: add {.key = $k, .value = $v}] == [
|
assume [: for $k = $v in {.x = 1}: add {.key = $k, .value = $v}] ==
|
||||||
{.key = "x", .value = 1}
|
[{.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 = 11, .z = 10}
|
||||||
assume ({.x = 1, .y = 1} | {.y = 10, .z = 10}) == {.x = 1, .y = 1, .z = 10}
|
assume ({.x = 1, .y = 1} | {.y = 10, .z = 10}) == {.x = 1, .y = 1, .z = 10}
|
||||||
assume ({.x = 1, .y = 1} & {.y = 10, .z = 10}) == {.y = 1}
|
assume ({.x = 1, .y = 1} & {.y = 10, .z = 10}) == {.y = 1}
|
||||||
@ -62,9 +61,8 @@ externally ($lists flattened) means:
|
|||||||
test:
|
test:
|
||||||
assume ((entries in {.x = 1}) == [{.key = "x", .value = 1}])
|
assume ((entries in {.x = 1}) == [{.key = "x", .value = 1}])
|
||||||
|
|
||||||
(entries in $dict) parses as [
|
(entries in $dict) parses as
|
||||||
: for $k = $v in $dict: add {.key = $k, .value = $v}
|
[: for $k = $v in $dict: add {.key = $k, .value = $v}]
|
||||||
]
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
assume ((keys in {.x = 1}) == ["x"])
|
assume ((keys in {.x = 1}) == ["x"])
|
||||||
@ -81,10 +79,9 @@ test:
|
|||||||
assume ("\$t" == "XXX")
|
assume ("\$t" == "XXX")
|
||||||
|
|
||||||
(set $dict's metatable to $metatable) compiles to
|
(set $dict's metatable to $metatable) compiles to
|
||||||
.."setmetatable(\($dict as lua expr), \($metatable as lua expr));"
|
"setmetatable(\($dict as lua expr), \($metatable as lua expr));"
|
||||||
|
|
||||||
[$'s metatable, $'metatable] all compile to "getmetatable(\($ as lua expr))"
|
[$'s metatable, $'metatable] all compile to "getmetatable(\($ as lua expr))"
|
||||||
|
|
||||||
test:
|
test:
|
||||||
assume (({} with fallback $ -> ($ + 1)).10 == 11)
|
assume (({} with fallback $ -> ($ + 1)).10 == 11)
|
||||||
|
|
||||||
|
@ -30,8 +30,9 @@ test:
|
|||||||
barf "conditional fail"
|
barf "conditional fail"
|
||||||
|
|
||||||
(unless $condition $unless_body) parses as (if (not $condition) $unless_body)
|
(unless $condition $unless_body) parses as (if (not $condition) $unless_body)
|
||||||
[if $condition $if_body else $else_body, unless $condition $else_body else $if_body]
|
[
|
||||||
..all compile to ("
|
if $condition $if_body else $else_body, unless $condition $else_body else $if_body
|
||||||
|
] all compile to ("
|
||||||
if \($condition as lua expr) then
|
if \($condition as lua expr) then
|
||||||
\($if_body as lua)
|
\($if_body as lua)
|
||||||
else
|
else
|
||||||
@ -58,7 +59,10 @@ test:
|
|||||||
equivalent of a conditional expression: (cond and if_true or if_false)
|
equivalent of a conditional expression: (cond and if_true or if_false)
|
||||||
if {.Text, .List, .Dict, .Number}.($when_true_expr.type):
|
if {.Text, .List, .Dict, .Number}.($when_true_expr.type):
|
||||||
return
|
return
|
||||||
Lua "(\($condition as lua expr) and \($when_true_expr as lua expr) or \($when_false_expr as lua expr))"
|
Lua ("
|
||||||
|
(\($condition as lua expr) and \($when_true_expr as lua expr) or \
|
||||||
|
..\($when_false_expr as lua expr))
|
||||||
|
")
|
||||||
..else:
|
..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!)
|
doesn't have a proper ternary operator!)
|
||||||
@ -135,9 +139,15 @@ test:
|
|||||||
assume ($x == 20)
|
assume ($x == 20)
|
||||||
|
|
||||||
(repeat while $condition $body) compiles to:
|
(repeat while $condition $body) compiles to:
|
||||||
$lua = (Lua "while \($condition as lua expr) do\n \($body as lua)")
|
$lua =
|
||||||
|
Lua ("
|
||||||
|
while \($condition as lua expr) do
|
||||||
|
\($body as lua)
|
||||||
|
")
|
||||||
|
|
||||||
if ($body has subtree \(do next)):
|
if ($body has subtree \(do next)):
|
||||||
$lua, add "\n ::continue::"
|
$lua, add "\n ::continue::"
|
||||||
|
|
||||||
$lua, add "\nend --while-loop"
|
$lua, add "\nend --while-loop"
|
||||||
return $lua
|
return $lua
|
||||||
|
|
||||||
@ -173,7 +183,10 @@ test:
|
|||||||
] all compile to:
|
] all compile to:
|
||||||
# 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
|
||||||
$lua =
|
$lua =
|
||||||
Lua "for \($var as lua identifier)=\($start as lua expr),\($stop as lua expr),\($step as lua expr) do"
|
Lua ("
|
||||||
|
for \($var as lua identifier)=\($start as lua expr),\($stop as lua expr),\
|
||||||
|
..\($step as lua expr) do
|
||||||
|
")
|
||||||
$lua, add "\n " ($body as lua)
|
$lua, add "\n " ($body as lua)
|
||||||
if ($body has subtree \(do next)):
|
if ($body has subtree \(do next)):
|
||||||
$lua, add "\n ::continue::"
|
$lua, add "\n ::continue::"
|
||||||
@ -265,7 +278,10 @@ test:
|
|||||||
[for $key = $value in $iterable $body, for $key $value in $iterable $body]
|
[for $key = $value in $iterable $body, for $key $value in $iterable $body]
|
||||||
..all compile to:
|
..all compile to:
|
||||||
$lua =
|
$lua =
|
||||||
Lua "for \($key as lua identifier),\($value as lua identifier) in pairs(\($iterable as lua expr)) do"
|
Lua ("
|
||||||
|
for \($key as lua identifier),\($value as lua identifier) in pairs(\
|
||||||
|
..\($iterable as lua expr)) do
|
||||||
|
")
|
||||||
$lua, add "\n " ($body as lua)
|
$lua, add "\n " ($body as lua)
|
||||||
if ($body has subtree \(do next)):
|
if ($body has subtree \(do next)):
|
||||||
$lua, add "\n ::continue::"
|
$lua, add "\n ::continue::"
|
||||||
@ -314,7 +330,7 @@ test:
|
|||||||
$else_allowed = (yes)
|
$else_allowed = (yes)
|
||||||
unless ($body.type is "Block"):
|
unless ($body.type is "Block"):
|
||||||
compile error at $body "'if' expected a Block, but got a \($body.type)."
|
compile error at $body "'if' expected a Block, but got a \($body.type)."
|
||||||
.."Perhaps you forgot to put a ':' after 'if'?"
|
"Perhaps you forgot to put a ':' after 'if'?"
|
||||||
|
|
||||||
for $line in $body:
|
for $line in $body:
|
||||||
unless
|
unless
|
||||||
@ -329,7 +345,7 @@ test:
|
|||||||
if (($line.1 is "else") and ((size of $line) == 2)):
|
if (($line.1 is "else") and ((size of $line) == 2)):
|
||||||
unless $else_allowed:
|
unless $else_allowed:
|
||||||
compile error at $line "You can't have two 'else' blocks."
|
compile error at $line "You can't have two 'else' blocks."
|
||||||
.."Merge all of the 'else' blocks together."
|
"Merge all of the 'else' blocks together."
|
||||||
|
|
||||||
unless ((size of "\$code") > 0):
|
unless ((size of "\$code") > 0):
|
||||||
compile error at $line
|
compile error at $line
|
||||||
@ -338,12 +354,7 @@ test:
|
|||||||
..around it. Otherwise, make sure the 'else' block comes last.
|
..around it. Otherwise, make sure the 'else' block comes last.
|
||||||
")
|
")
|
||||||
|
|
||||||
$code, add ("
|
$code, add "\nelse\n " ($action as lua)
|
||||||
|
|
||||||
else
|
|
||||||
\;
|
|
||||||
") ($action as lua)
|
|
||||||
|
|
||||||
$else_allowed = (no)
|
$else_allowed = (no)
|
||||||
..else:
|
..else:
|
||||||
$code, add $clause " "
|
$code, add $clause " "
|
||||||
@ -351,20 +362,14 @@ test:
|
|||||||
if ($i > 1):
|
if ($i > 1):
|
||||||
$code, add " or "
|
$code, add " or "
|
||||||
$code, add ($line.$i as lua expr)
|
$code, add ($line.$i as lua expr)
|
||||||
|
$code, add " then\n " ($action as lua)
|
||||||
$code, add ("
|
|
||||||
then
|
|
||||||
\;
|
|
||||||
") ($action as lua)
|
|
||||||
|
|
||||||
$clause = "\nelseif"
|
$clause = "\nelseif"
|
||||||
|
|
||||||
if ((size of "\$code") == 0):
|
if ((size of "\$code") == 0):
|
||||||
compile error at $body "'if' block has an empty body."
|
compile error at $body "'if' block has an empty body."
|
||||||
.."This means nothing would happen, so the 'if' block should be deleted."
|
"This means nothing would happen, so the 'if' block should be deleted."
|
||||||
|
|
||||||
$code, add "\nend --when"
|
$code, add "\nend --when"
|
||||||
|
|
||||||
return $code
|
return $code
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@ -389,7 +394,7 @@ test:
|
|||||||
define mangler
|
define mangler
|
||||||
unless ($body.type is "Block"):
|
unless ($body.type is "Block"):
|
||||||
compile error at $body "'if' expected a Block, but got a \($body.type)"
|
compile error at $body "'if' expected a Block, but got a \($body.type)"
|
||||||
.."Perhaps you forgot to put a ':' after the 'is'?"
|
"Perhaps you forgot to put a ':' after the 'is'?"
|
||||||
|
|
||||||
for $line in $body:
|
for $line in $body:
|
||||||
unless
|
unless
|
||||||
@ -403,7 +408,7 @@ test:
|
|||||||
if (($line.1 is "else") and ((size of $line) == 2)):
|
if (($line.1 is "else") and ((size of $line) == 2)):
|
||||||
unless $else_allowed:
|
unless $else_allowed:
|
||||||
compile error at $line "You can't have two 'else' blocks."
|
compile error at $line "You can't have two 'else' blocks."
|
||||||
.."Merge all of the 'else' blocks together."
|
"Merge all of the 'else' blocks together."
|
||||||
|
|
||||||
unless ((size of "\$code") > 0):
|
unless ((size of "\$code") > 0):
|
||||||
compile error at $line
|
compile error at $line
|
||||||
@ -412,12 +417,7 @@ test:
|
|||||||
..around it. Otherwise, make sure the 'else' block comes last.
|
..around it. Otherwise, make sure the 'else' block comes last.
|
||||||
")
|
")
|
||||||
|
|
||||||
$code, add ("
|
$code, add "\nelse\n " ($action as lua)
|
||||||
|
|
||||||
else
|
|
||||||
\;
|
|
||||||
") ($action as lua)
|
|
||||||
|
|
||||||
$else_allowed = (no)
|
$else_allowed = (no)
|
||||||
..else:
|
..else:
|
||||||
$code, add $clause " "
|
$code, add $clause " "
|
||||||
@ -425,20 +425,14 @@ test:
|
|||||||
if ($i > 1):
|
if ($i > 1):
|
||||||
$code, add " or "
|
$code, add " or "
|
||||||
$code, add "\(mangle "branch value") == " ($line.$i as lua expr)
|
$code, add "\(mangle "branch value") == " ($line.$i as lua expr)
|
||||||
|
$code, add " then\n " ($action as lua)
|
||||||
$code, add ("
|
|
||||||
then
|
|
||||||
\;
|
|
||||||
") ($action as lua)
|
|
||||||
|
|
||||||
$clause = "\nelseif"
|
$clause = "\nelseif"
|
||||||
|
|
||||||
if ((size of "\$code") == 0):
|
if ((size of "\$code") == 0):
|
||||||
compile error at $body "'if' block has an empty body."
|
compile error at $body "'if' block has an empty body."
|
||||||
.."This means nothing would happen, so the 'if' block should be deleted."
|
"This means nothing would happen, so the 'if' block should be deleted."
|
||||||
|
|
||||||
$code, add "\nend --when"
|
$code, add "\nend --when"
|
||||||
|
|
||||||
return
|
return
|
||||||
Lua ("
|
Lua ("
|
||||||
do --if % is...
|
do --if % is...
|
||||||
|
@ -7,10 +7,12 @@ use "core/metaprogramming.nom"
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
(barf $msg) compiles to
|
(barf $msg) compiles to
|
||||||
.."error(\(=lua "\$msg and \($msg as lua expr) or 'nil'"), 0);"
|
"error(\(=lua "\$msg and \($msg as lua expr) or 'nil'"), 0);"
|
||||||
|
|
||||||
(assume $condition) compiles to:
|
(assume $condition) compiles to:
|
||||||
lua> "local \$assumption = 'Assumption failed: '..tostring((\$condition):get_source_code())"
|
lua> ("
|
||||||
|
local \$assumption = 'Assumption failed: '..tostring((\$condition):get_source_code())
|
||||||
|
")
|
||||||
|
|
||||||
return
|
return
|
||||||
Lua ("
|
Lua ("
|
||||||
@ -29,7 +31,8 @@ use "core/metaprogramming.nom"
|
|||||||
do
|
do
|
||||||
local \(mangle "a"), \(mangle "b") = \($a as lua expr), \($b as lua expr)
|
local \(mangle "a"), \(mangle "b") = \($a as lua expr), \($b as lua expr)
|
||||||
if \(mangle "a") ~= \(mangle "b") then
|
if \(mangle "a") ~= \(mangle "b") then
|
||||||
error(\(quote "\$assumption").."\\n"..tostring(\(mangle "a")).." != "..tostring(\(mangle "b")), 0)
|
error(\(quote "\$assumption").."\\n"..tostring(\(mangle "a")).." != "..tostring(\
|
||||||
|
..\(mangle "b")), 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
")
|
")
|
||||||
|
@ -16,7 +16,8 @@ $obj_by_id = {}
|
|||||||
set $obj_by_id's metatable to {.__mode = "v"}
|
set $obj_by_id's metatable to {.__mode = "v"}
|
||||||
$id_by_obj = {}
|
$id_by_obj = {}
|
||||||
set $id_by_obj's metatable to {
|
set $id_by_obj's metatable to {
|
||||||
.__mode = "k", .__index = (
|
.__mode = "k"
|
||||||
|
.__index =
|
||||||
for ($self $key):
|
for ($self $key):
|
||||||
if ($key == (nil)):
|
if ($key == (nil)):
|
||||||
return $self.$nil_surrogate
|
return $self.$nil_surrogate
|
||||||
@ -30,7 +31,6 @@ set $id_by_obj's metatable to {
|
|||||||
$self.$key = $id
|
$self.$key = $id
|
||||||
$obj_by_id.$id = $key
|
$obj_by_id.$id = $key
|
||||||
return $id
|
return $id
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
externally (uuid) means:
|
externally (uuid) means:
|
||||||
|
@ -13,10 +13,8 @@ use "core/collections.nom"
|
|||||||
# Literals:
|
# Literals:
|
||||||
test:
|
test:
|
||||||
assume (all of [inf, NaN, pi, tau, golden ratio, e]) or barf
|
assume (all of [inf, NaN, pi, tau, golden ratio, e]) or barf
|
||||||
.."math constants failed"
|
"math constants failed"
|
||||||
|
|
||||||
$nan = (NaN)
|
$nan = (NaN)
|
||||||
|
|
||||||
assume ($nan != $nan) or barf "NaN failed"
|
assume ($nan != $nan) or barf "NaN failed"
|
||||||
[infinity, inf] all compile to "math.huge"
|
[infinity, inf] all compile to "math.huge"
|
||||||
[not a number, NaN, nan] all compile to "(0/0)"
|
[not a number, NaN, nan] all compile to "(0/0)"
|
||||||
@ -42,29 +40,23 @@ test:
|
|||||||
[absolute value $, | $ |, abs $] all compile to "math.abs(\($ as lua expr))"
|
[absolute value $, | $ |, abs $] all compile to "math.abs(\($ as lua expr))"
|
||||||
|
|
||||||
[square root $, square root of $, √ $, sqrt $] all compile to
|
[square root $, square root of $, √ $, sqrt $] all compile to
|
||||||
.."math.sqrt(\($ as lua expr))"
|
"math.sqrt(\($ as lua expr))"
|
||||||
|
|
||||||
[sine $, sin $] all compile to "math.sin(\($ as lua expr))"
|
[sine $, sin $] all compile to "math.sin(\($ as lua expr))"
|
||||||
|
|
||||||
[cosine $, cos $] all compile to "math.cos(\($ as lua expr))"
|
[cosine $, cos $] all compile to "math.cos(\($ as lua expr))"
|
||||||
[tangent $, tan $] all compile to "math.tan(\($ as lua expr))"
|
[tangent $, tan $] all compile to "math.tan(\($ as lua expr))"
|
||||||
[arc sine $, asin $] all compile to "math.asin(\($ as lua expr))"
|
[arc sine $, asin $] all compile to "math.asin(\($ as lua expr))"
|
||||||
[arc cosine $, acos $] all compile to "math.acos(\($ as lua expr))"
|
[arc cosine $, acos $] all compile to "math.acos(\($ as lua expr))"
|
||||||
[arc tangent $, atan $] all compile to "math.atan(\($ as lua expr))"
|
[arc tangent $, atan $] all compile to "math.atan(\($ as lua expr))"
|
||||||
[arc tangent $y / $x, atan2 $y $x] all compile to
|
[arc tangent $y / $x, atan2 $y $x] all compile to
|
||||||
.."math.atan2(\($y as lua expr), \($x as lua expr))"
|
"math.atan2(\($y as lua expr), \($x as lua expr))"
|
||||||
|
|
||||||
[hyperbolic sine $, sinh $] all compile to "math.sinh(\($ as lua expr))"
|
[hyperbolic sine $, sinh $] all compile to "math.sinh(\($ as lua expr))"
|
||||||
|
|
||||||
[hyperbolic cosine $, cosh $] all compile to "math.cosh(\($ as lua expr))"
|
[hyperbolic cosine $, cosh $] all compile to "math.cosh(\($ as lua expr))"
|
||||||
[hyperbolic tangent $, tanh $] all compile to "math.tanh(\($ as lua expr))"
|
[hyperbolic tangent $, tanh $] all compile to "math.tanh(\($ as lua expr))"
|
||||||
[e^ $, exp $] all compile to "math.exp(\($ as lua expr))"
|
[e^ $, exp $] all compile to "math.exp(\($ as lua expr))"
|
||||||
[natural log $, ln $, log $] all compile to "math.log(\($ as lua expr))"
|
[natural log $, ln $, log $] all compile to "math.log(\($ as lua expr))"
|
||||||
[log $ base $base, log base $base of $] all compile to
|
[log $ base $base, log base $base of $] all compile to
|
||||||
.."math.log(\($ as lua expr), \($base as lua expr))"
|
"math.log(\($ as lua expr), \($base as lua expr))"
|
||||||
|
|
||||||
(floor $) compiles to "math.floor(\($ as lua expr))"
|
(floor $) compiles to "math.floor(\($ as lua expr))"
|
||||||
|
|
||||||
[ceiling $, ceil $] all compile to "math.ceil(\($ as lua expr))"
|
[ceiling $, ceil $] all compile to "math.ceil(\($ as lua expr))"
|
||||||
[round $, $ rounded] all compile to "math.floor(\($ as lua expr) + .5)"
|
[round $, $ rounded] all compile to "math.floor(\($ as lua expr) + .5)"
|
||||||
test:
|
test:
|
||||||
@ -204,7 +196,7 @@ externally (seed random with $) means:
|
|||||||
(seed random) parses as (seed random with (=lua "os.time()"))
|
(seed random) parses as (seed random with (=lua "os.time()"))
|
||||||
[random number, random, rand] all compile to "math.random()"
|
[random number, random, rand] all compile to "math.random()"
|
||||||
[random int $n, random integer $n, randint $n] all compile to
|
[random int $n, random integer $n, randint $n] all compile to
|
||||||
.."math.random(\($n as lua expr))"
|
"math.random(\($n as lua expr))"
|
||||||
|
|
||||||
[random from $low to $high, random number from $low to $high, rand $low $high]
|
[random from $low to $high, random number from $low to $high, rand $low $high]
|
||||||
..all compile to "math.random(\($low as lua expr), \($high as lua expr))"
|
..all compile to "math.random(\($low as lua expr), \($high as lua expr))"
|
||||||
|
@ -210,13 +210,11 @@ test:
|
|||||||
[$1, $2] = [1, 2]
|
[$1, $2] = [1, 2]
|
||||||
swap $1 and $2
|
swap $1 and $2
|
||||||
assume (($1 == 2) and ($2 == 1)) or barf
|
assume (($1 == 2) and ($2 == 1)) or barf
|
||||||
.."'parse % as %' failed on 'swap % and %'"
|
"'parse % as %' failed on 'swap % and %'"
|
||||||
|
|
||||||
[$tmp, $tmp2] = [1, 2]
|
[$tmp, $tmp2] = [1, 2]
|
||||||
|
|
||||||
swap $tmp and $tmp2
|
swap $tmp and $tmp2
|
||||||
assume (($tmp == 2) and ($tmp2 == 1)) or barf
|
assume (($tmp == 2) and ($tmp2 == 1)) or barf
|
||||||
.."'parse % as %' variable mangling failed."
|
"'parse % as %' variable mangling failed."
|
||||||
|
|
||||||
($actions all parse as $body) compiles to:
|
($actions all parse as $body) compiles to:
|
||||||
lua> ("
|
lua> ("
|
||||||
@ -310,7 +308,12 @@ externally ($ is $kind syntax tree) means
|
|||||||
|
|
||||||
($tree with $t -> $replacement) compiles to ("
|
($tree with $t -> $replacement) compiles to ("
|
||||||
\($tree as lua expr):map(function(\($t as lua expr))
|
\($tree as lua expr):map(function(\($t as lua expr))
|
||||||
\(=lua "\$replacement.type == 'Block' and \($replacement as lua) or 'return '..\($replacement as lua expr)")
|
\(
|
||||||
|
=lua ("
|
||||||
|
\$replacement.type == 'Block' and \($replacement as lua) or 'return '..\
|
||||||
|
..\($replacement as lua expr)
|
||||||
|
")
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
")
|
")
|
||||||
|
|
||||||
@ -360,7 +363,13 @@ externally (match $tree with $patt) means:
|
|||||||
")
|
")
|
||||||
|
|
||||||
test:
|
test:
|
||||||
assume ((quote "one\n\"two\"") == "\"one\\n\\\"two\\\"\"")
|
assume
|
||||||
|
(
|
||||||
|
quote ("
|
||||||
|
one
|
||||||
|
"two"
|
||||||
|
")
|
||||||
|
) == "\"one\\n\\\"two\\\"\""
|
||||||
|
|
||||||
(quote $s) compiles to "tostring(\($s as lua expr)):as_lua()"
|
(quote $s) compiles to "tostring(\($s as lua expr)):as_lua()"
|
||||||
test:
|
test:
|
||||||
@ -400,7 +409,7 @@ test:
|
|||||||
assume (run \(return \(\(5) + \(5)))) == 10
|
assume (run \(return \(\(5) + \(5)))) == 10
|
||||||
(run $nomsu_code) compiles to "run_1_in(\($nomsu_code as lua expr), _ENV)"
|
(run $nomsu_code) compiles to "run_1_in(\($nomsu_code as lua expr), _ENV)"
|
||||||
[compile $block, compiled $block, $block compiled] all compile to
|
[compile $block, compiled $block, $block compiled] all compile to
|
||||||
.."compile(\($block as lua))"
|
"compile(\($block as lua))"
|
||||||
|
|
||||||
test:
|
test:
|
||||||
(foo) means:
|
(foo) means:
|
||||||
@ -443,4 +452,6 @@ test:
|
|||||||
")
|
")
|
||||||
|
|
||||||
externally (Nomsu version) means:
|
externally (Nomsu version) means:
|
||||||
return "\(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)"
|
return ("
|
||||||
|
\(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)
|
||||||
|
")
|
||||||
|
@ -17,7 +17,7 @@ test:
|
|||||||
($x >= $y) compiles to "(\($x as lua expr) >= \($y as lua expr))"
|
($x >= $y) compiles to "(\($x as lua expr) >= \($y as lua expr))"
|
||||||
[$a is $b, $a == $b] all compile to "(\($a as lua expr) == \($b as lua expr))"
|
[$a is $b, $a == $b] all compile to "(\($a as lua expr) == \($b as lua expr))"
|
||||||
[$a isn't $b, $a is not $b, $a not= $b, $a != $b] all compile to
|
[$a isn't $b, $a is not $b, $a not= $b, $a != $b] all compile to
|
||||||
.."(\($a as lua expr) ~= \($b as lua expr))"
|
"(\($a as lua expr) ~= \($b as lua expr))"
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
@ -91,11 +91,13 @@ test:
|
|||||||
$y = "inner"
|
$y = "inner"
|
||||||
set global x local y
|
set global x local y
|
||||||
assume (($foozle == "inner") and ($y == "outer")) or barf
|
assume (($foozle == "inner") and ($y == "outer")) or barf
|
||||||
.."'with external' failed."
|
"'with external' failed."
|
||||||
|
|
||||||
(with external $externs $body) compiles to:
|
(with external $externs $body) compiles to:
|
||||||
$body_lua = ($body as lua)
|
$body_lua = ($body as lua)
|
||||||
lua> "\$body_lua:remove_free_vars(table.map(\$externs, function(v) return compile(v):text() end))"
|
lua> ("
|
||||||
|
\$body_lua:remove_free_vars(table.map(\$externs, function(v) return compile(v):text() end))
|
||||||
|
")
|
||||||
return $body_lua
|
return $body_lua
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@ -120,6 +122,7 @@ test:
|
|||||||
\$defs:add("local ", item_lua, ";")
|
\$defs:add("local ", item_lua, ";")
|
||||||
end
|
end
|
||||||
")
|
")
|
||||||
|
|
||||||
return
|
return
|
||||||
Lua ("
|
Lua ("
|
||||||
do
|
do
|
||||||
@ -133,7 +136,7 @@ test:
|
|||||||
assume ((5 wrapped around 2) == 1) or barf "mod not working"
|
assume ((5 wrapped around 2) == 1) or barf "mod not working"
|
||||||
|
|
||||||
[$x wrapped around $y, $x mod $y] all compile to
|
[$x wrapped around $y, $x mod $y] all compile to
|
||||||
.."((\($x as lua expr)) % (\($y as lua expr)))"
|
"((\($x as lua expr)) % (\($y as lua expr)))"
|
||||||
|
|
||||||
# 3-part chained comparisons
|
# 3-part chained comparisons
|
||||||
# (uses a lambda to avoid re-evaluating middle value, while still being an expression)
|
# (uses a lambda to avoid re-evaluating middle value, while still being an expression)
|
||||||
@ -144,10 +147,8 @@ test:
|
|||||||
return 1
|
return 1
|
||||||
assume (0 <= (one) <= 2) or barf "Three-way chained comparison failed."
|
assume (0 <= (one) <= 2) or barf "Three-way chained comparison failed."
|
||||||
assume ($calls == 1) or barf
|
assume ($calls == 1) or barf
|
||||||
.."Three-way comparison evaluated middle value multiple times"
|
"Three-way comparison evaluated middle value multiple times"
|
||||||
|
|
||||||
($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)
|
||||||
|
|
||||||
($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)
|
||||||
($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)
|
||||||
($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)
|
||||||
@ -183,31 +184,30 @@ test:
|
|||||||
lua> "if \((is jit) or ((Lua version) == "Lua 5.2")) then"
|
lua> "if \((is jit) or ((Lua version) == "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
|
[$x OR $y, $x | $y] all compile to
|
||||||
.."bit.bor(\($x as lua expr), \($y as lua expr))"
|
"bit.bor(\($x as lua expr), \($y as lua expr))"
|
||||||
|
|
||||||
[$x XOR $y, $x ~ $y] all compile to
|
[$x XOR $y, $x ~ $y] all compile to
|
||||||
.."bit.bxor(\($x as lua expr), \($y as lua expr))"
|
"bit.bxor(\($x as lua expr), \($y as lua expr))"
|
||||||
|
|
||||||
[$x AND $y, $x & $y] all compile to
|
[$x AND $y, $x & $y] all compile to
|
||||||
.."bit.band(\($x as lua expr), \($y as lua expr))"
|
"bit.band(\($x as lua expr), \($y as lua expr))"
|
||||||
|
|
||||||
[$x LSHIFT $shift, $x << $shift] all compile to
|
[$x LSHIFT $shift, $x << $shift] all compile to
|
||||||
.."bit.lshift(\($x as lua expr), \($shift as lua expr))"
|
"bit.lshift(\($x as lua expr), \($shift as lua expr))"
|
||||||
|
|
||||||
[$x RSHIFT $shift, $x >> $shift] all compile to
|
[$x RSHIFT $shift, $x >> $shift] all compile to
|
||||||
.."bit.rshift(\($x as lua expr), \($shift as lua expr))"
|
"bit.rshift(\($x as lua expr), \($shift as lua expr))"
|
||||||
|
|
||||||
lua> "else"
|
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 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 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))"
|
[$x AND $y, $x & $y] all compile to "(\($x as lua expr) & \($y as lua expr))"
|
||||||
[$x LSHIFT $shift, $x << $shift] all compile to
|
[$x LSHIFT $shift, $x << $shift] all compile to
|
||||||
.."(\($x as lua expr) << \($shift as lua expr))"
|
"(\($x as lua expr) << \($shift as lua expr))"
|
||||||
|
|
||||||
[$x RSHIFT $shift, $x >> $shift] all compile to
|
[$x RSHIFT $shift, $x >> $shift] all compile to
|
||||||
.."(\($x as lua expr) >> \($shift as lua expr))"
|
"(\($x as lua expr) >> \($shift as lua expr))"
|
||||||
|
|
||||||
lua> "end"
|
lua> "end"
|
||||||
|
|
||||||
|
@ -27,7 +27,14 @@ test:
|
|||||||
assume ("asdf", capitalized) == "Asdf"
|
assume ("asdf", capitalized) == "Asdf"
|
||||||
assume ("asdf", uppercase) == "ASDF"
|
assume ("asdf", uppercase) == "ASDF"
|
||||||
assume ("asdf", with "s" -> "X") == "aXdf"
|
assume ("asdf", with "s" -> "X") == "aXdf"
|
||||||
assume ("one\ntwo\n", lines) == ["one", "two", ""]
|
assume
|
||||||
|
("
|
||||||
|
one
|
||||||
|
two
|
||||||
|
|
||||||
|
"), lines
|
||||||
|
..== ["one", "two", ""]
|
||||||
|
|
||||||
($spec とは $body) parses as ($spec means $body)
|
($spec とは $body) parses as ($spec means $body)
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
@ -248,8 +248,7 @@ 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 long first argument that needs its own line" and also
|
say both "Very long first argument that needs its own line" and also
|
||||||
.."short second arg"
|
"short second arg"
|
||||||
|
|
||||||
(my favorite number) means (21 + 2)
|
(my favorite number) means (21 + 2)
|
||||||
|
|
||||||
# This can be nested:
|
# This can be nested:
|
||||||
@ -272,7 +271,11 @@ say "The square root of 2 is \(square root of 2)"
|
|||||||
# 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:
|
(debug only $body) compiles to:
|
||||||
if $DEBUG_ENABLED:
|
if $DEBUG_ENABLED:
|
||||||
return (Lua "-- Debug code:\n\($body as lua)")
|
return
|
||||||
|
Lua ("
|
||||||
|
-- Debug code:
|
||||||
|
\($body as lua)
|
||||||
|
")
|
||||||
..else:
|
..else:
|
||||||
return (Lua "-- (debug code removed for production)")
|
return (Lua "-- (debug code removed for production)")
|
||||||
$DEBUG_ENABLED = (yes)
|
$DEBUG_ENABLED = (yes)
|
||||||
|
@ -25,7 +25,7 @@ test:
|
|||||||
) != "inf"
|
) != "inf"
|
||||||
|
|
||||||
assume ((hash "\000") != (hash "\000\000\000\000\000")) or barf
|
assume ((hash "\000") != (hash "\000\000\000\000\000")) or barf
|
||||||
.."Incorrect hashing of null strings"
|
"Incorrect hashing of null strings"
|
||||||
|
|
||||||
if $use_sha1:
|
if $use_sha1:
|
||||||
assume ((hash "hello world") == "Kq5sNclPz7QV2+lfQIuc6R7oRu0=")
|
assume ((hash "hello world") == "Kq5sNclPz7QV2+lfQIuc6R7oRu0=")
|
||||||
|
@ -81,7 +81,7 @@ test:
|
|||||||
(object $classname extends $parent $class_body) compiles to:
|
(object $classname extends $parent $class_body) compiles to:
|
||||||
unless ($classname.type == "Action"):
|
unless ($classname.type == "Action"):
|
||||||
compile error at $classname
|
compile error at $classname
|
||||||
.."Expected this to be an action, not a \$classname.type"
|
"Expected this to be an action, not a \$classname.type"
|
||||||
|
|
||||||
for $ in $classname:
|
for $ in $classname:
|
||||||
unless ($ is text):
|
unless ($ is text):
|
||||||
|
@ -106,14 +106,14 @@ externally (a class named $classname with $members ((initialize $it)'s meaning))
|
|||||||
barf "Cannot set \$key, it's not one of the allowed member fields."
|
barf "Cannot set \$key, it's not one of the allowed member fields."
|
||||||
|
|
||||||
set $class's metatable to {
|
set $class's metatable to {
|
||||||
.__tostring = ($class -> $class.__type), .__call = (
|
.__tostring = ($class -> $class.__type)
|
||||||
|
.__call =
|
||||||
for ($class with $initial_values):
|
for ($class with $initial_values):
|
||||||
if ($initial_values == (nil)): return $class
|
if ($initial_values == (nil)): return $class
|
||||||
set $initial_values's metatable to $class
|
set $initial_values's metatable to $class
|
||||||
if $initial_values.set_up:
|
if $initial_values.set_up:
|
||||||
$initial_values, set up
|
$initial_values, set up
|
||||||
return $initial_values
|
return $initial_values
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((initialize)'s meaning):
|
if ((initialize)'s meaning):
|
||||||
@ -136,8 +136,15 @@ externally (a class named $classname with $members ((initialize $it)'s meaning))
|
|||||||
|
|
||||||
return
|
return
|
||||||
Lua ("
|
Lua ("
|
||||||
\$class_id = a_class_named_1_with(\(quote $classname.stub), \($members as lua)\((Lua ", function(\$class_id)\n \$body_lua\nend") if $class_body else "")\
|
\$class_id = a_class_named_1_with(\(quote $classname.stub), \($members as lua)\(
|
||||||
..)
|
(
|
||||||
|
Lua ("
|
||||||
|
, function(\$class_id)
|
||||||
|
\$body_lua
|
||||||
|
end
|
||||||
|
")
|
||||||
|
) if $class_body else ""
|
||||||
|
))
|
||||||
a_\$class_id = function(initial_values) return \($classname.stub, as lua id)(initial_values \
|
a_\$class_id = function(initial_values) return \($classname.stub, as lua id)(initial_values \
|
||||||
..or {}) end
|
..or {}) end
|
||||||
an_\$class_id, a_\($class_id)_with, an_\($class_id)_with = a_\$class_id, a_\$class_id, a_\$class_id
|
an_\$class_id, a_\($class_id)_with, an_\($class_id)_with = a_\$class_id, a_\$class_id, a_\$class_id
|
||||||
|
@ -24,7 +24,9 @@ use "lib/consolecolor.nom"
|
|||||||
$wildcard = ($(COMMAND LINE ARGS)."--wildcard" or "%*")
|
$wildcard = ($(COMMAND LINE ARGS)."--wildcard" or "%*")
|
||||||
$pattern = $(COMMAND LINE ARGS).extras.1
|
$pattern = $(COMMAND LINE ARGS).extras.1
|
||||||
if (any of [not $pattern, $pattern == "*", $pattern == "**"]):
|
if (any of [not $pattern, $pattern == "*", $pattern == "**"]):
|
||||||
barf "Usage: nomsu -t find [-l] [--wildcard=<wildcard>] <pattern>, where <pattern> is valid Nomsu code"
|
barf ("
|
||||||
|
Usage: nomsu -t find [-l] [--wildcard=<wildcard>] <pattern>, where <pattern> is valid Nomsu code
|
||||||
|
")
|
||||||
$pattern = ($pattern, with "\$wildcard\$wildcard" -> "$multi_wildcard")
|
$pattern = ($pattern, with "\$wildcard\$wildcard" -> "$multi_wildcard")
|
||||||
$pattern = ($pattern, with $wildcard -> "$wildcard")
|
$pattern = ($pattern, with $wildcard -> "$wildcard")
|
||||||
$pattern_tree = ($pattern parsed)
|
$pattern_tree = ($pattern parsed)
|
||||||
@ -47,7 +49,9 @@ $pattern_tree = ($pattern parsed)
|
|||||||
return (yes)
|
return (yes)
|
||||||
$filenames = ($(COMMAND LINE ARGS).extras, from 2 to -1)
|
$filenames = ($(COMMAND LINE 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 -"
|
say ("
|
||||||
|
Warning: searching stdin (ctrl-d to abort). To avoid this message, use nomsu -t find -
|
||||||
|
")
|
||||||
$filenames = ["stdin"]
|
$filenames = ["stdin"]
|
||||||
|
|
||||||
for $filename in $filenames:
|
for $filename in $filenames:
|
||||||
@ -58,7 +62,11 @@ for $filename in $filenames:
|
|||||||
try:
|
try:
|
||||||
$tree = ($code parsed)
|
$tree = ($code parsed)
|
||||||
..and if it barfs $msg:
|
..and if it barfs $msg:
|
||||||
say (red "\$filename failed to parse:\n\$msg")
|
say
|
||||||
|
red ("
|
||||||
|
\$filename failed to parse:
|
||||||
|
\$msg
|
||||||
|
")
|
||||||
$tree = (nil)
|
$tree = (nil)
|
||||||
|
|
||||||
unless $tree:
|
unless $tree:
|
||||||
@ -68,8 +76,9 @@ for $filename in $filenames:
|
|||||||
for $t in recursive $tree:
|
for $t in recursive $tree:
|
||||||
if ($t matches $pattern_tree):
|
if ($t matches $pattern_tree):
|
||||||
$line_num = ($file, line number at $t.source.start)
|
$line_num = ($file, line number at $t.source.start)
|
||||||
$results,
|
$results, add {
|
||||||
add {.line = $line_num, .text = "\(blue "\$filename:\$line_num:")\n\(source lines of $t)"}
|
.line = $line_num, .text = "\(blue "\$filename:\$line_num:")\n\(source lines of $t)"
|
||||||
|
}
|
||||||
|
|
||||||
for $sub in $t:
|
for $sub in $t:
|
||||||
if ($sub is syntax tree):
|
if ($sub is syntax tree):
|
||||||
|
@ -12,7 +12,9 @@ use "lib/os.nom"
|
|||||||
|
|
||||||
$filenames = $(COMMAND LINE ARGS).extras
|
$filenames = $(COMMAND LINE ARGS).extras
|
||||||
if ((#$filenames) == 0):
|
if ((#$filenames) == 0):
|
||||||
say "Warning: reading from stdin (ctrl-d to abort). To avoid this message, use nomsu -t format -"
|
say ("
|
||||||
|
Warning: reading from stdin (ctrl-d to abort). To avoid this message, use nomsu -t format -
|
||||||
|
")
|
||||||
$filenames = ["stdin"]
|
$filenames = ["stdin"]
|
||||||
|
|
||||||
for $filename in $filenames:
|
for $filename in $filenames:
|
||||||
@ -31,7 +33,7 @@ for $filename in $filenames:
|
|||||||
|
|
||||||
if ($tree and (not $formatted)):
|
if ($tree and (not $formatted)):
|
||||||
$formatted =
|
$formatted =
|
||||||
.."\$leading_indent\($tree as nomsu, text, with "\n" -> "\n\$leading_indent")"
|
"\$leading_indent\($tree as nomsu, text, with "\n" -> "\n\$leading_indent")"
|
||||||
|
|
||||||
if $formatted:
|
if $formatted:
|
||||||
if $(COMMAND LINE ARGS)."-i":
|
if $(COMMAND LINE ARGS)."-i":
|
||||||
|
@ -17,7 +17,8 @@ externally (help) means:
|
|||||||
|
|
||||||
say ("
|
say ("
|
||||||
|
|
||||||
\(bright)\(underscore)Welcome to the Nomsu v\(Nomsu version) interactive console!\(reset color)
|
\(bright)\(underscore)Welcome to the Nomsu v\(Nomsu version) interactive console!\
|
||||||
|
..\(reset color)
|
||||||
press 'enter' twice to run a command
|
press 'enter' twice to run a command
|
||||||
|
|
||||||
")
|
")
|
||||||
|
@ -13,7 +13,12 @@ for $filename in $(COMMAND LINE ARGS).extras: use $filename
|
|||||||
$tests = {: for $s = $t in $TESTS: add (=lua "Source:from_string(\$s)") = $t}
|
$tests = {: for $s = $t in $TESTS: add (=lua "Source:from_string(\$s)") = $t}
|
||||||
for $filename in $(COMMAND LINE ARGS).extras:
|
for $filename in $(COMMAND LINE ARGS).extras:
|
||||||
$file = (read file $filename)
|
$file = (read file $filename)
|
||||||
$version = ($file, matching "#![^\n]* nomsu %-V[ ]*([^\n]*)")
|
$version =
|
||||||
|
$file, matching ("
|
||||||
|
#![^
|
||||||
|
]* nomsu %-V[ ]*([^
|
||||||
|
]*)
|
||||||
|
")
|
||||||
$file_tests = []
|
$file_tests = []
|
||||||
for $src = $test in $tests:
|
for $src = $test in $tests:
|
||||||
if ($src.filename == $filename):
|
if ($src.filename == $filename):
|
||||||
|
@ -24,10 +24,8 @@ for $filename in $(COMMAND LINE ARGS).extras:
|
|||||||
$tree = ($code parsed $start_version)
|
$tree = ($code parsed $start_version)
|
||||||
$uptree =
|
$uptree =
|
||||||
$tree upgraded from ($start_version or ($tree.version or (Nomsu version))) to
|
$tree upgraded from ($start_version or ($tree.version or (Nomsu version))) to
|
||||||
..$version
|
$version
|
||||||
|
|
||||||
$text = "\$leading_indent\($uptree as nomsu, text, with "\n" -> "\n\$leading_indent")"
|
$text = "\$leading_indent\($uptree as nomsu, text, with "\n" -> "\n\$leading_indent")"
|
||||||
|
|
||||||
when:
|
when:
|
||||||
$inplace:
|
$inplace:
|
||||||
say "Upgraded \$filename"
|
say "Upgraded \$filename"
|
||||||
|
Loading…
Reference in New Issue
Block a user