Function: eglot-tempel--peg

eglot-tempel--peg is a natively compiled function defined in eglot-tempel.el.

Signature

(eglot-tempel--peg SNIPPET)

Documentation

Parse lsp-server provided SNIPPET and produce a Lisp form that tempel can use.

Source Code

;; Defined in /nix/store/lqz3cn8ff5miaxachlhqgwligclg6la5-emacs-packages-deps/share/emacs/site-lisp/elpa/eglot-tempel-20241115.1110/eglot-tempel.el
;;; Code:
(defun eglot-tempel--peg (snippet)
  "Parse lsp-server provided SNIPPET and produce a Lisp form that tempel can use."
  (with-temp-buffer
    (insert snippet)
    (goto-char (point-min))
    (with-peg-rules
        ((snippet (* (or anything text)))
         (anything (or tabstop
                       braced
                       placeholder
                       choice))
         (tabstop (and "$" int )  `(num -- (if (= 0 num) 'q 'p)))
         (braced (and "${" int "}") `(num --  (if (= 0 num) 'q 'p)))
         (placeholder (and "${" int ":" (or anything name) "}")
                      `(num place -- (let ((placeholder (if (string-empty-p place)
                                                            "_"
                                                          place)))
                                       `(p ,placeholder ,num))))
         (choice  (and "${" int "|" choices "|}" `(num choices -- `(p ,choices ,num))))
         (int (substring (+ [0-9])) `(num -- (string-to-number num)))
         (text (substring (+ (not (or "$" (eob))) (any))))
         (name (substring (* (not (or (set "$}") (eob))) (any))))
         (choices (substring (* (not (or (set "$|") (eob))) (any)))))
      (peg-run (peg snippet)))))