diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | par/piece-table.scm | 57 | ||||
-rw-r--r-- | par/piece-table.sld | 8 | ||||
-rw-r--r-- | tests/piece-table.scm | 19 | ||||
-rwxr-xr-x | tests/run-tests.sh | 12 |
6 files changed, 98 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d787759 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tests/*.log diff --git a/README.md b/README.md new file mode 100644 index 0000000..64bd4b4 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# `par` text editor diff --git a/par/piece-table.scm b/par/piece-table.scm new file mode 100644 index 0000000..d6a3c4e --- /dev/null +++ b/par/piece-table.scm @@ -0,0 +1,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) diff --git a/par/piece-table.sld b/par/piece-table.sld new file mode 100644 index 0000000..4f428b0 --- /dev/null +++ b/par/piece-table.sld @@ -0,0 +1,8 @@ +(define-library (par piece-table) + (import (scheme base)) + (export make-piece-table + piece-table-index + piece-table-insert! + piece-table-delete! + string->piece-table) + (include "piece-table.scm")) diff --git a/tests/piece-table.scm b/tests/piece-table.scm new file mode 100644 index 0000000..ecf57bc --- /dev/null +++ b/tests/piece-table.scm @@ -0,0 +1,19 @@ +(import (srfi 64) + (par piece-table)) + +;; https://srfi.schemers.org/srfi-64/srfi-64.html + + +(test-begin "index") + (define table (make-piece-table "HOLA" "" (list))) + (test-equal #\L (piece-table-index table 2)) +(test-end "index") + +(test-begin "insert") + (define table (make-piece-table "HOLA" "" (list))) + (piece-table-insert! table 2 #\9) + (test-equal #\9 (piece-table-index table 2)) +(test-end "insert") + +(test-begin "delete") +(test-end "delete") diff --git a/tests/run-tests.sh b/tests/run-tests.sh new file mode 100755 index 0000000..e9a543d --- /dev/null +++ b/tests/run-tests.sh @@ -0,0 +1,12 @@ +HERE=`dirname $0` +TESTS=$@ + +pushd "$HERE" +if [ -z "$TESTS" ]; then + TESTS=*.scm +fi + +for i in $TESTS; do + guile -L .. --r7rs "$i" +done +popd |