Wikify-grammar

From ABL
Jump to: navigation, search
;; Make sure this function is run below the first line of the generated
;; grammar HTML file, else it will muck up the DOCTYPE line of the html.

;; I know HTML is not a regular language. The code below would be safer if
;; elisp had a `replace-cfg'. That would be sweet. But that's what you get
;; when people try to juice up regexps to make up for the fact that most
;; interesting languages are not regular.

(defun wikify-grammar ()
  (interactive)
  ;; Remove anchors.
  (save-excursion (replace-regexp "<A [^>]*>" ""))
  (save-excursion (replace-regexp "</A>" ""))

  ;; Put <code>...</code> around token types.
  (save-excursion (replace-regexp "\\(<[^&]*>\\)" "<code>\\1</code>"))

  ;; Put <code>...</code> around quoted text.
  (save-excursion (replace-regexp "\\(\"[^\"]+\"\\)" "<code>\\1</code>"))
  )