Markup for Editing with Simple Bracket Notation

For the Compleat Fan
Locked
DrDave
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Markup for Editing with Simple Bracket Notation

Post by DrDave »

I found this an interesting topic that I might be able to actually put to use.

http://humanized.com/weblog/2006/06/30/ ... _notation/
It’s simply three sets of square brackets. The first set denotes deletion, the second set denotes addition, and the third set denotes a comment.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

I [like][love][- cormullion monday evening] it! Are you going to write the algorithm for parsing text written thus[?][!][- me again]

DrDave
Posts: 126
Joined: Wed May 21, 2008 2:47 pm

Post by DrDave »

cormullion wrote:I [like][love][- cormullion monday evening] it! Are you going to write the algorithm for parsing text written thus[?][!][- me again]
LOL. Not [write][right][DrD-MON pm] away. But I'll probably actuall[][y] [ewes][use] it this we[a][e]k.
...it is better to first strive for clarity and correctness and to make programs efficient only if really needed.
"Getting Started with Erlang" version 5.6.2

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

I had a go at writing a function:

Code: Select all

(define (ignore) "")

(define (process-bracket-notation str (stet-fn string) (delete-fn ignore) (insert-fn string) (comment-fn ignore))
    (let ((buff "") (prev-char "") (mode 0))
    (dolist (c (explode str))
        (cond   ((= c "[")  (if (= prev-char "]") (inc mode 2) (inc mode))) ; version 10 only :)
                ((= c "]")  (if (= mode 3) (set 'mode 0) (dec mode)))
                (true
                    (if (= prev-char "]") (set 'mode 0))
                    (cond
                        ((= mode 1)
                            (push (apply delete-fn (list c)) buff -1))
                        ((= mode 2)
                            (push (apply insert-fn (list c)) buff -1))
                        ((= mode 3)
                            (push (apply comment-fn (list c)) buff -1))
                        (true
                            (push (apply stet-fn (list c)) buff -1)))))
          (set 'prev-char c))
    buff))

You pass this a string and specify how you want to process it by supplying four functions:

Code: Select all

(set 't {
The [silver] quick[-][ ]brow[ed][n] fox jum[][ped] over th[ier][eir][Remember, 
I before E, unless after C. Unless the word is weird.] lazy dog. [][][Shouldn’t “their” really be “the”?]})

(process-bracket-notation t string ignore string ignore) 

;-> The  quick brown fox jumped over their lazy dog. 
ie the original (stet) and corrections are output, but deletions and comments aren't. Or:

Code: Select all

(set 'comments "")
(process-bracket-notation t string ignore string (fn (c) (push c comments -1) ""))
;-> The  quick brown fox jumped over their lazy dog. 

comments
;-> Remember, I before E, 
unless after C. Unless the word is weird.Shouldn’t “their” really be “the”?
It wouldn't be too hard to write a newLISP-GS thing that shows the different parts using HTML tags.

Locked