-
Notifications
You must be signed in to change notification settings - Fork 6
/
playground.lisp
426 lines (320 loc) · 11.2 KB
/
playground.lisp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
(uiop:define-package #:playground
(:use #:cl)
(:import-from #:40ants-doc
#:section
#:defsection)
(:export
#:user))
(in-package playground)
(defun user ()
;; "Just to check locatives in docstrings"
"Set FULL-PACKAGE-NAMES to NIL to reduce clutter."
(values))
(define-compiler-macro bar (&whole form arg)
"A custom dostring for a compiler macro. Optimizes a call to the BAR function, when arg is an atom."
(if (atom arg)
arg
form))
;; Надо разобраться почему не работает явное указание locatives
(defun bar (user)
"Cool! This function prints its USER argument. It is also exists as BAR compiler-macro."
(format t "BAR: ~S~%"
user))
(defun foo (arg)
"Cool! It calls BAR function!"
(bar arg))
(40ants-doc:defsection @index (:title "Playground"
:ignore-words ("MGL-PAX"
"GIT"
"MIT"))
"Hello World!
And here is a link to @METHODS section.
And there can be the @SECOND-PAGE section."
(@asdf section)
(@function section)
(@class section)
(@structure section)
(@compiler-macro section)
(@constant section)
(@vars section)
(@glossary section)
(@locative section)
(@macro section)
(@METHODS section)
(@package section)
(@restart section)
(@type section)
(@include section)
(@todo section)
"Finally the other @SECOND-PAGE section link.")
(40ants-doc:defsection @function (:title "Functions")
(foo function)
(user function)
;; Это и не должно работать:
;; (user 40ants-doc/locatives/argument::argument)
(bar function))
(40ants-doc:defsection @asdf (:title "ASDF System")
(40ants-doc asdf:system))
(40ants-doc:defsection @compiler-macro (:title "Compiler macro")
(bar compiler-macro))
(defconstant +the-question+ nil)
(defconstant +the-answer+ 42
"The answer to everything")
(40ants-doc:defsection @constant (:title "Constants")
(+the-question+ constant)
(+the-answer+ constant))
(defvar *var-a*)
(defvar *var-b* 100500
"Just a var with docstring.")
(defvar *var-c*)
(setf (documentation '*var-c* 'variable)
"Unbound var with docstring. LISP allows us to define docstring separately.")
(40ants-doc:defsection @vars (:title "Variables")
(*var-a* variable)
(*var-b* variable)
(*var-c* variable))
(40ants-doc/glossary:define-glossary-term lisp (:title "The Best Programming Language")
"You really should use LISP!")
(40ants-doc:defsection @glossary (:title "Glossary")
(lisp glossary-term))
(40ants-doc:defsection @locative (:title "Locatives")
(variable locative))
(defmacro the-macro ((title) &body body)
"Macro's docstring.
We can refer FOO function from here.
"
(declare (ignore title))
`(progn ,@body))
(40ants-doc:defsection @macro (:title "Macro")
(the-macro macro))
(defclass the-object ()
()
(:documentation "Base class for all objects in the system"))
(defun the-object ()
"A constructor for THE-OBJECT class objects.")
(defclass user (the-object)
((nickname :reader user-nickname
:initform :unauthorized
:documentation "User's nickname")
(email :accessor user-email
:type (or string null)
:initform nil
:documentation "User's Email. Can be empty")
(processed :writer user-processed
:initform nil
;; :documentation "Sets a \"PROCESSED\" flag."
))
(:documentation "Class for all users except admins.
```python
def foo():
pass
```
This was the `Python` code.
"))
(40ants-doc:defsection @class (:title "Classes")
(the-object class)
(user class)
(user-nickname (reader user))
(user-email (accessor user))
(user-processed (writer user)))
(defgeneric get-address (entity)
(:documentation "Docstring of the generic function."))
(defstruct box
x
y
width
(height 0
:type integer
:read-only t))
(40ants-doc:defsection @structure (:title "Structures")
"No support for structure type yet (`MGL-PAX` lack it too)"
;; (box structure)
(box-width structure-accessor)
(box-height structure-accessor))
(defun a-few-p (value)
(and (> value 0)
(<= value 3)))
(deftype a-few (&optional (type 'integer))
"Very small integer, less or equal than 3."
`(and ,type
(satisfies a-few-p)))
(40ants-doc:defsection @type (:title "Types")
(a-few type))
(defmethod get-address ((user user))
"Returns user's address."
:foo-bar)
(40ants-doc:defsection @METHODS (:title "Generic and methods")
(get-address generic-function)
(get-address (method () (user))))
(40ants-doc:defsection @package (:title "Package")
(40ants-doc package)
(40ants-doc/full package)
(playground package))
;; TODO: make this public
(40ants-doc/restart::define-restart retry-this-error ()
"Some docstring for restart")
(40ants-doc:defsection @restart (:title "Restarts")
(retry-this-error restart))
(40ants-doc:defsection @include (:title "Inclusions")
(function-locative-example
(include
(:start (user function)
:end (bar function))
:lang "lisp"
;; TODO: remove after refactoring
:header-nl "```lisp"
:footer-nl "```")))
(40ants-doc:defsection @todo (:title "TODO"
:ignore-words ("SLIME"
"SLY"
"M-."))
"Here what I need to [check](https://yandex.ru) and fix:
1. enable all locatives
1. check dependencies of core
1. reenable tests suite
1. fix how do `M-.` work in `SLIME`
1. fix transcribe
1. create integration with `SLY`
"
)
(defun print-dependency-graph (system-name &key (level 0)
(started-from nil))
(loop for i upto level do (format t " "))
(format t "~A~%" system-name)
(typecase system-name
((or string symbol)
(when (and started-from
(string-equal started-from
system-name))
(format t "Circular dependency detected~%")
(return-from print-dependency-graph))
(let ((system (asdf:registered-system system-name)))
(loop for dep in (asdf/system:system-depends-on system)
do (print-dependency-graph dep
:level (1+ level)
:started-from (or started-from
system-name)))))))
(defun external-dependencies (system-name)
(let ((primary-name (asdf:primary-system-name system-name))
(processed nil))
(labels ((rec (system-name &optional collected)
(cond
((member system-name processed
:test #'string-equal)
collected)
(t
(push system-name processed)
;; (format t "Processing ~S system~%" system-name)
(let* ((system (asdf:registered-system system-name))
(dependencies (asdf/system:system-depends-on system)))
(loop for dep in dependencies
for dep-primary = (asdf:primary-system-name dep)
unless (or (string-equal primary-name dep-primary)
(member dep collected
:test #'string-equal))
collect dep into new-deps
finally (setf collected
(append new-deps
collected)))
(loop for dep in dependencies
do (setf collected
(rec dep collected)))
collected)))))
(sort (rec system-name)
#'string<))))
;; To load:
#+nil
(load (asdf:system-relative-pathname :40ants-doc "playground.lisp"))
;; #+nil
(defun render ()
(40ants-doc-full/builder::update-asdf-system-html-docs
playground::@index :40ants-doc
:pages
`((:objects
(,playground::@index)
:source-uri-fn ,(40ants-doc-full/github::make-github-source-uri-fn
:40ants-doc
"https://github.com/40ants/doc")))))
(40ants-doc:defsection @second-page (:title "Second Page")
;; "This is a second page.
;; It mentions only the:
;; "
;; (playground package)
(user class)
;; (user-nickname (reader user))
;; "But can also refer @INDEX section or @MACRO."
)
(defun render-multi ()
(40ants-doc-full/builder::update-asdf-system-html-docs
(list playground::@index
playground::@second-page)
:40ants-doc
:pages
`((:objects
(,playground::@index)
:source-uri-fn ,(40ants-doc-full/github::make-github-source-uri-fn
:40ants-doc
"https://github.com/40ants/doc"))
(:objects
(,playground::@second-page)
:source-uri-fn ,(40ants-doc-full/github::make-github-source-uri-fn
:40ants-doc
"https://github.com/40ants/doc")))))
(defsection @experiment (:title "Experiment"
:link-title-to (the-object function)
:external-docs ("./docs/build/"))
"Checking how trans work
40ANTS-DOC-FULL/BUILDER:RENDER-TO-FILES
"
(the-object function))
(defsection @readme (:title "Experiment")
"See SECTION class. This should be a full link to the site.")
(defun new-render-multi ()
(40ants-doc-full/builder:render-to-files
(list ;; @index
;; 40ants-doc-full/doc::@index
;; @second-page
(40ants-doc-full/page:make-page @experiment)
;; (40ants-doc-full/page:make-page @readme
;; :format 'commondoc-markdown:markdown
;; :base-dir "./new-docs/")
)
:base-url "https://40ants.com/doc/"
:base-dir "./new-docs/html/"
;; :format 'commondoc-markdown:markdown
))
(defun render-readme ()
(40ants-doc-full/builder::page-to-markdown
(list
40ants-doc-full/doc::@index
;; @second-page
;; @experiment
)
"NEW.md")
(format t "====~%~A~%====~%"
(alexandria:read-file-into-string "NEW.md"))
(values))
#+nil
(defun render-readme ()
(40ants-doc-full/builder::update-asdf-system-readme playground::@index :40ants-doc)
(40ants-doc-full/builder::update-asdf-system-readme playground::@index :40ants-doc
:format :plain))
;; PLaying with different plugins
(progn
(defsection @index (:title "Example")
"# Highlight example
```lisp
(loop for i upto 10
do (+ i i))
```
"
"## MathJax example
1. $a \ne 0$
2. $x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$")
(40ants-doc-full/builder:render-to-files
@index
:base-dir "/tmp/output/"
:theme (make-instance '40ants-doc-full/themes/light:light-theme
:plugins (list
(highlightjs :theme "magula")
(mathjax)))))