Download
98 lines 3.5 KiBNomsuModified 2019-03-27 raw
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
#!/usr/bin/env nomsu -V7.0.0
###
    This file defines upgrades from Nomsu <4.11 to Nomsu 4.11
    (overhaul of function literals, deleting (if all of ...), etc. shorthand)
    
use "compatibility/compatibility"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

### Overhaul of function literals:
upgrade action "call 1 with" to "4.11" via
    for $tree:
        $tree2 = {.type = "Action", .source = $tree.source, .1 = $tree.2}
        for ($i = $arg) in $tree.4:
            $tree2.($i + 1) = $arg
        return (SyntaxTree $tree2)

upgrade action ->$yield_value to "4.11" as (yield $yield_value)

### Replace set {$x:1, $y:2} with [$x, $y] = [1, 2]
upgrade action "set" to "4.11" via
    for $tree:
        [$lhs, $rhs] = [\[], \[]]
        $lhs.source = $tree.2.source
        $rhs.source = $tree.2.source
        for ($i = $entry) in $tree.2:
            $lhs.$i = $entry.1
            $rhs.$i = $entry.2
        return ("Action" tree from $tree.source with $lhs "=" $rhs)

upgrade action "1 with 2 ~>" to "4.11" via
    for $tree:
        at $tree fail ("
            Upgrade error: This method has been deprecated.
            Hint: Perhaps this could be use ($tree, map ...) instead.
        ")

### Changing filesystem API:
upgrade action (for file $f in $path $body) to "4.11" as
    for $f in (files for $path) $body

upgrade action ($expr for file $f in $path) to "4.11" as
    [: for $f in (files for $path): add $expr]

upgrade action (line $n in $text) to "4.11" as ($text, line $n)
upgrade action (line number of $pos in $text) to "4.11" as
    $text, line number at $pos

### Deduplicating goto labels:
upgrade action [=== $label ===, *** $label ***] to "4.11" as (--- $label ---)
upgrade action [===stop $label ===, ***stop $label ***] to "4.11" as
    ---stop $label ---

upgrade action [===next $label ===, ***next $label ***] to "4.11" as
    ---next $label ---

### Deprecating shorthand functions:
upgrade action [if all of $items $body, if all of $items then $body] to "4.11" as
    if (all of $items) $body

upgrade action [unless all of $items $body, unless all of $items then $body] to
.."4.11" as (if (not (all of $items)) $body)

upgrade action [if any of $items $body, if any of $items then $body] to "4.11" as
    if (any of $items) $body

upgrade action [unless any of $items $body, unless any of $items then $body] to
.."4.11" as (if (not (any of $items)) $body)

upgrade action [if none of $items $body, if none of $items then $body] to "4.11"
..as (if (not (any of $items)) $body)

upgrade action [unless none of $items $body, unless none of $items then $body] to
.."4.11" as (if (any of $items) $body)

upgrade action [
    if all of $items $body else $else, if all of $items then $body else $else
] to "4.11" as (if (all of $items) $body else $else)

upgrade action [
    unless all of $items $body else $else, unless all of $items then $body else $else
] to "4.11" as (if (not (all of $items)) $body else $else)

upgrade action [
    if any of $items $body else $else, if any of $items then $body else $else
] to "4.11" as (if (any of $items) $body else $else)

upgrade action [
    unless any of $items $body else $else, unless any of $items then $body else $else
] to "4.11" as (if (not (any of $items)) $body else $else)

upgrade action [
    if none of $items $body else $else, if none of $items then $body else $else
] to "4.11" as (if (not (any of $items)) $body else $else)

upgrade action [
    unless none of $items $body else $else
    unless none of $items then $body else $else
] to "4.11" as (if (any of $items) $body else $else)