-
Notifications
You must be signed in to change notification settings - Fork 7
/
common.rkt
41 lines (35 loc) · 1.54 KB
/
common.rkt
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
;; This file defines units for formatting
#lang racket/base
(provide (struct-out thing)
(struct-out commentable)
(struct-out visible)
(struct-out node)
(struct-out atom)
(struct-out full-atom)
(struct-out newl)
(struct-out line-comment)
(struct-out sexp-comment)
(struct-out wrapper)
strip-comment)
(struct thing () #:transparent)
(struct commentable thing (inline-comment) #:transparent)
(struct visible commentable () #:transparent)
;; prefix :: (listof (cons (or/c 'breakable 'unbreakable) string?))
(struct node visible (opener closer prefix content) #:transparent)
(struct atom visible (content type) #:transparent)
(struct full-atom atom () #:transparent)
;; invariant: n >= 1
(struct newl thing (n) #:transparent)
(struct line-comment thing (content) #:transparent)
;; when style is 'disappeared or 'any, content must have length exactly one
(struct sexp-comment commentable (style tok content) #:transparent)
(struct wrapper visible (tk content) #:transparent)
;; strip-comment :: commentable? -> commentable?
(define (strip-comment obj)
(if (commentable-inline-comment obj)
(cond
[(node? obj) (struct-copy node obj [inline-comment #:parent commentable #f])]
[(atom? obj) (struct-copy atom obj [inline-comment #:parent commentable #f])]
[(wrapper? obj) (struct-copy wrapper obj [inline-comment #:parent commentable #f])]
[(sexp-comment? obj) (struct-copy sexp-comment obj [inline-comment #:parent commentable #f])])
obj))