~subsetpark/mago

4c1cd795b384effacd1cd63f81c6c6e09419ad25 — Zach Smith 3 years ago
Initial commit
3 files changed, 36 insertions(+), 0 deletions(-)

A .gitignore
A mago.janet
A project.janet
A  => .gitignore +0 -0
A  => mago.janet +29 -0
@@ 1,29 @@
(def default-separator "%%%")

(defn peg
  [separator]
  (peg/compile ~(* (<- (to ,separator))
                   ,separator
                   (<- (any 1)))))

(def default-peg (peg default-separator))

(def- boot-parse parse)

(defn parse
  ```
  Parse a Mago document into Janet frontmatter and arbitrary body text.

  The text before the separator is treated as a single Janet term and
  parsed. The text after the separator is left untouched.

  Accepts an optional second argument to specify the separator string
  to use. The default is `%%%`.
  ```
  [src &opt separator]
  (default separator default-separator)
  (let [peg (case separator
              default-separator default-peg
              (peg separator))
        [front body] (peg/match peg src)]
    {:front (boot-parse front) :body body}))

A  => project.janet +7 -0
@@ 1,7 @@
(declare-project
 :name "mago"
 :description "a minimal frontmatter library"
 :author "Z. D. Smith")

(declare-source
 :source ["mago.janet"])