diff options
Diffstat (limited to 'copilot.moon')
| -rw-r--r-- | copilot.moon | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/copilot.moon b/copilot.moon new file mode 100644 index 0000000..88aa8fa --- /dev/null +++ b/copilot.moon @@ -0,0 +1,36 @@ +lfs = require 'lfs' +import program from require 'parsing' + +slurp = (file) -> + file = io.open file, 'r' + with file\read '*all' + file\close! + +spit = (file, str) -> + file = io.open file, 'w' + file\write str + file\close! + +class Copilot + new: (@file, @registry) => + @last_modification = 0 + + mode = lfs.attributes @file, 'mode' + if mode != 'file' + error "not a file: #{@file}" + + patch: => + { :mode, :modification } = (lfs.attributes @file) or {} + if mode != 'file' + return + + if @last_modification < modification + print "---" + + root = assert (program\match slurp @file), "error parsing" + @registry\patch_root root + + spit @file, root\stringify! + @last_modification = os.time! + +:Copilot |
