aboutsummaryrefslogtreecommitdiff
path: root/nomnom/source.nom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-09-21 00:30:28 -0700
committerBruce Hill <bruce@bruce-hill.com>2018-09-21 00:30:44 -0700
commitf2048235f5cc7ff02db39a0e2fe5c79c7f390e0b (patch)
tree738faa0d4692e53d0fe2deb61399b6d7a9eedc9f /nomnom/source.nom
parent79d4bd5125de7ff220fbf8a8a5493d437ed16963 (diff)
Incremental checkin, currently not working, just saving progress.
Diffstat (limited to 'nomnom/source.nom')
-rw-r--r--nomnom/source.nom49
1 files changed, 49 insertions, 0 deletions
diff --git a/nomnom/source.nom b/nomnom/source.nom
new file mode 100644
index 0000000..e05b314
--- /dev/null
+++ b/nomnom/source.nom
@@ -0,0 +1,49 @@
+use "lib/object.nom"
+
+object (Source):
+ action [Source from text %text]:
+ %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})