about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-27 21:03:43 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-27 21:03:43 -0800
commit1af628effea8c4f1f29ba22949c7af9e46dc2745 (patch)
treeacef7a1fdf78fab927ed988982565336e14ceca6
parent4270ca61d70311230f22a718090423f5e0bdc91b (diff)
downloadmu-1af628effea8c4f1f29ba22949c7af9e46dc2745.tar.gz
644 - backspacing out from within strings/comments
I'd worried last night that I'd have to track the points where
comments/strings begin, but at least so far this is elegant. Might run
into problems when I try to backspace over strings after ending them.

And backspacing over comments after terminating them is a whole
different ball of wax. We still can't backspace over newlines because we
can't move the cursor across lines because we can't tell where our
cursor currently is. And even if we could tell we'd need to track how
long each line is. A new data structure is needed..
-rw-r--r--color-repl.mu35
1 files changed, 23 insertions, 12 deletions
diff --git a/color-repl.mu b/color-repl.mu
index d733b8f8..d95d48d9 100644
--- a/color-repl.mu
+++ b/color-repl.mu
@@ -30,7 +30,7 @@
       (comment?:boolean <- equal c:character ((#\; literal)))
       (break-unless comment?:boolean)
       ($print-key-to-host c:character 4:literal/fg/blue)
-      (skip-comment)
+      (skip-comment result:buffer-address)
       ; comment slurps newline, so check if we should return
       (end-sexp?:boolean <- lesser-or-equal open-parens:integer 0:literal)
       (break-if end-sexp?:boolean 2:blocks)
@@ -86,8 +86,11 @@
 
 (function skip-comment [
   (default-space:space-address <- new space:literal 30:literal)
+  (result:buffer-address <- next-input)
+  (orig-len:integer <- get result:buffer-address/deref length:offset)
   ; test: ; abc<enter>
   { begin
+    next-key-in-comment
     (c:character <- $wait-for-key-from-host)
     ($print-key-to-host c:character 4:literal/fg/blue)
     ; handle backspace
@@ -96,17 +99,25 @@
     { begin
       (backspace?:boolean <- equal c:character ((#\backspace literal)))
       (break-unless backspace?:boolean)
-      (loop 2:blocks)
+      (len:integer-address <- get-address result:buffer-address/deref length:offset)
+      ; buffer has to have at least the semi-colon so can't be empty
+      (len:integer-address/deref <- subtract len:integer-address/deref 1:literal)
+      ; if we erase start of comment, return
+      (comment-deleted?:boolean <- lesser-or-equal len:integer-address/deref orig-len:integer)
+      (jump-unless comment-deleted?:boolean end:offset)
+      (jump next-key-in-comment:offset)
     }
+    (result:buffer-address <- append result:buffer-address c:character)
     (newline?:boolean <- equal c:character ((#\newline literal)))
-    (break-if newline?:boolean)
-    (loop)
+    (jump-unless newline?:boolean next-key-in-comment:offset)
   }
+  end
 ])
 
 (function slurp-string [
   (default-space:space-address <- new space:literal 30:literal)
   (result:buffer-address <- next-input)
+  (orig-len:integer <- get result:buffer-address/deref length:offset)
   ; test: "abc"
   { begin
     next-key-in-string
@@ -119,14 +130,12 @@
       (backspace?:boolean <- equal c:character ((#\backspace literal)))
       (break-unless backspace?:boolean)
       (len:integer-address <- get-address result:buffer-address/deref length:offset)
-      ; but only if we need to
-      ; test: "<backspace>abc"
-      ; unnecessary?!
-      { begin
-        (zero?:boolean <- lesser-or-equal len:integer-address/deref 0:literal)
-        (break-if zero?:boolean)
-        (len:integer-address/deref <- subtract len:integer-address/deref 1:literal)
-      }
+      ; typed a quote before calling slurp-string, so can't be empty
+      (len:integer-address/deref <- subtract len:integer-address/deref 1:literal)
+      ; if we erase start of string, return
+      ; test: "<backspace>34
+      (string-deleted?:boolean <- lesser-or-equal len:integer-address/deref orig-len:integer)
+      (jump-unless string-deleted?:boolean end:offset)
       (jump next-key-in-string:offset)
     }
     (result:buffer-address <- append result:buffer-address c:character)
@@ -145,6 +154,7 @@
           (backspace?:boolean <- equal c2:character ((#\backspace literal)))
           (break-unless backspace?:boolean)
           (len:integer-address <- get-address result:buffer-address/deref length:offset)
+          ; just typed a backslash, so buffer can't be empty
           (len:integer-address/deref <- subtract len:integer-address/deref 1:literal)
           (jump next-key-in-string:offset)
         }
@@ -157,6 +167,7 @@
     (end-quote?:boolean <- equal c:character ((#\" literal)))  ; for vim: "
     (jump-unless end-quote?:boolean next-key-in-string:offset)
   }
+  end
 ])
 
 (function main [
06 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 427 428 429 430 431 432 433 434 435 436 437 438 439