summaryrefslogtreecommitdiff
path: root/lib/utils.fnl
blob: 046f646fc17815432cf0a85eb7868c1e392dddea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(fn must [...]
  (local (ok? result) ...)
  (if ok? result (error result)))

(fn measure [what f]
  (local start (must (luna.time.now)))
  (local res (table.pack (f)))
  (print (.. what ": " (/ (- (must (luna.time.now)) start) 1e6)))
  (values (table.unpack res)))

(fn test-peg [file peg]
  (local fennel (require :vendor.fennel))
  (local parser (require :parser.parser))
  (with-open [f (io.open file "r")]
    (local contents (f:read :*all))
    (print (fennel.view (parser.match-many contents peg))))
  (os.exit 1))

{: must : measure : test-peg}