This repository was archived by the owner on Dec 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhyghlight.hy
72 lines (56 loc) · 2.14 KB
/
hyghlight.hy
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env hy
(import hy.core)
(defn hyghlight-names []
(-> (hy.core.reserved.names)
(sorted)))
(defn hyghlight-keywords []
(sorted hy.core.reserved.keyword.kwlist))
(defn hyghlight-builtins []
(sorted
(- (hy.core.reserved.names)
(frozenset hy.core.reserved.keyword.kwlist))))
(defmacro replace-line [spaces line-format end-of-line keywords]
`(+ line
(.join ~end-of-line
(list-comp
(.format ~line-format
:space (* " " ~spaces)
:line (.join " " keyword-line))
[keyword-line (partition ~keywords 10)]))
"\n"))
(defn generate-highlight-js-file []
(defn replace-highlight-js-keywords [line]
(cond
[(in "// keywords" line) (replace-line 6
"{space}'{line} '"
" +\n"
(hyghlight-names))]
[True line]))
(with [f (open "templates/highlight_js/hy.js")]
(.join ""
(list-comp (replace-highlight-js-keywords line)
[line (.readlines f)]))))
(defn generate-rouge-file []
(defn replace-rouge-keywords [line]
(cond
[(in "@keywords" line) (replace-line 10
"{space}{line}"
"\n"
(hyghlight-keywords))]
[(in "@builtins" line) (replace-line 10
"{space}{line}"
"\n"
(hyghlight-builtins))]
[True line]))
(with [f (open "templates/rouge/hylang.rb")]
(.join ""
(list-comp (replace-rouge-keywords line)
[line (.readlines f)]))))
(defmain [&rest args]
(let [highlight-library (second args)]
(print (cond
[(= highlight-library "highlight.js")
(generate-highlight-js-file)]
[(= highlight-library "rouge")
(generate-rouge-file)]
[True "Usage: hy hyghlight.hy [highlight.js | rouge]"]))))