summaryrefslogtreecommitdiff
path: root/par/piece-table.scm
blob: d6a3c4e13fa95375f2ada902c3c49ccda507a926 (plain)
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
;; Pieces themselves: the buffer is a reference to the buffer they take their
;; data from.
;; Start and end are numbers.
;; The type defines how they should be rendered, it makes
;; possible to account for hyperlinks or stuff like that in the future with
;; ease.
(define-record-type <piece>
  (make-piece buffer start length type)
  piece?
  (buffer piece-buffer set-piece-buffer!)
  (start piece-start set-piece-start!)
  (length piece-length set-piece-length!)
  (type piece-type set-piece-type!))



;; The piece table itself;
;; original and add are strings and pieces is a list of pieces
(define-record-type <piece-table>
  (make-piece-table original add pieces)
  piece-table?
  (original piece-table-original set-piece-table-original!)
  (add piece-table-add set-piece-table-add!)
  (pieces piece-table-pieces set-piece-table-pieces!))

(define (add-piece-table-piece! piece-table piece)
  (cons piece (piece-table-pieces piece-table)))


(define (piece-table-index piece-table pos)
  #f)

(define (piece-table-insert! piece-table pos char)
  #f)

(define (piece-table-delete! piece-table pos)
  #f)



;; Serialization - Deserialization
(define (piece-table-write port)
  "Write a piece table to port"
  #f)
(define (piece-table-read port)
  "Read a piece table stored in port"
  #f)



;; From/to string
(define (string->piece-table string)
  (make-piece-table string ""
    (list (make-piece string 0 (string-length string) 'normal))))

(define (piece-table->string piece-table)
  #f)