Nomsu v7.0.0 API
This page has a listing of the Nomsu API, automatically generated using this script. Click on an action's name to see its definition and a link to where it's defined in the codebase. This API documentation does not include complete descriptions of what each action does, but hopefully the actions are descriptively-enough named, and have readable-enough source code that it will be easy to understand what they do.
lib/base64/init.nom
-
base64 $str
View source in Bitbucket repo
[base64 $str, base64 encode $str, $str base64] all mean: $chars = [] 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: 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) $chars, add $b64_chars.(($bytes.3 & 63) + 1) 2: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) $chars, add $b64_chars.((($bytes.2 & 15) << 2) + 1) $chars, add "=" 1: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + 1) $chars, add "=" $chars, add "=" return ($chars, joined)
-
base64 encode $str
View source in Bitbucket repo
[base64 $str, base64 encode $str, $str base64] all mean: $chars = [] 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: 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) $chars, add $b64_chars.(($bytes.3 & 63) + 1) 2: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) $chars, add $b64_chars.((($bytes.2 & 15) << 2) + 1) $chars, add "=" 1: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + 1) $chars, add "=" $chars, add "=" return ($chars, joined)
-
$str base64
View source in Bitbucket repo
[base64 $str, base64 encode $str, $str base64] all mean: $chars = [] 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: 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) $chars, add $b64_chars.(($bytes.3 & 63) + 1) 2: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1) $chars, add $b64_chars.((($bytes.2 & 15) << 2) + 1) $chars, add "=" 1: $chars, add $b64_chars.((($bytes.1 & 3) << 4) + 1) $chars, add "=" $chars, add "=" return ($chars, joined)
-
chr $
View source in Bitbucket repo
(chr $) means (=lua "string.char(\$)")
-
decode base64 $str
View source in Bitbucket repo
[decode base64 $str, $str base64 decoded, base64 decode $str] all mean: $chars = [] 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))) if (($str, character ($i + 3)) == "="): stop $chars, add (chr ((($indices.3 & 3) << 6) + $indices.4)) return ($chars, joined)
-
$str base64 decoded
View source in Bitbucket repo
[decode base64 $str, $str base64 decoded, base64 decode $str] all mean: $chars = [] 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))) if (($str, character ($i + 3)) == "="): stop $chars, add (chr ((($indices.3 & 3) << 6) + $indices.4)) return ($chars, joined)
-
base64 decode $str
View source in Bitbucket repo
[decode base64 $str, $str base64 decoded, base64 decode $str] all mean: $chars = [] 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))) if (($str, character ($i + 3)) == "="): stop $chars, add (chr ((($indices.3 & 3) << 6) + $indices.4)) return ($chars, joined)
lib/commandline/init.nom
-
command line program with $args $body
View source in Bitbucket repo
(command line program with $args $body) parses as: external ((run with $args) means $body) if (this file was run directly): run with (the command line arguments)
-
usage $
View source in Bitbucket repo
(usage $) means: say "Usage: \$" exit 1
lib/compatibility/compatibility.nom
-
upgrade to $version via $upgrade_fn
View source in Bitbucket repo
(upgrade to $version via $upgrade_fn) means: $UPGRADES.$version = $upgrade_fn
-
upgrade action $stub to $version via $upgrade_fn
View source in Bitbucket repo
(upgrade action $stub to $version via $upgrade_fn) means: $ACTION_UPGRADES.$version.$stub = $upgrade_fn
-
upgrade $tree to $version as $body
View source in Bitbucket repo
(upgrade $tree to $version as $body) parses as upgrade to $version via ($ -> ($, with ($tree -> $body)))
-
upgrade action $actions to $version as $body
View source in Bitbucket repo
(upgrade action $actions to $version as $body) compiles to: if ($actions is "Action" syntax tree): $actions = \[\$actions] $lua = (Lua "") for $action in $actions: $replacements = {} for $i in (1 to #$action): if ($action.$i is "Var" syntax tree): $replacements.($action.$i.1) = "\(\$tree as lua id)[\$i]" define mangler (make tree $t) means: when: ($t is "Var" syntax tree): if $replacements.($t.1): return $replacements.($t.1) ..else: external ($needs_mangle = (yes)) return (" SyntaxTree{type=\(quote $t.type), source=\(quote "\($t.source)"), \(quote (mangle $t.1))} ") ($t is syntax tree): $args = [] for ($k = $v) in $t: if ((type of $k) == "a Number"): $args, add (make tree $v) ..else: $args, add "\($k)=\(make tree $v)" return "SyntaxTree{\($args, joined with ", ")}" else: return (quote $t) unless ("\$lua" == ""): $lua, add "\n" $retval = (make tree $body) $lua, add Lua (" upgrade_action_1_to_2_via(\(quote $action.stub), \($version as lua expr), function(\ ..\(\$tree as lua id)) return \$retval end) ") return $lua
-
$tree upgraded from $start_version to $end_version
View source in Bitbucket repo
[ $tree upgraded from $start_version to $end_version $tree upgraded to $end_version from $start_version ] all mean: unless ($tree is syntax tree): return $tree ($ver as version list) means: if ($ver is "Text"): return (($ as number) for $ in $ver matching "[0-9]+") return $ver (Ver $) means: if ($ is "a List"): if ($.1 is "Text"): return {.lib = $.1, .version = ($, from 2)} return {.version = $} [$lib, $ver] = ($, match "(.*)/([0-9.]+)") if $lib: return {.lib = $lib, .version = ($ver as version list)} return {.version = ($ as version list)} $start = (Ver $start_version) $end = (Ver $end_version) $end.lib or= $start.lib assume $start.lib == $end.lib $seen = {} $versions = {} for ($v = $) in $UPGRADES: $versions.$v = (yes) for ($v = $) in $ACTION_UPGRADES: $versions.$v = (yes) $versions = [: for ($v = $) in $versions: $v2 = (Ver $v) if ($v2.lib == $start.lib): if ($start.version < $v2.version <= $end.version): add $v ] sort $versions by $ -> ($ as version list) $curr_version = $start_version for $ver in $versions: $tree = SyntaxTree {: for ($k = $v) in $tree: add $k = ($v upgraded from $curr_version to $ver)} if (($tree.type == "Action") and $ACTION_UPGRADES.$ver): $(upgrade 1) = $ACTION_UPGRADES.$ver.($tree, get stub) if $(upgrade 1): $tree = (upgrade $tree) go to (next version) if $UPGRADES.$ver: $tree = ($UPGRADES.$ver $tree $ver) go to (next version) --- (next version) --- $curr_version = $ver if ($tree.version != $end_version): $tree = (SyntaxTree {: for ($k = $v) in $tree: add $k = $v}) $tree.version = $end_version if $tree.shebang: unless ($end_version is "Text"): $end_version = ($end_version, joined with ".") $tree.shebang = "#!/usr/bin/env nomsu -V\$end_version\n" return $tree
-
$tree upgraded to $end_version from $start_version
View source in Bitbucket repo
[ $tree upgraded from $start_version to $end_version $tree upgraded to $end_version from $start_version ] all mean: unless ($tree is syntax tree): return $tree ($ver as version list) means: if ($ver is "Text"): return (($ as number) for $ in $ver matching "[0-9]+") return $ver (Ver $) means: if ($ is "a List"): if ($.1 is "Text"): return {.lib = $.1, .version = ($, from 2)} return {.version = $} [$lib, $ver] = ($, match "(.*)/([0-9.]+)") if $lib: return {.lib = $lib, .version = ($ver as version list)} return {.version = ($ as version list)} $start = (Ver $start_version) $end = (Ver $end_version) $end.lib or= $start.lib assume $start.lib == $end.lib $seen = {} $versions = {} for ($v = $) in $UPGRADES: $versions.$v = (yes) for ($v = $) in $ACTION_UPGRADES: $versions.$v = (yes) $versions = [: for ($v = $) in $versions: $v2 = (Ver $v) if ($v2.lib == $start.lib): if ($start.version < $v2.version <= $end.version): add $v ] sort $versions by $ -> ($ as version list) $curr_version = $start_version for $ver in $versions: $tree = SyntaxTree {: for ($k = $v) in $tree: add $k = ($v upgraded from $curr_version to $ver)} if (($tree.type == "Action") and $ACTION_UPGRADES.$ver): $(upgrade 1) = $ACTION_UPGRADES.$ver.($tree, get stub) if $(upgrade 1): $tree = (upgrade $tree) go to (next version) if $UPGRADES.$ver: $tree = ($UPGRADES.$ver $tree $ver) go to (next version) --- (next version) --- $curr_version = $ver if ($tree.version != $end_version): $tree = (SyntaxTree {: for ($k = $v) in $tree: add $k = $v}) $tree.version = $end_version if $tree.shebang: unless ($end_version is "Text"): $end_version = ($end_version, joined with ".") $tree.shebang = "#!/usr/bin/env nomsu -V\$end_version\n" return $tree
-
$tree upgraded from $start_version
View source in Bitbucket repo
($tree upgraded from $start_version) means $tree upgraded from $start_version to $(NOMSU VERSION)
-
$tree upgraded to $end_version
View source in Bitbucket repo
($tree upgraded to $end_version) means $tree upgraded from ($tree.version or $(NOMSU VERSION)) to $end_version
-
$tree upgraded
View source in Bitbucket repo
($tree upgraded) means $tree upgraded from ($tree.version or $(NOMSU VERSION)) to $(NOMSU VERSION)
lib/core/collections.nom
-
entries in $dict
View source in Bitbucket repo
(entries in $dict) parses as [: for ($k = $v) in $dict: add {.key = $k, .value = $v}]
-
keys in $dict
View source in Bitbucket repo
[keys in $dict, keys of $dict] all parse as [: for ($k = $v) in $dict: add $k]
-
keys of $dict
View source in Bitbucket repo
[keys in $dict, keys of $dict] all parse as [: for ($k = $v) in $dict: add $k]
-
values in $dict
View source in Bitbucket repo
[values in $dict, values of $dict] all parse as [: for ($k = $v) in $dict: add $v]
-
values of $dict
View source in Bitbucket repo
[values in $dict, values of $dict] all parse as [: for ($k = $v) in $dict: add $v]
-
set $dict's metatable to $metatable
View source in Bitbucket repo
(set $dict's metatable to $metatable) compiles to "setmetatable(\($dict as lua expr), \($metatable as lua expr));"
-
$'s metatable
View source in Bitbucket repo
[$'s metatable, $'metatable] all compile to "getmetatable(\($ as lua expr))"
-
$'metatable
View source in Bitbucket repo
[$'s metatable, $'metatable] all compile to "getmetatable(\($ as lua expr))"
-
$dict with fallback $key -> $value
View source in Bitbucket repo
($dict with fallback $key -> $value) compiles to (" (function(d) local mt = {} for k,v in pairs(getmetatable(d) or {}) do mt[k] = v end mt.__index = function(self, \($key as lua expr)) local value = \($value as lua expr) self[\($key as lua expr)] = value return value end return setmetatable(d, mt) end)(\($dict as lua expr)) ")
-
sort $items
View source in Bitbucket repo
(sort $items) compiles to "table.sort(\($items as lua expr));"
-
sort $items by $item = $key_expr
View source in Bitbucket repo
[sort $items by $item = $key_expr, sort $items by $item -> $key_expr] ..all parse as do: $keys = ({} with fallback $item -> $key_expr) lua> "table.sort(\$items, function(x,y) return \$keys[x] < \$keys[y] end)"
-
sort $items by $item -> $key_expr
View source in Bitbucket repo
[sort $items by $item = $key_expr, sort $items by $item -> $key_expr] ..all parse as do: $keys = ({} with fallback $item -> $key_expr) lua> "table.sort(\$items, function(x,y) return \$keys[x] < \$keys[y] end)"
-
$items sorted
View source in Bitbucket repo
[$items sorted, sorted $items] all mean: $copy = [: for $ in $items: add $] sort $copy return $copy
-
sorted $items
View source in Bitbucket repo
[$items sorted, sorted $items] all mean: $copy = [: for $ in $items: add $] sort $copy return $copy
-
$items sorted by $item = $key
View source in Bitbucket repo
[$items sorted by $item = $key, $items sorted by $item -> $key] all parse as result of: $copy = [: for $ in $items: add $] sort $copy by $item = $key return $copy
-
$items sorted by $item -> $key
View source in Bitbucket repo
[$items sorted by $item = $key, $items sorted by $item -> $key] all parse as result of: $copy = [: for $ in $items: add $] sort $copy by $item = $key return $copy
-
unique $items
View source in Bitbucket repo
(unique $items) means: $unique = [] $seen = {} for $ in $items: unless $seen.$: $unique, add $ $seen.$ = (yes) return $unique
-
$first to $last by $step
View source in Bitbucket repo
($first to $last by $step) means setmetatable {.first = $first, .last = $last, .step = $step} $range_mt
-
$first to $last
View source in Bitbucket repo
($first to $last) means setmetatable {.first = $first, .last = $last, .step = 1} $range_mt
lib/core/control_flow.nom
-
do nothing
View source in Bitbucket repo
(do nothing) compiles to ""
-
if $condition $if_body
View source in Bitbucket repo
(if $condition $if_body) compiles to (" if \($condition as lua expr) then \($if_body as lua) end ")
-
unless $condition $unless_body
View source in Bitbucket repo
(unless $condition $unless_body) parses as (if (not $condition) $unless_body)
-
if $condition $if_body else $else_body
View source in Bitbucket repo
[ if $condition $if_body else $else_body, unless $condition $else_body else $if_body ] all compile to (" if \($condition as lua expr) then \($if_body as lua) else \($else_body as lua) end ")
-
unless $condition $else_body else $if_body
View source in Bitbucket repo
[ if $condition $if_body else $else_body, unless $condition $else_body else $if_body ] all compile to (" if \($condition as lua expr) then \($if_body as lua) else \($else_body as lua) end ")
-
else $
View source in Bitbucket repo
(else $) compiles to: at (this tree) fail (" Compile error: This 'else' is not connected to any 'if' or 'unless' condition. Hint: You should probably have a ".." in front of the "else", to indicate that it's attached \ ..to the previous condition. ")
-
$when_true_expr if $condition else $when_false_expr
View source in Bitbucket repo
[ $when_true_expr if $condition else $when_false_expr $when_true_expr if $condition otherwise $when_false_expr $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 equivalent of a conditional expression: (cond and if_true or if_false) if {.Text, .List, .Dict, .Number}.($when_true_expr.type): return Lua (" (\($condition as lua expr) and \($when_true_expr as lua expr) or \ ..\($when_false_expr as lua expr)) ") ..else: ### 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 (" ((function() if \($condition as lua expr) then return \($when_true_expr as lua expr) else return \($when_false_expr as lua expr) end end)()) ")
-
$when_true_expr if $condition otherwise $when_false_expr
View source in Bitbucket repo
[ $when_true_expr if $condition else $when_false_expr $when_true_expr if $condition otherwise $when_false_expr $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 equivalent of a conditional expression: (cond and if_true or if_false) if {.Text, .List, .Dict, .Number}.($when_true_expr.type): return Lua (" (\($condition as lua expr) and \($when_true_expr as lua expr) or \ ..\($when_false_expr as lua expr)) ") ..else: ### 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 (" ((function() if \($condition as lua expr) then return \($when_true_expr as lua expr) else return \($when_false_expr as lua expr) end end)()) ")
-
$when_false_expr unless $condition else $when_true_expr
View source in Bitbucket repo
[ $when_true_expr if $condition else $when_false_expr $when_true_expr if $condition otherwise $when_false_expr $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 equivalent of a conditional expression: (cond and if_true or if_false) if {.Text, .List, .Dict, .Number}.($when_true_expr.type): return Lua (" (\($condition as lua expr) and \($when_true_expr as lua expr) or \ ..\($when_false_expr as lua expr)) ") ..else: ### 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 (" ((function() if \($condition as lua expr) then return \($when_true_expr as lua expr) else return \($when_false_expr as lua expr) end end)()) ")
-
$when_false_expr unless $condition then $when_true_expr
View source in Bitbucket repo
[ $when_true_expr if $condition else $when_false_expr $when_true_expr if $condition otherwise $when_false_expr $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 equivalent of a conditional expression: (cond and if_true or if_false) if {.Text, .List, .Dict, .Number}.($when_true_expr.type): return Lua (" (\($condition as lua expr) and \($when_true_expr as lua expr) or \ ..\($when_false_expr as lua expr)) ") ..else: ### 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 (" ((function() if \($condition as lua expr) then return \($when_true_expr as lua expr) else return \($when_false_expr as lua expr) end end)()) ")
-
--- $label ---
View source in Bitbucket repo
(--- $label ---) compiles to (" ::label_\( ($label.stub, as lua id) if ($label.type == "Action") else $label as lua identifier ):: ")
-
go to $label
View source in Bitbucket repo
(go to $label) compiles to (" goto label_\( ($label.stub, as lua id) if ($label.type == "Action") else $label as lua identifier ) ")
-
stop $var
View source in Bitbucket repo
(stop $var) compiles to: if $var: return Lua "goto stop_\($var as lua identifier)" ..else: return Lua "break"
-
do next $var
View source in Bitbucket repo
(do next $var) compiles to: if $var: return Lua "goto continue_\($var as lua identifier)" ..else: return Lua "goto continue"
-
---stop $var ---
View source in Bitbucket repo
(---stop $var ---) compiles to "::stop_\($var as lua identifier)::"
-
---next $var ---
View source in Bitbucket repo
(---next $var ---) compiles to "::continue_\($var as lua identifier)::"
-
repeat while $condition $body
View source in Bitbucket repo
(repeat while $condition $body) compiles to: $lua = Lua (" while \($condition as lua expr) do \($body as lua) ") if ($body, contains \(do next)): $lua, add "\n ::continue::" $lua, add "\nend --while-loop" return $lua
-
repeat $body
View source in Bitbucket repo
(repeat $body) parses as (repeat while (yes) $body)
-
repeat until $condition $body
View source in Bitbucket repo
(repeat until $condition $body) parses as (repeat while (not $condition) $body)
-
for $var in $iterable $body
View source in Bitbucket repo
(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 if (($var.type == "Action") and ($var.stub == "1 =")): [$key, $value] = [$var.1, $var.3] ..else: [$key, $value] = [nil, $var] unless $value: at (this tree) fail "No value here" ### Numeric loop: if (($iterable.type == "Action") and (($iterable, get stub) == "1 to")): [$start, $stop] = [$iterable.1, $iterable.3] $loop = Lua (" local _start = \($start as lua expr) for \($value as lua identifier)=_start,\($stop as lua expr) do ") if $key: $loop, add (" local \($key as lua identifier) = \($value as lua identifier) - _start + 1; ") go to (loop set) ### 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 = Lua (" local _start, _step = \($start as lua expr), \($step as lua expr); for \($value as lua identifier)=_start,\($stop as lua expr),_step do ") if $key: $loop, add (" local \($key as lua identifier) = (\($value as lua identifier) - _start)/_step + 1 ") go to (loop set) ### for $ in (...): if $key: $loop = Lua (" 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" --- (loop set) --- ### TODO: don't always wrap in block $lua = Lua (" do -- for-loop \$loop \; ") $lua, add ($body as lua) if ($body, contains \(do next)): $lua, add "\n ::continue::" if ($key and ($body, contains \(do next \$key))): $lua, add "\n " (\(---next \$key ---) as lua) if ($body, contains \(do next \$value)): $lua, add "\n " (\(---next \$value ---) as lua) $lua, add "\n end" if ($key and ($body, contains \(stop \$key))): $lua, add "\n " (\(---stop \$key ---) as lua) if ($body, contains \(stop \$value)): $lua, add "\n " (\(---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)] return $lua
-
repeat $n times $body
View source in Bitbucket repo
(repeat $n times $body) parses as (for (=lua "_i") in (1 to $n by 1) $body)
-
when $body
View source in Bitbucket repo
(when $body) compiles to: $code = (Lua "") $clause = "if" $else_allowed = (yes) unless ($body.type == "Block"): at $body fail (" Compile error: 'if' expected a Block, but got a \($body.type). Hint: Perhaps you forgot to put a ':' after 'if'? ") for $line in $body: unless (($line.type == "Action") and (#$line >= 2)) and $line.(#$line) is "Block" syntax tree ..: at $line fail (" Compile error: Invalid line for the body of an 'if' block. Hint: Each line should contain one or more conditional expressions followed by a block, \ ..or "else" followed by a block. ") $action = $line.(#$line) 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): 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 \ ..block around it. Otherwise, make sure the 'else' block comes last. ") $code, add "\nelse\n " ($action as lua) $else_allowed = (no) ..else: $code, add $clause " " 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): at $body fail (" Compile error: 'if' block has an empty body. Hint: This means nothing would happen, so the 'if' block should be deleted. ") $code, add "\nend --when" return $code
-
if $branch_value is $body
View source in Bitbucket repo
[if $branch_value is $body, when $branch_value is $body] all compile to: $code = (Lua "") $clause = "if" $else_allowed = (yes) define mangler unless ($body.type == "Block"): at $body fail (" Compile error: 'if' expected a Block, but got a \($body.type). Hint: Perhaps you forgot to put a ':' after the 'is'? ") for $line in $body: unless (($line.type == "Action") and (#$line >= 2)) and $line.(#$line) is "Block" syntax tree ..: at $line fail (" Compile error: Invalid line for 'if' block. 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)): 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): 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 \ ..block around it. Otherwise, make sure the 'else' block comes last. ") $code, add "\nelse\n " ($action as lua) $else_allowed = (no) ..else: $code, add $clause " " 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): at $body fail (" Compile error: 'if' block has an empty body. Hint: This means nothing would happen, so the 'if' block should be deleted. ") $code, add "\nend --when" return Lua (" do --if $ is... local \(mangle "branch value") = \($branch_value as lua expr) \$code end -- if $ is... ")
-
when $branch_value is $body
View source in Bitbucket repo
[if $branch_value is $body, when $branch_value is $body] all compile to: $code = (Lua "") $clause = "if" $else_allowed = (yes) define mangler unless ($body.type == "Block"): at $body fail (" Compile error: 'if' expected a Block, but got a \($body.type). Hint: Perhaps you forgot to put a ':' after the 'is'? ") for $line in $body: unless (($line.type == "Action") and (#$line >= 2)) and $line.(#$line) is "Block" syntax tree ..: at $line fail (" Compile error: Invalid line for 'if' block. 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)): 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): 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 \ ..block around it. Otherwise, make sure the 'else' block comes last. ") $code, add "\nelse\n " ($action as lua) $else_allowed = (no) ..else: $code, add $clause " " 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): at $body fail (" Compile error: 'if' block has an empty body. Hint: This means nothing would happen, so the 'if' block should be deleted. ") $code, add "\nend --when" return Lua (" do --if $ is... local \(mangle "branch value") = \($branch_value as lua expr) \$code end -- if $ is... ")
-
do $action
View source in Bitbucket repo
(do $action) compiles to (" do \($action as lua) end -- do ")
-
result of $body
View source in Bitbucket repo
(result of $body) compiles to "\(\(->(\$body)) as lua)()"
-
recurse $v on $x
View source in Bitbucket repo
(recurse $v on $x) compiles to Lua "table.insert(_stack_\($v as lua expr), \($x as lua expr))"
-
for $var in recursive $structure $body
View source in Bitbucket repo
(for $var in recursive $structure $body) compiles to: $lua = Lua (" do local _stack_\($var as lua expr) = a_List{\($structure as lua expr)} while #_stack_\($var as lua expr) > 0 do \($var as lua expr) = table.remove(_stack_\($var as lua expr), 1) \($body as lua) ") if ($body, contains \(do next)): $lua, add "\n ::continue::" if ($body, contains \(do next \$var)): $lua, add "\n \(\(---next \$var ---) as lua)" $lua, add "\n end -- Recursive loop" if ($body, contains \(stop \$var)): $lua, add "\n \(\(---stop \$var ---) as lua)" $lua, add "\nend -- Recursive scope" return $lua
lib/core/coroutines.nom
-
coroutine $body
View source in Bitbucket repo
(coroutine $body) parses as (coroutine from ->$body)
-
$ is a dead coroutine
View source in Bitbucket repo
($ is a dead coroutine) means ((lua type of $) == "thread") and ((coroutine status of $) == "dead")
lib/core/errors.nom
-
fail $msg
View source in Bitbucket repo
(fail $msg) compiles to (" at_1_fail(\(quote (this tree).source), \(($msg as lua expr) if $msg else (quote "A failure was triggered here'")) ) ")
-
assume $condition
View source in Bitbucket repo
(assume $condition) compiles to: if ($condition.type == "IndexChain"): return Lua (" do -- Assumption: local _thing, _key = \($condition.1 as lua expr), \($condition.2.1 as lua expr) if not _thing[_key] then _key = type_of(_key) == 'Text' and _key:as_lua() or _1_as_text(_key) at_1_fail(\(quote "\($condition.source)"), "Assumption failed: \($condition.1 as nomsu, text) does not have a value for ".._key..".") end end ") if ($condition.type == "Action"): when $condition.stub is: "1 ==": return Lua (" do -- Assumption: local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr) if _a ~= _b then _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a) _b = type_of(_b) == 'Text' and _b:as_lua() or _1_as_text(_b) at_1_fail(\(quote "\($condition.1.source)"), "Assumption failed: This value was ".._a.." but it was expected to be ".._b..".") end end ") "1 !=": return Lua (" do -- Assumption: local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr) if _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 was ".._a.." but it wasn't expected to be.") end end ") "1 >" "1 <" "1 >=" "1 <=": return Lua (" do -- Assumption: local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr) if not (_a \($condition.2) _b) then _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a) _b = type_of(_b) == 'Text' and _b:as_lua() or _1_as_text(_b) at_1_fail(\(quote "\($condition.1.source)"), "Assumption failed: This value was ".._a..", but it was expected to be \ ..\($condition.2)".._b..".") end end ") "1 is": return Lua (" do -- Assumption: local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr) 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.") end end ") "1 isn ' t" "1 is not": return Lua (" do -- Assumption: local _a, _b = \($condition.1 as lua expr), \($condition.(#$condition) as lua expr) 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.") end end ") return Lua (" if not \($condition as lua expr) then at_1_fail(\(quote "\($condition.source)"), "Assumption failed: This assumption did not hold.") end ")
-
assume $a == $b
View source in Bitbucket repo
(assume $a == $b) parses as (assume ($a == $b))
-
assume $a != $b
View source in Bitbucket repo
(assume $a != $b) parses as (assume ($a != $b))
-
test that $condition
View source in Bitbucket repo
(test that $condition) parses as (assume $condition)
-
try $action if it succeeds $success if it fails with $msg $fallback
View source in Bitbucket repo
[ 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): $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): $msg_lua = ($msg as lua expr) 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)] $fallback_lua, prepend "-- Failure:\n" return Lua (" do local _fell_through = false local _result = {xpcall(function() \($action as lua) _fell_through = true end, enhance_error)} if _result[1] then \$success_lua else \$fallback_lua end end ")
-
try $action if it fails with $msg $fallback if it succeeds $success
View source in Bitbucket repo
[ 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): $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): $msg_lua = ($msg as lua expr) 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)] $fallback_lua, prepend "-- Failure:\n" return Lua (" do local _fell_through = false local _result = {xpcall(function() \($action as lua) _fell_through = true end, enhance_error)} if _result[1] then \$success_lua else \$fallback_lua end end ")
-
try $action
View source in Bitbucket repo
(try $action) parses as try $action if it succeeds (do nothing) if it fails (do nothing)
-
try $action if it fails $fallback
View source in Bitbucket repo
(try $action if it fails $fallback) parses as try $action if it succeeds (do nothing) if it fails $fallback
-
try $action if it fails with $msg $fallback
View source in Bitbucket repo
(try $action if it fails with $msg $fallback) parses as try $action if it succeeds (do nothing) if it fails with $msg $fallback
-
try $action if it succeeds $success
View source in Bitbucket repo
(try $action if it succeeds $success) parses as try $action if it succeeds $success if it fails (do nothing)
-
try $action if it fails $fallback if it succeeds $success
View source in Bitbucket repo
(try $action if it fails $fallback if it succeeds $success) parses as try $action if it fails with (=lua "") $fallback if it succeeds $success
-
try $action if it succeeds $success if it fails $fallback
View source in Bitbucket repo
(try $action if it succeeds $success if it fails $fallback) parses as try $action if it succeeds $success if it fails with (=lua "") $fallback
-
do $action then always $final_action
View source in Bitbucket repo
(do $action then always $final_action) compiles to (" do -- do/then always local _fell_through = false local _results = {xpcall(function() \($action as lua) _fell_through = true end, enhance_error)} \($final_action as lua) if not _results[1] then error(_results[2], 0) end if not _fell_through then return table.unpack(_results, 2) end end ")
lib/core/id.nom
-
uuid
View source in Bitbucket repo
(uuid) means: ### Set all the other bits to randomly (or pseudo-randomly) chosen values. $bytes = [ ### 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 randint (2 ^ (1 * 8 - 2)), randint (2 ^ (1 * 8)), randint (2 ^ (3 * 8)) ### 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. $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. $bytes.4 += 0xC0 return (=lua "('%08x-%04x-%04x-%02x%02x-%6x%6x'):format(unpack(\$bytes))")
-
id of $
View source in Bitbucket repo
[id of $, $'s id, $'id] all mean $id_by_obj.$
-
$'s id
View source in Bitbucket repo
[id of $, $'s id, $'id] all mean $id_by_obj.$
-
$'id
View source in Bitbucket repo
[id of $, $'s id, $'id] all mean $id_by_obj.$
lib/core/io.nom
-
say (*extra arguments*)
View source in Bitbucket repo
(say (*extra arguments*)) means: for $ in (1 to (select "#" (*extra arguments*))): $arg = (select $ (*extra arguments*)) $io.write ($arg as text) $io.write "\n" $io.flush()
-
say $message inline
View source in Bitbucket repo
(say $message inline) means ($io.write $message)
-
ask $prompt
View source in Bitbucket repo
(ask $prompt) means: $io.write $prompt return ($io.read())
lib/core/math.nom
-
infinity
View source in Bitbucket repo
[infinity, inf] all compile to "math.huge"
-
inf
View source in Bitbucket repo
[infinity, inf] all compile to "math.huge"
-
not a number
View source in Bitbucket repo
[not a number, NaN, nan] all compile to "(0/0)"
-
NaN
View source in Bitbucket repo
[not a number, NaN, nan] all compile to "(0/0)"
-
nan
View source in Bitbucket repo
[not a number, NaN, nan] all compile to "(0/0)"
-
pi
View source in Bitbucket repo
[pi, Pi, PI] all compile to "math.pi"
-
Pi
View source in Bitbucket repo
[pi, Pi, PI] all compile to "math.pi"
-
PI
View source in Bitbucket repo
[pi, Pi, PI] all compile to "math.pi"
-
tau
View source in Bitbucket repo
[tau, Tau, TAU] all compile to "(2*math.pi)"
-
Tau
View source in Bitbucket repo
[tau, Tau, TAU] all compile to "(2*math.pi)"
-
TAU
View source in Bitbucket repo
[tau, Tau, TAU] all compile to "(2*math.pi)"
-
golden ratio
View source in Bitbucket repo
(golden ratio) compiles to "((1+math.sqrt(5))/2)"
-
e
View source in Bitbucket repo
(e) compiles to "math.exp(1)"
-
round $
View source in Bitbucket repo
[round $, $ rounded] all mean (floor ($ + 0.5))
-
$ rounded
View source in Bitbucket repo
[round $, $ rounded] all mean (floor ($ + 0.5))
-
$n to the nearest $rounder
View source in Bitbucket repo
($n to the nearest $rounder) means ($rounder * (floor ($n / $rounder + 0.5)))
-
all of $items
View source in Bitbucket repo
[all of $items, all $items] all mean: for $ in $items: unless $: return (no) return (yes)
-
all $items
View source in Bitbucket repo
[all of $items, all $items] all mean: for $ in $items: unless $: return (no) return (yes)
-
not all of $items
View source in Bitbucket repo
[not all of $items, not all $items] all parse as (not (all of $items))
-
not all $items
View source in Bitbucket repo
[not all of $items, not all $items] all parse as (not (all of $items))
-
any of $items
View source in Bitbucket repo
[any of $items, any $items] all mean: for $ in $items: if $: return (yes) return (no)
-
any $items
View source in Bitbucket repo
[any of $items, any $items] all mean: for $ in $items: if $: return (yes) return (no)
-
none of $items
View source in Bitbucket repo
[none of $items, none $items] all parse as (not (any of $items))
-
none $items
View source in Bitbucket repo
[none of $items, none $items] all parse as (not (any of $items))
-
sum of $items
View source in Bitbucket repo
[sum of $items, sum $items] all mean: $total = 0 for $ in $items: $total += $ return $total
-
sum $items
View source in Bitbucket repo
[sum of $items, sum $items] all mean: $total = 0 for $ in $items: $total += $ return $total
-
product of $items
View source in Bitbucket repo
[product of $items, product $items] all mean: $prod = 1 for $ in $items: $prod *= $ return $prod
-
product $items
View source in Bitbucket repo
[product of $items, product $items] all mean: $prod = 1 for $ in $items: $prod *= $ return $prod
-
avg of $items
View source in Bitbucket repo
[avg of $items, average of $items] all mean ((sum of $items) / #$items)
-
average of $items
View source in Bitbucket repo
[avg of $items, average of $items] all mean ((sum of $items) / #$items)
-
min of $items
View source in Bitbucket repo
[min of $items, smallest of $items, lowest of $items] all mean: $best = (nil) for $ in $items: if (($best == (nil)) or ($ < $best)): $best = $ return $best
-
smallest of $items
View source in Bitbucket repo
[min of $items, smallest of $items, lowest of $items] all mean: $best = (nil) for $ in $items: if (($best == (nil)) or ($ < $best)): $best = $ return $best
-
lowest of $items
View source in Bitbucket repo
[min of $items, smallest of $items, lowest of $items] all mean: $best = (nil) for $ in $items: if (($best == (nil)) or ($ < $best)): $best = $ return $best
-
max of $items
View source in Bitbucket repo
[max of $items, biggest of $items, largest of $items, highest of $items] all mean: $best = (nil) for $ in $items: if (($best == (nil)) or ($ > $best)): $best = $ return $best
-
biggest of $items
View source in Bitbucket repo
[max of $items, biggest of $items, largest of $items, highest of $items] all mean: $best = (nil) for $ in $items: if (($best == (nil)) or ($ > $best)): $best = $ return $best
-
largest of $items
View source in Bitbucket repo
[max of $items, biggest of $items, largest of $items, highest of $items] all mean: $best = (nil) for $ in $items: if (($best == (nil)) or ($ > $best)): $best = $ return $best
-
highest of $items
View source in Bitbucket repo
[max of $items, biggest of $items, largest of $items, highest of $items] all mean: $best = (nil) for $ in $items: if (($best == (nil)) or ($ > $best)): $best = $ return $best
-
min of $items by $item = $value_expr
View source in Bitbucket repo
(min of $items by $item = $value_expr) parses as result of: $best = (nil) $best_key = (nil) for $item in $items: $key = $value_expr if (($best == (nil)) or ($key < $best_key)): $best = $item $best_key = $key return $best
-
max of $items by $item = $value_expr
View source in Bitbucket repo
(max of $items by $item = $value_expr) parses as result of: $best = (nil) $best_key = (nil) for $item in $items: $key = $value_expr if (($best == (nil)) or ($key > $best_key)): $best = $item $best_key = $key return $best
-
$ clamped between $min and $max
View source in Bitbucket repo
($ clamped between $min and $max) means: when: ($ < $min): return $min ($ > $max): return $max else: return $
-
$ smoothed by $smoothness
View source in Bitbucket repo
($ smoothed by $smoothness) means: $ = ($ clamped between 0 and 1) if ($smoothness == 0): return $ $k = (2 ^ $smoothness) if ($ < 0.5): return (0.5 * (2 * $) ^ $k) ..else: return (1 - 0.5 * (2 - 2 * $) ^ $k)
-
$lo to $hi mixed by $amount
View source in Bitbucket repo
($lo to $hi mixed by $amount) means: $ = ($amount clamped between 0 and 1) return ((1 - $) * $lo + $ * $hi)
-
$nums mixed by $amount
View source in Bitbucket repo
($nums mixed by $amount) means: $ = ($amount clamped between 0 and 1) $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))
-
seed random with $
View source in Bitbucket repo
(seed random with $) means: lua> (" math.randomseed(\$); for i=1,20 do math.random(); end ")
-
seed random
View source in Bitbucket repo
(seed random) parses as (seed random with (=lua "os.time()"))
-
random number
View source in Bitbucket repo
[random number, random, rand] all compile to "math.random()"
-
random
View source in Bitbucket repo
[random number, random, rand] all compile to "math.random()"
-
rand
View source in Bitbucket repo
[random number, random, rand] all compile to "math.random()"
-
random int $n
View source in Bitbucket repo
[random int $n, random integer $n, randint $n] all compile to "math.random(\($n as lua expr))"
-
random integer $n
View source in Bitbucket repo
[random int $n, random integer $n, randint $n] all compile to "math.random(\($n as lua expr))"
-
randint $n
View source in Bitbucket repo
[random int $n, random integer $n, randint $n] all compile to "math.random(\($n as lua expr))"
-
random from $low to $high
View source in Bitbucket repo
[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))"
-
random number from $low to $high
View source in Bitbucket repo
[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))"
-
rand $low $high
View source in Bitbucket repo
[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))"
-
random choice from $elements
View source in Bitbucket repo
[random choice from $elements, random choice $elements, random $elements] ..all mean (=lua "\$elements[math.random(#\$elements)]")
-
random choice $elements
View source in Bitbucket repo
[random choice from $elements, random choice $elements, random $elements] ..all mean (=lua "\$elements[math.random(#\$elements)]")
-
random $elements
View source in Bitbucket repo
[random choice from $elements, random choice $elements, random $elements] ..all mean (=lua "\$elements[math.random(#\$elements)]")
lib/core/metaprogramming.nom
-
$actions all compile to $body
View source in Bitbucket repo
($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 \$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 for i=2,#\$actions do local alias = \$actions[i] local \$alias_args = a_List{"\(nomsu environment)", "\(this tree)", unpack(alias:get_args())} lua:add("\\nCOMPILE_RULES[", alias:get_stub():as_lua(), "] = ") if \$alias_args == \$args then lua:add("COMPILE_RULES[", \$actions[1]:get_stub():as_lua(), "]") else lua:add("function(") local \$compiled_alias_args = a_List{"\(nomsu environment)", "\(this tree)"}; for i=3,#\$alias_args do \$compiled_alias_args[i] = \(nomsu environment):compile(\$alias_args[i]) end lua:concat_add(\$compiled_alias_args, ", ") lua:add(") return COMPILE_RULES[", \$actions[1]:get_stub():as_lua(), "](") lua:concat_add(\$compiled_args, ", ") lua:add(") end") end end return lua ")
-
$action means $body
View source in Bitbucket repo
($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()) elseif \$action.type == "Action" then lua:add(\$action:get_stub():as_lua_id()) lua:add_free_vars({\$action:get_stub():as_lua_id()}) else at_1_fail(\$action, "Compile error: This is not an action or method call.") end lua:add(" = ", \(\(\$action -> \$body) as lua), ";") return lua ")
-
$actions all mean $body
View source in Bitbucket repo
($actions all mean $body) compiles to: 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()) or LuaCode(\$actions[1]:get_stub():as_lua_id())) local \$args = a_List(\$actions[1]:get_args()) for i=2,#\$actions do local alias = \$actions[i] local \$alias_args = a_List(alias:get_args()) lua:add("\\n") if alias.type == "MethodCall" then lua:add(\(nomsu environment):compile(alias[1]), ".", alias[2]:get_stub():as_lua_id()) else lua:add(alias:get_stub():as_lua_id()) lua:add_free_vars({alias_name}) end if \$args == \$alias_args then lua:add(" = ", first_def, ";") else lua:add(" = ", \(\(\$alias_args -> \$actions.1) as lua), ";") end end return lua ")
-
external $body
View source in Bitbucket repo
(external $body) compiles to: lua> (" local lua = \($body as lua) lua:remove_free_vars() return lua ")
-
with external $externals $body
View source in Bitbucket repo
(with external $externals $body) compiles to: lua> (" local body_lua = \($body as lua) local varnames = {} for i,\$v in ipairs(\$externals) do varnames[i] = \($v as lua):text() end body_lua:remove_free_vars(varnames) return body_lua ")
-
$actions all parse as $body
View source in Bitbucket repo
($actions all parse as $body) compiles to: lua> (" local replacements = {} if \$actions.type ~= "List" then at_1_fail(\$actions, "Compile error: This should be a list.") end for i,arg in ipairs(\$actions[1]:get_args()) do replacements[arg[1]] = \(nomsu environment):compile(arg):text() end local function make_tree(t) if SyntaxTree:is_instance(t) and t.type == "Var" then if replacements[t:as_var()] then return replacements[t:as_var()] else return "SyntaxTree{mangle("..t:as_var():as_lua().."), type="..t.type:as_lua(\ ..)..", source=".._1_as_text(t.source):as_lua().."}" end elseif SyntaxTree:is_instance(t) then local ret = {} local i = 1 for k, v in pairs(t) do if k == i then ret[#ret+1] = make_tree(t[i]) i = i + 1 elseif k == "source" then ret[#ret+1] = k.."= ".._1_as_text(v):as_lua() elseif lua_type_of(k) == 'string' and k:is_a_lua_id() then ret[#ret+1] = k.."= "..make_tree(v) else ret[#ret+1] = "["..make_tree(k).."]= "..make_tree(v) end end return "SyntaxTree{"..table.concat(ret, ", ").."}" elseif lua_type_of(t) == 'number' then return _1_as_text(t) else return t:as_lua() end end local \$new_body = LuaCode:from(\$body.source, "local mangle = mangler()", "\\nreturn ", make_tree(\$body)) return \(\(\$actions all compile to \$new_body) as lua) ")
-
$action parses as $body
View source in Bitbucket repo
[$action parses as $body] all parse as ([$action] all parse as $body)
-
$tree as lua expr
View source in Bitbucket repo
($tree as lua expr) compiles to \(nomsu environment, \$tree as lua expr)
-
$var as lua identifier
View source in Bitbucket repo
[$var as lua identifier, $var as lua id] all mean: lua> (" local lua = \($var as lua) if not lua:text():is_a_lua_id() then at_1_fail(\$var, "Compile error: ".. "This is supposed to be something that compiles to a valid Lua identifier. ".. "Hint: This should probably be a variable.") end return lua ")
-
$var as lua id
View source in Bitbucket repo
[$var as lua identifier, $var as lua id] all mean: lua> (" local lua = \($var as lua) if not lua:text():is_a_lua_id() then at_1_fail(\$var, "Compile error: ".. "This is supposed to be something that compiles to a valid Lua identifier. ".. "Hint: This should probably be a variable.") end return lua ")
-
*extra arguments*
View source in Bitbucket repo
(*extra arguments*) compiles to "..."
-
$ is syntax tree
View source in Bitbucket repo
($ is syntax tree) compiles to "SyntaxTree:is_instance(\($ as lua expr))"
-
$ is $kind syntax tree
View source in Bitbucket repo
($ is $kind syntax tree) means =lua "SyntaxTree:is_instance(\$) and \$.type == \$kind"
-
match $tree with $patt
View source in Bitbucket repo
(match $tree with $patt) means: lua> (" if \$patt.type == "Var" then return a_Dict{[\$patt:as_var()]=\$tree} end if \$patt.type == "Action" and \$patt:get_stub() ~= \$tree:get_stub() then return nil end if #\$patt ~= #\$tree then return nil end local matches = a_Dict{} for \($i)=1,#\$patt do if SyntaxTree:is_instance(\$tree[\$i]) then local submatch = \(match $tree.$i with $patt.$i) if not submatch then return nil end for k,v in pairs(submatch) do if matches[k] and matches[k] ~= v then return nil end matches[k] = v end end end return matches ")
-
quote $
View source in Bitbucket repo
(quote $) means ($ as text, as lua)
-
$ is text
View source in Bitbucket repo
($ is text) means (=lua "\(lua type of $) == 'string'")
-
$ is not text
View source in Bitbucket repo
[$ is not text, $ isn't text] all mean (=lua "\(lua type of $) ~= 'string'")
-
$ isn't text
View source in Bitbucket repo
[$ is not text, $ isn't text] all mean (=lua "\(lua type of $) ~= 'string'")
-
type of $
View source in Bitbucket repo
(type of $) means: lua> (" local mt = getmetatable(\$) if mt and mt.__type then return mt.__type end if \$ == nil then return 'nil' end local lua_type = \(lua type of $) return 'a '..lua_type:capitalized() ")
-
$ is $type
View source in Bitbucket repo
($ is $type) means: lua> (" local class = getmetatable(\$) ::check_parent:: if not class or not class.__type then return 'a '..\(lua type of $):capitalized() == \$type end if class.__type == \$type then return true end local class_mt = getmetatable(class) if class_mt.__index and class_mt.__index ~= class then class = class_mt.__index goto check_parent end return false ")
-
$ isn't $type
View source in Bitbucket repo
[$ isn't $type, $ is not $type] all parse as (not ($ is $type))
-
$ is not $type
View source in Bitbucket repo
[$ isn't $type, $ is not $type] all parse as (not ($ is $type))
-
$type tree with (*extra arguments*)
View source in Bitbucket repo
($type tree with (*extra arguments*)) means SyntaxTree (=lua "{type=\$type, ...}")
-
$type tree from $source
View source in Bitbucket repo
($type tree from $source) means SyntaxTree (=lua "{type=\$type, source=\$source}")
-
$type tree from $source with (*extra arguments*)
View source in Bitbucket repo
($type tree from $source with (*extra arguments*)) means SyntaxTree (=lua "{type=\$type, source=\$source, ...}")
-
return (*extra arguments*)
View source in Bitbucket repo
(return (*extra arguments*)) compiles to: lua> (" local lua = \(Lua "do return ") for i=1,select('#',...) do if i > 1 then lua:add(", ") end lua:add(\(nomsu environment):compile((select(i, ...)))) end lua:add(" end") return lua ")
-
return Lua (*extra arguments*)
View source in Bitbucket repo
(return Lua (*extra arguments*)) compiles to \(return (Lua \(*extra arguments*)))
-
yes
View source in Bitbucket repo
(yes) compiles to "(true)"
-
no
View source in Bitbucket repo
(no) compiles to "(false)"
-
nothing
View source in Bitbucket repo
[nothing, nil, null] all compile to "(nil)"
-
nil
View source in Bitbucket repo
[nothing, nil, null] all compile to "(nil)"
-
null
View source in Bitbucket repo
[nothing, nil, null] all compile to "(nil)"
-
command line args
View source in Bitbucket repo
(command line args) compiles to "COMMAND_LINE_ARGS"
-
at compilation $expr
View source in Bitbucket repo
(at compilation $expr) compiles to: lua> (" 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 return LuaCode(tostring(value)) end ")
-
using compile rules $rules do $body
View source in Bitbucket repo
(using compile rules $rules do $body) compiles to: lua> (" local env = \(new environment) env:run(\$rules) local lua = env:compile(\$body) return lua ")
-
$tree with $t -> $replacement
View source in Bitbucket repo
($tree with $t -> $replacement) parses as ($tree, with ($t -> $replacement))
-
tree $tree with vars $replacements
View source in Bitbucket repo
[tree $tree with vars $replacements, $tree with vars $replacements] all parse as $tree, with $replacements
-
$tree with vars $replacements
View source in Bitbucket repo
[tree $tree with vars $replacements, $tree with vars $replacements] all parse as $tree, with $replacements
-
$tree has subtree $match_tree
View source in Bitbucket repo
($tree has subtree $match_tree) parses as ($tree, contains $match_tree)
lib/core/operators.nom
-
$x < $y
View source in Bitbucket repo
($x < $y) compiles to "(\($x as lua expr) < \($y as lua expr))"
-
$x > $y
View source in Bitbucket repo
($x > $y) compiles to "(\($x as lua expr) > \($y as lua expr))"
-
$x <= $y
View source in Bitbucket repo
($x <= $y) compiles to "(\($x as lua expr) <= \($y as lua expr))"
-
$x >= $y
View source in Bitbucket repo
($x >= $y) compiles to "(\($x as lua expr) >= \($y as lua expr))"
-
$a == $b
View source in Bitbucket repo
($a == $b) compiles to "(\($a as lua expr) == \($b as lua expr))"
-
$a not= $b
View source in Bitbucket repo
[$a not= $b, $a != $b] all compile to "(\($a as lua expr) ~= \($b as lua expr))"
-
$a != $b
View source in Bitbucket repo
[$a not= $b, $a != $b] all compile to "(\($a as lua expr) ~= \($b as lua expr))"
-
$var = $value
View source in Bitbucket repo
($var = $value) compiles to: lua> (" local lua = LuaCode() if \$var.type == "List" then for i, \$assignment in ipairs(\$var) do if i > 1 then lua:add(", ") end local assignment_lua = \($assignment as lua expr) lua:add(assignment_lua) if \$assignment.type == 'Var' and \$assignment[1].type ~= "MethodCall" then lua:add_free_vars({assignment_lua:text()}) end end lua:add(' = ') if \$value.type == "List" then if #\$value ~= #\$var then compile_error_at(\$value, "This assignment has too "..(#\$value > #\$var and "many" or "few").." values.", "Make sure it has the same number of values on the left and right hand side \ ..of the '=' operator.") end for i, \$val in ipairs(\$value) do if i > 1 then lua:add(", ") end local val_lua = \($val as lua expr) lua:add(val_lua) end lua:add(";") else lua:add(\($value as lua expr), ';') end else local var_lua = \($var as lua expr) lua:add(var_lua) if \$var.type == 'Var' and \$var[1].type ~= "MethodCall" then lua:add_free_vars({var_lua:text()}) end lua:add(' = ', \($value as lua expr), ';') end return lua ")
-
with $assignments $body
View source in Bitbucket repo
(with $assignments $body) compiles to: lua> (" local \$defs = LuaCode() for i, \$item in ipairs(\$assignments) do if i > 1 then \$defs:add("\\n") end local item_lua = \($item as lua) if \$item.type == 'Action' and \$item.stub == '1 =' then item_lua:remove_free_vars(item_lua.free_vars) end \$defs:add("local ", item_lua, ";") end ") return Lua (" do \$defs \($body as lua) end -- 'with' block ")
-
$x wrapped around $y
View source in Bitbucket repo
[$x wrapped around $y, $x mod $y, $x % $y] all compile to "((\($x as lua expr)) % (\($y as lua expr)))"
-
$x mod $y
View source in Bitbucket repo
[$x wrapped around $y, $x mod $y, $x % $y] all compile to "((\($x as lua expr)) % (\($y as lua expr)))"
-
$x % $y
View source in Bitbucket repo
[$x wrapped around $y, $x mod $y, $x % $y] all compile to "((\($x as lua expr)) % (\($y as lua expr)))"
-
$x < $y < $z
View source in Bitbucket repo
($x < $y < $z) parses as ((($a $b $c) -> (($a < $b) and ($b < $c))) $x $y $z)
-
$x <= $y < $z
View source in Bitbucket repo
($x <= $y < $z) parses as ((($a $b $c) -> (($a <= $b) and ($b < $c))) $x $y $z)
-
$x < $y <= $z
View source in Bitbucket repo
($x < $y <= $z) parses as ((($a $b $c) -> (($a < $b) and ($b <= $c))) $x $y $z)
-
$x <= $y <= $z
View source in Bitbucket repo
($x <= $y <= $z) parses as ((($a $b $c) -> (($a <= $b) and ($b <= $c))) $x $y $z)
-
$x > $y > $z
View source in Bitbucket repo
($x > $y > $z) parses as ((($a $b $c) -> (($a > $b) and ($b > $c))) $x $y $z)
-
$x >= $y > $z
View source in Bitbucket repo
($x >= $y > $z) parses as ((($a $b $c) -> (($a >= $b) and ($b > $c))) $x $y $z)
-
$x > $y >= $z
View source in Bitbucket repo
($x > $y >= $z) parses as ((($a $b $c) -> (($a > $b) and ($b >= $c))) $x $y $z)
-
$x >= $y >= $z
View source in Bitbucket repo
($x >= $y >= $z) parses as ((($a $b $c) -> (($a >= $b) and ($b >= $c))) $x $y $z)
-
$x and $y
View source in Bitbucket repo
($x and $y) compiles to "(\($x as lua expr) and \($y as lua expr))"
-
$x or $y
View source in Bitbucket repo
($x or $y) compiles to "(\($x as lua expr) or \($y as lua expr))"
-
NOT $
View source in Bitbucket repo
[NOT $, ~$] all compile to "Bit.bnot(\($ as lua expr))"
-
~$
View source in Bitbucket repo
[NOT $, ~$] all compile to "Bit.bnot(\($ as lua expr))"
-
$x OR $y
View source in Bitbucket repo
[$x OR $y, $x | $y] all compile to "Bit.bor(\($x as lua expr), \($y as lua expr))"
-
$x | $y
View source in Bitbucket repo
[$x OR $y, $x | $y] all compile to "Bit.bor(\($x as lua expr), \($y as lua expr))"
-
$x XOR $y
View source in Bitbucket repo
[$x XOR $y, $x ~ $y] all compile to "Bit.bxor(\($x as lua expr), \($y as lua expr))"
-
$x ~ $y
View source in Bitbucket repo
[$x XOR $y, $x ~ $y] all compile to "Bit.bxor(\($x as lua expr), \($y as lua expr))"
-
$x AND $y
View source in Bitbucket repo
[$x AND $y, $x & $y] all compile to "Bit.band(\($x as lua expr), \($y as lua expr))"
-
$x & $y
View source in Bitbucket repo
[$x AND $y, $x & $y] all compile to "Bit.band(\($x as lua expr), \($y as lua expr))"
-
$x LSHIFT $shift
View source in Bitbucket repo
[$x LSHIFT $shift, $x << $shift] all compile to "Bit.lshift(\($x as lua expr), \($shift as lua expr))"
-
$x << $shift
View source in Bitbucket repo
[$x LSHIFT $shift, $x << $shift] all compile to "Bit.lshift(\($x as lua expr), \($shift as lua expr))"
-
$x RSHIFT $shift
View source in Bitbucket repo
[$x RSHIFT $shift, $x >> $shift] all compile to "Bit.rshift(\($x as lua expr), \($shift as lua expr))"
-
$x >> $shift
View source in Bitbucket repo
[$x RSHIFT $shift, $x >> $shift] all compile to "Bit.rshift(\($x as lua expr), \($shift as lua expr))"
-
NOT $
View source in Bitbucket repo
[NOT $, ~$] all compile to "(~(\($ as lua expr)))"
-
~$
View source in Bitbucket repo
[NOT $, ~$] all compile to "(~(\($ as lua expr)))"
-
$x OR $y
View source in Bitbucket repo
[$x OR $y, $x | $y] all compile to "(\($x as lua expr) | \($y as lua expr))"
-
$x | $y
View source in Bitbucket repo
[$x OR $y, $x | $y] all compile to "(\($x as lua expr) | \($y as lua expr))"
-
$x XOR $y
View source in Bitbucket repo
[$x XOR $y, $x ~ $y] all compile to "(\($x as lua expr) ~ \($y as lua expr))"
-
$x ~ $y
View source in Bitbucket repo
[$x XOR $y, $x ~ $y] all compile to "(\($x as lua expr) ~ \($y as lua expr))"
-
$x AND $y
View source in Bitbucket repo
[$x AND $y, $x & $y] all compile to "(\($x as lua expr) & \($y as lua expr))"
-
$x & $y
View source in Bitbucket repo
[$x AND $y, $x & $y] all compile to "(\($x as lua expr) & \($y as lua expr))"
-
$x LSHIFT $shift
View source in Bitbucket repo
[$x LSHIFT $shift, $x << $shift] all compile to "(\($x as lua expr) << \($shift as lua expr))"
-
$x << $shift
View source in Bitbucket repo
[$x LSHIFT $shift, $x << $shift] all compile to "(\($x as lua expr) << \($shift as lua expr))"
-
$x RSHIFT $shift
View source in Bitbucket repo
[$x RSHIFT $shift, $x >> $shift] all compile to "(\($x as lua expr) >> \($shift as lua expr))"
-
$x >> $shift
View source in Bitbucket repo
[$x RSHIFT $shift, $x >> $shift] all compile to "(\($x as lua expr) >> \($shift as lua expr))"
-
-$
View source in Bitbucket repo
-$ compiles to "(-(\($ as lua expr)))"
-
not $
View source in Bitbucket repo
(not $) compiles to "(not \($ as lua expr))"
-
#$list
View source in Bitbucket repo
[#$list, size of $list] all compile to: lua> (" local list_lua = \($list as lua expr) if list_lua:text() == "..." then return LuaCode("select('#', ...)") end return LuaCode("(#", list_lua, ")") ")
-
size of $list
View source in Bitbucket repo
[#$list, size of $list] all compile to: lua> (" local list_lua = \($list as lua expr) if list_lua:text() == "..." then return LuaCode("select('#', ...)") end return LuaCode("(#", list_lua, ")") ")
-
$list is empty
View source in Bitbucket repo
($list is empty) parses as (#$list == 0)
-
$var += $
View source in Bitbucket repo
($var += $) parses as ($var = (($var or 0) + $))
-
$var -= $
View source in Bitbucket repo
($var -= $) parses as ($var = (($var or 0) - $))
-
$var *= $
View source in Bitbucket repo
($var *= $) parses as ($var = (($var or 1) * $))
-
$var /= $
View source in Bitbucket repo
($var /= $) parses as ($var = ($var / $))
-
$var ^= $
View source in Bitbucket repo
($var ^= $) parses as ($var = ($var ^ $))
-
$var and= $
View source in Bitbucket repo
($var and= $) parses as ($var = ($var and $))
-
$var or= $
View source in Bitbucket repo
($var or= $) parses as ($var = ($var or $))
-
wrap $var around $
View source in Bitbucket repo
(wrap $var around $) parses as ($var = ($var wrapped around $))
lib/core/text.nom
-
$expr for $match in $text matching $patt
View source in Bitbucket repo
($expr for $match in $text matching $patt) compiles to: define mangler return Lua (" (function() local \(mangle "comprehension") = a_List{} for \($match as lua expr) in (\($text as lua expr)):gmatch(\($patt as lua expr)) do \(mangle "comprehension")[#\(mangle "comprehension")+1] = \($expr as lua) end return \(mangle "comprehension") end)() ")
-
$num as hex
View source in Bitbucket repo
($num as hex) means: if ($num < 0): return ("-0x%X", formatted with -$num) ..else: return ("0x%X", formatted with $num)
lib/core/things.nom
-
$parent class named $classname $(initialize $)
View source in Bitbucket repo
($parent class named $classname $(initialize $)) means: $class = {.__type = $classname} $class.__index = $class $class.class = $class $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 = for ($class with $initial_values): $initial_values or= {} set $initial_values's metatable to $class if $initial_values.set_up: $initial_values, set up return $initial_values } if $(initialize $): initialize $class for ($stub = $metamethod) in $METAMETHOD_MAP: if $class.($stub, as lua id): $class.$metamethod = $class.($stub, as lua id) return $class
-
$classname is $parent with $vars $class_body
View source in Bitbucket repo
($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." $class_id = ($classname.stub, as lua id) $class_body and= $class_body, with $t ->: for $v in $vars: if ($t == $v): 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)\( ( Lua (" , function(\$class_id) local self = \$class_id \($class_body as lua) end ") ) if $class_body else "" )) ") $lua, add free vars [$class_id] return $lua
lib/core/time.nom
-
now
View source in Bitbucket repo
(now) means: return (a Time ($os.date "*t"))
-
sleep for $t seconds
View source in Bitbucket repo
[sleep for $t seconds, sleep for $t second] all mean: ### 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
-
sleep for $t second
View source in Bitbucket repo
[sleep for $t seconds, sleep for $t second] all mean: ### 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
lib/file_hash/init.nom
-
hash $
View source in Bitbucket repo
(hash $) means: $hash = (=lua "\$hashlib.new('sha1'):final(\$)") return (base64 $hash)
-
hash $
View source in Bitbucket repo
(hash $) means: $bytes = ($, bytes) $hash = ($bytes.1 << 7) for $i in (2 to #$bytes): $hash = ((1000003 * $hash) ~ $bytes.$i) $hash = ($hash ~ #$bytes) return "\$hash"
-
file with hash $hash
View source in Bitbucket repo
(file with hash $hash) means: for $filename in (files for "."): $contents = (read file $filename) $file_hash = (hash $contents) if ($file_hash == $hash): return $filename
-
hash of file $filename
View source in Bitbucket repo
(hash of file $filename) parses as (hash (read file $filename))
lib/filesystem/init.nom
-
files for $path
View source in Bitbucket repo
(files for $path) means: $files = (=lua "Files.list(\$path)") if $files: $files = (List $files) return $files
-
write to file $filename $text
View source in Bitbucket repo
[ write to file $filename $text, to file $filename write $text write $text to file $filename ] all mean: unless ($filename != "stdin"): fail "Cannot write to stdin" lua> (" local file = io.open(\$filename, 'w') file:write(\$text) file:close() ")
-
to file $filename write $text
View source in Bitbucket repo
[ write to file $filename $text, to file $filename write $text write $text to file $filename ] all mean: unless ($filename != "stdin"): fail "Cannot write to stdin" lua> (" local file = io.open(\$filename, 'w') file:write(\$text) file:close() ")
-
write $text to file $filename
View source in Bitbucket repo
[ write to file $filename $text, to file $filename write $text write $text to file $filename ] all mean: unless ($filename != "stdin"): fail "Cannot write to stdin" lua> (" local file = io.open(\$filename, 'w') file:write(\$text) file:close() ")
-
source lines of $tree
View source in Bitbucket repo
(source lines of $tree) means: $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 $) ], joined with "\n"
lib/progressbar/init.nom
-
$x / $w progress bar
View source in Bitbucket repo
($x / $w progress bar) means: $x = ($x clamped between 0 and $w) if $(COLOR ENABLED): $bits = [" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"] $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)] ") ..else: ### Probably not unicode support either: return "[\("#", rep ($x, rounded down))\("-", rep ($w - ($x, rounded down)))]"
-
$w wide $ progress bar
View source in Bitbucket repo
($w wide $ progress bar) means (($ * $w) / $w progress bar)
lib/shell/init.nom
-
at $callsite =sh $cmd
View source in Bitbucket repo
(at $callsite =sh $cmd) means: $f = ($io.popen $cmd) $contents = ($f, read "*a") [$ok, $return_type, $return] = ($f, close) unless $ok: if ($return_type == "exit"): 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" return $contents
-
at $callsite sh> $cmd
View source in Bitbucket repo
(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" ..else: at $callsite fail "Command failure: Command `\($cmd)` was terminated by signal \$return"
-
=sh $cmd
View source in Bitbucket repo
(=sh $cmd) compiles to \(at \("Text" tree with "\($cmd.source)") =sh \$cmd)
-
sh> $cmd
View source in Bitbucket repo
(sh> $cmd) compiles to \(at \("Text" tree with "\($cmd.source)") sh> \$cmd)
lib/tools/find.nom
-
$tree matches $patt
View source in Bitbucket repo
($tree matches $patt) means: when: (not ($tree is syntax tree)): return (no) (($patt.type == "Var") and ($patt.1 == "wildcard")): return (yes) ($tree.type != $patt.type): return (no) ($tree.type == "Action"): if (($tree, get stub) != ($patt, get stub)): return (no) for $ in (1 to #$patt): if ($patt.$ is syntax tree): if ($patt.$ == \$multi_wildcard): return (yes) unless ($tree.$ matches $patt.$): return (no) ..else: unless ($tree.$ == $patt.$): return (no) if (#$tree != #$patt): return (no) return (yes)
lib/tools/install.nom
-
download $patts with $cmd
View source in Bitbucket repo
(download $patts with $cmd) means: $actions, add {.patterns = $patts, .cmd = $cmd}
-
run command $cmd
View source in Bitbucket repo
(run command $cmd) means: say $cmd try: sh> $cmd ..if it fails: say (" Sorry, the install failed. You may need to re-run as root with `sudo` in front of the command. ") exit 1
lib/tools/parse.nom
-
print tree $t at indent $indent
View source in Bitbucket repo
(print tree $t at indent $indent) means: if $t.type is: "Action": say "\($indent)Action (\($t.stub)):" for $arg in $t: if ($arg is syntax tree): print tree $arg at indent "\$indent " "MethodCall": say "\($indent)MethodCall on:" print tree $t.1 at indent "\$indent " print tree $t.2 at indent "\$indent " "Number": say "\$indent\($t.1)" "Var": say "\($indent)$\($t.1)" else: say "\$indent\($t.type):" for $arg in $t: when: ($arg is syntax tree): print tree $arg at indent "\$indent " else: say "\$indent \(quote $arg)"
-
$ as xml
View source in Bitbucket repo
($ as xml) means: when (type of $) is: "a Syntax Tree": $body = ([: for $bit in $: add ($bit as xml)], joined with " ") if ($.type == "Action"): return "
\($body) " ..else: return "<\($.type)>\($body)\($.type)>" "Text": return ( ($, with "&" -> "&", with "\"" -> """, with "'" -> "'"), with "<" -> "<" ), with ">" -> ">" else: return "\$" -
$ as lisp
View source in Bitbucket repo
($ as lisp) means: when (type of $) is: "a Syntax Tree": $body = ([$.type, : for $bit in $: add ($bit as lisp)], joined with " ") return "(\$body)" "Text": return "\"\($, with "\\" -> "\\\\", with "\"" -> "\\\"", with "\n" -> "\\n")\"" else: return "\$"
lib/tools/repl.nom
-
help
View source in Bitbucket repo
(help) means: say (" This is the Nomsu v\($(NOMSU VERSION), joined with ".") interactive console. You can type in Nomsu code here and hit 'enter' twice to run it. To exit, type 'exit' or 'quit' and hit enter twice. ")
-
tutorial
View source in Bitbucket repo
(tutorial) means: (use "tools/tutorial").run_with {.extras = []} exit
-
say results of (*extra arguments*)
View source in Bitbucket repo
(say results of (*extra arguments*)) means: $N = (select "#" (*extra arguments*)) if ($N == 0): return for $ in (1 to $N): $ret = (select $ (*extra arguments*)) if ($ret is "Text"): $ret = (quote $ret) say "\$ret"
lib/tools/replace.nom
-
$tree matches $patt with $substitution_values
View source in Bitbucket repo
($tree matches $patt with $substitution_values) means: ### 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)): if $substitution_values.($patt.1): if ($tree == $substitution_values.($patt.1)): return $substitution_values ..else: return (nil) ..else: $substitution_values.($patt.1) = $tree return $substitution_values ($tree.type != $patt.type): return (nil) ($tree.type == "Action"): if (($tree, get stub) != ($patt, get stub)): return (nil) 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: $substitution_values.$k = $v ..else: unless ($tree.$ == $patt.$): return (nil) if (#$tree != #$patt): return (nil) return $substitution_values
-
$tree with replacements
View source in Bitbucket repo
($tree with replacements) means $tree, with for $t: $values = ($t matches $pattern_tree with {}) if $values: $matched.$t = (yes) for ($k = $v) in $values: $values.$k = ($v with replacements) $ret = ($replacement_tree, with $values) if ($args.i and (not $args.f)): if ($user_answers.$t == (nil)): if (#$user_answers > 0): say "" $user_answers.$t = "n" say "\(bright)Should this:" say (" \(bright)\(yellow)\("\(($t with replacements) as nomsu)", with "\n" -> "\n ")\ ..\(reset color) ") say "\(bright)..be replaced with:" say (" \(bright)\(blue)\("\($ret as nomsu)", with "\n" -> "\n ")\(reset color) ") $user_answers.$t = (ask "\(bright)..? [Y/n]\(reset color) ") if ($user_answers.$t == "n"): return (nil) $replaced.$t = (yes) return $ret
lib/tools/tutorial.nom
-
lesson $name $lesson
View source in Bitbucket repo
(lesson $name $lesson) compiles to (" {name=\($name as lua expr), lesson=\( quote ((SyntaxTree {.type = "FileChunks"} $lesson) as nomsu, text) )} ")
-
<your code here>
View source in Bitbucket repo
[
, ???] all compile to \( at \("Text" tree with "\((this tree).source)") fail "Incomplete code: This needs to be filled in." ) -
???
View source in Bitbucket repo
[
, ???] all compile to \( at \("Text" tree with "\((this tree).source)") fail "Incomplete code: This needs to be filled in." ) -
ask $q
View source in Bitbucket repo
(ask $q) means (ask normally (bold (cyan $q)))
-
filename of $i
View source in Bitbucket repo
(filename of $i) means ("\($tutorial_dir)/lesson\$i.nom", with "//" -> "/")
-
run lesson $i
View source in Bitbucket repo
(run lesson $i) means: $filename = (filename of $i) $file = (read file $filename) $file = ($NomsuCode, from (Source $filename 1 #$file) $file) $tree = ($file parsed) $tree = $tree, with $ ->: if ($ == \(
)): return ("Text" tree with (filename of ($i - 1), with "%.nom$" -> "")) run $tree -
get failures
View source in Bitbucket repo
(get failures) means [: for ($i = $lesson) in $lessons: try: run lesson $i ..if it fails with $msg: $msg = ($msg, with "\n *stack traceback:.*" -> "") add {.lesson_number = $i, .failure = $msg} ]
-
show first failure from $failures
View source in Bitbucket repo
(show first failure from $failures) means: say (" \(bold "Next thing to fix:") \( bold yellow (" Lesson \($failures.1.lesson_number): \($lessons.($failures.1.lesson_number).name) ") ) \($failures.1.failure, indented) ")
lib/tools/uninstall.nom
-
run command $cmd
View source in Bitbucket repo
(run command $cmd) means: say $cmd try: sh> $cmd ..if it fails: say (" Sorry, the uninstall failed. You may need to re-run as root with `sudo` in front of the command. ") exit 1