(index ("mistie-def-char" 0) ("mistie-def-ctl-seq" 2507) ("mistie-escape-char" 3514) ("mistie-push-frame" 3810) ("mistie-pop-frame" 4032) ("mistie-load" 4838) ("mistie-path" 5064) ("mistie-main" 5389))
(def (sig (procedure "(mistie-def-char CHAR OUTPUT-PROC)" (id mistie-def-char))) (p "A typical intent of a format file is to cause certain characters in the input document to trigger non-trivial changes in the output document. E.g., if the output is to be HTML, we'd like the characters " (tt "<") ", " (tt ">") ", " (tt "&") ", and " (tt "\"") "  in the input to come out as " (tt "&lt;") ", " (tt "&gt;") ", " (tt "&amp;") ", and " (tt "&quot;") ", respectively.") (p "The Mistie procedure " (tt "mistie-def-char") " can be used for this:") (highlight scheme "(mistie-def-char #\\< \n  (lambda ()\n    (display \"&lt;\")))\n\n(mistie-def-char #\\> \n  (lambda ()\n    (display \"&gt;\")))\n\n(mistie-def-char #\\& \n  (lambda ()\n    (display \"&amp;\")))\n\n(mistie-def-char #\\\" \n  (lambda ()\n    (display \"&quot;\")))") (p (tt "mistie-def-char") " takes two arguments:  The first is the character that is defined, and the second is the procedure associated with it.  Here, the procedure writes the HTML encoded version of the character.") (p "Suppose we want a contiguous sequence of blank lines to be come out as the paragraph separator, " (tt "<p>") ".  We could " (tt "mistie-def-char") " the newline character as follows:") (highlight scheme "(mistie-def-char #\\newline\n  (lambda ()\n    (newline)\n    (let* ((s (h-read-whitespace))\n           (n (h-number-of-newlines s)))\n      (if (> n 0)\n          (begin (display \"<p>\")\n            (newline) (newline))\n          (display s)))))") (p "This will cause newline to read up all the following whitespace, and then check to see how many further newlines it picked up.  If there was at least one, it outputs the paragraph separator, viz., " (tt "<p>") " followed by two newlines (added for human readability).  Otherwise, it merely prints the picked up whitespace as is.") (p "The help procedures " (tt "h-read-whitespace") " and " (tt "h-number-of-newlines") " in the code above are ordinary Scheme procedures:") (highlight scheme "(define h-read-whitespace\n  (lambda ()\n    (let loop ((r '()))\n      (let ((c (peek-char)))\n        (if (or (eof-object? c) (not (char-whitespace? c)))\n            (list->string (reverse r))\n            (loop (cons (read-char) r)))))))\n\n(define h-number-of-newlines\n  (lambda (ws)\n    (let ((n (string-length ws)))\n      (let loop ((i 0) (k 0))\n        (if (>= i n) k\n            (loop (+ i 1)\n              (if (char=? (string-ref ws i) #\\newline)\n                  (+ k 1) k)))))))"))
(def (sig (procedure "(mistie-def-ctl-seq SEQ WRITER)" (id mistie-def-ctl-seq))) (p "This Mistie procedure defines " (i "control sequences") ". A control sequence is a sequence of letters (alphabetic characters), and is invoked in the input document by prefixing the sequence with an " (i "escape character") ". The case of the letters is insignificant.") (p (tt "mistie-def-ctl-seq") " associates a procedure with a control sequence -- when the control sequence " (tt "SEQ") " occurs in the input document, it causes the procedure " (tt "WRITER") " to be applied.") (p "The following defines the control sequence " (tt "br") ", which emits the HTML tag " (tt "<br>") ":") (highlight scheme "(mistie-def-ctl-seq 'br\n  (lambda ()\n    (display \"<br>\")))") (p "Before a control sequence can be used, we must fix the escape character.  The following sets it to backslash:") (highlight scheme "(set! mistie-escape-char #\\\\)") (p "We can now invoke the " (tt "br") " control sequence as " (tt "\\br") "."))
(def (sig (parameter "mistie-escape-char" (id mistie-escape-char))) (p "Not a true SRFI-39 parameter, but a regular variable which you can " (tt "set!") " to a value.  The value of this variable determines what character causes the string following it to be interpreted as a control sequence."))
(def (sig (procedure "(mistie-push-frame)" (id mistie-push-frame))) (p "This Mistie procedure causes any definitions (whether " (tt "mistie-def-char") " or " (tt "mistie-def-ctl-seq") ") to shadow existing definitions."))
(def (sig (procedure "(mistie-pop-frame)" (id mistie-pop-frame))) (p "This Mistie procedure exits the frame entered by the most recent call to " (tt "mistie-push-frame") ", causing the older definitions to take effect again.") (p "In this case, we create a shadowing " (tt "mistie-def-char") " for newline, so that it will emit " (tt "<br>") " instead of performing its default action (which, as we described above, was to look for paragraph separation). We also define a control sequence " (tt "endobeylines") " which will pop the frame pushed by " (tt "obeylines") ".  With this definition in place, any text sandwiched between " (tt "\\obeylines") " and " (tt "\\endobeylines") " (assuming " (tt "\\") " is the escape character) will be output with a " (tt "<br>") " at the end of each of its lines."))
(def (sig (procedure "(mistie-load FILENAME ...)" (id mistie-load))) (p "This procedure loads a " (tt ".mistie") " file. It will search the working directory and the directory given in the parameter " (tt "mistie-path") "."))
(def (sig (parameter "(mistie-path PATH)" (id mistie-path))) (p "This defines the path which mistie will search when you issue a call to " (tt "mistie-load") ".  It defaults to the value of " (tt "(repository-path)") ", the path where " (tt "chicken-setup") " will install the initially provided " (tt ".mistie") " files."))
(def (sig (procedure "(mistie-main [FILENAME])" (id mistie-main))) (p "This procedure will invoke the filtering process."))
