aboutsummaryrefslogtreecommitdiff
path: root/nomnom/source.nom
blob: bff8d8d4bba9660194a8a4f3e5eea873334e8c67 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env nomsu -V4.8.10
use "lib/object.nom"

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

object (Source):
    externally (Source from text %text) means:
        %match = (%text::matching groups "^@(.-)%[(%d+):(%d+)%]$")
        set {%filename:%match.1, %start:%match.2, %stop:%match.3}
        unless %filename:
            %match = (%text::matching groups "^@(.-)%[(%d+)%]$")
            set {%filename:%match.1, %start:%match.2}
        
        return (..)
            Source {filename:%filename, start:(%start or 1) as number, stop:%stop as number}
    
    my action [as text] "\
        ..@\(%me.filename)[\(%me.start)\(":\(%me.stop)" if %me.stop else "")]"
    my action [as lua] "\
        ..Source{filename=\(%me.filename::as lua), start=\(%me.start)\(..)
            ", stop=\(%me.stop)" if %stop else ""
        ..}"
    
    my action [as nomsu] "\
        ..(Source {filename:\(%me.filename::as nomsu), start:\(%me.start)\(..)
            ", stop:\(%me.stop)" if %stop else ""
        ..})"
    
    my action [== %other] (..)
        all of [..]
            (%me's metatable) == (%other's metatable)
            %me.filename == %other.filename
            %me.start == %other.start
            %me.stop == %other.stop
    
    my action [< %other]:
        assume %me.filename == %other.filename
        if (%start == %other.start):
            return ((%me.stop or %me.start) < (%other.stop or %other.start))
        ..else:
            return (%me.start < %other.start)
    
    my action [<= %other]:
        assume %me.filename == %other.filename
        if (%start == %other.start):
            return ((%me.stop or %me.start) <= (%other.stop or %other.start))
        ..else:
            return (%me.start <= %other.start)
    
    my action [+ %offset]:
        if ((type of %me) == "number"):
            set {%me:%offset, %offset:%me}
        ..else:
            assume (type of %offset) == "number"
        
        return (Source {filename:%me.filename, start:%me.start + %offset, stop:%me.stop})