aboutsummaryrefslogtreecommitdiff
path: root/lib/filesystem/init.nom
blob: a228bdc99f4add923be93cff220d94a2ec24e606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env nomsu -V6.14
#
    This file defines some actions that interact with the filesystem.
    
externally (files for $path) means:
    $files = (=lua "Files.list(\$path)")
    if $files:
        $files = (List $files)
    return $files

external $(read file $filename) = $Files.read
externally [
    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()
    ")

externally (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"

external $(spoof file $text) = $Files.spoof
external $(spoof file $filename = $text) = $Files.spoof