Created
November 13, 2025 01:18
-
-
Save sogaiu/0ab55b53bebed2f9c98589ae5f4ee7e8 to your computer and use it in GitHub Desktop.
janet -k flycheck-fails.janet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (def- template-peg | |
| "Extract string pieces to generate a templating function" | |
| (peg/compile | |
| ~{:sub (group | |
| (choice (sequence "${" (capture (to "}")) "}") | |
| (sequence "$" (capture (some (range "az" "AZ" "09" "__" "--")))))) | |
| :main (any (sequence (capture (to (choice "$$" | |
| -1 | |
| :sub)) ) | |
| (choice (capture "$$") | |
| :sub | |
| 0)))})) | |
| (defn- make-template | |
| "Make a simple string template as defined by Python PEP292 (shell-like $ substitution). | |
| Also allows dashes in indentifiers." | |
| [source] | |
| (def frags (peg/match template-peg source)) | |
| (def partitions (partition-by type frags)) | |
| (def string-args @[]) | |
| (each chunk partitions | |
| (case (type (get chunk 0)) | |
| :string (array/push string-args (string ;chunk)) | |
| :array (each sym chunk | |
| (array/push string-args ~(,get opts ,(keyword (first sym))))))) | |
| ~(fn [opts] (,string ,;string-args))) | |
| (defmacro- deftemplate | |
| "Define a template inline" | |
| [template-name body] | |
| ~(def ,template-name :private ,(make-template body))) | |
| (defn- opt-ask | |
| "Ask user for input" | |
| [key input-options] | |
| (def dflt (get input-options key)) | |
| (if (nil? dflt) | |
| (string/trim (getline (string key "? "))) | |
| dflt)) | |
| (deftemplate project-template | |
| ```` | |
| (declare-project | |
| :name "$name" | |
| :description ```$description ``` | |
| :version "0.0.0") | |
| (declare-source | |
| :prefix "$name" | |
| :source ["$name/init.janet"]) | |
| ````) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment