~technomancy/fennel-lang.org

ref: 10c80a6c65aa49c6154bc66593b0f84736160dab fennel-lang.org/syntax.fnl -rw-r--r-- 1.2 KiB
10c80a6cPhil Hagelberg Use syntax highlighter derived from fennel.syntax table. 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;; this program generates a syntax file in pandoc format
;; See https://docs.kde.org/stable5/en/applications/katepart/highlight.html
;; requires fennel 0.9.3 or newer

(local fennel (require :fennel))

(fn escape [str]
  (-> str (: :gsub "<" "&lt;") (: :gsub ">" "&gt;")))

(fn classify [name data]
  (if data.define? :defines
      (= "..." name) :keywords
      (name:find "^[^a-z]+$") :operators
      :keywords))

(fn item [entry]
  (string.format "<item>%s</item>" (escape entry)))

(fn syntax-list [section syntax]
  (string.format "    <list name=\"%s\">\n      %s\n    </list>\n"
                 section (table.concat (icollect [name data (pairs syntax)]
                                         (if (= section (classify name data))
                                             (item name)))
                                       "\n      ")))

(fn write []
  (let [head (with-open [f (io.open "fennel-syntax-head.xml")] (f:read "*a"))
        foot (with-open [f (io.open "fennel-syntax-foot.xml")] (f:read "*a"))]
    (print head)
    (print (syntax-list :operators (fennel.syntax)))
    (print (syntax-list :defines (fennel.syntax)))
    (print (syntax-list :keywords (fennel.syntax)))
    (print foot)))

(write)