Changeset 27131 in project


Ignore:
Timestamp:
07/28/12 16:56:55 (9 years ago)
Author:
sjamaan
Message:

colorize: Improve support for Scheme keyword syntax

Location:
release/4/colorize/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/colorize/trunk/coloring-types.scm

    r26701 r27131  
    99(define *symbol-characters*
    1010  (make-parameter
    11    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ*!%$&+-1234567890"))
     11   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ*!%$&+-:1234567890"))
    1212
    1313(define *non-constituent*
     
    4141      (and (scan #\\) (advance 1)))
    4242     (set-mode :symbol
    43                :until (scan-any (*non-constituent*))
    44                :advancing #f))
    45     ((or (scan #\:) (scan "#:"))
    46      (set-mode :keyword
    4743               :until (scan-any (*non-constituent*))
    4844               :advancing #f))
     
    7167     (set-mode :multiline
    7268               :until (scan "|#"))))
    73    ((:symbol :keyword :escaped-symbol :string)
     69   ((:symbol :escaped-symbol :string)
    7470    ((scan #\\)
    7571     (let ((count 0))
     
    139135                (char=? (string-ref new-s (sub1 (string-length new-s))) #\*))
    140136           (format #f "<span class=\"special\">~A</span>" s))
     137          ((string-prefix? ":" s)
     138           (format #f "<span class=\"keyword\">~A</span>" s))
    141139          (else s)))))
    142    (:keyword (lambda (type s)
    143                (format #f "<span class=\"keyword\">~A</span>"
    144                        s)))
    145140   ((:comment :multiline)
    146141    (lambda (type s)
     
    167162  :transitions
    168163  (((:normal :in-list)
     164    ((scan "#:")
     165     (set-mode :symbol
     166               :until (scan-any (*non-constituent*))
     167               :advancing #f))
    169168    ((scan "...")
    170169     (set-mode :symbol
     
    185184                         (funcall (symbol-function (intern "SYMBOL-LOOKUP" :r5rs-lookup))
    186185                                  s))))
    187         (if result
    188             (format #f "<a href=\"~A\" class=\"symbol\">~A</a>"
    189                     result (call-parent-formatter))
    190             (call-parent-formatter)))))))
     186        (cond
     187         (result
     188          (format #f "<a href=\"~A\" class=\"symbol\">~A</a>"
     189                  result (call-parent-formatter)))
     190         ((or (string-prefix? "#:" s) (string-suffix? ":" s))
     191          (format #f "<span class=\"keyword\">~A</span>" s))
     192         (else (call-parent-formatter))))))))
    191193
    192194(define-coloring-type :elisp "Emacs Lisp"
  • release/4/colorize/trunk/tests/quickrep.scheme.expected

    r26711 r27131  
    66  <span class="paren2">(<span class="default">irregex-replace/all re line rplc</span>)</span></span>)</span>
    77
    8 <span class="paren1">(<span class="default"><i><span class="symbol">define</span></i> <span class="paren2">(<span class="default">quickrep re rplc</span>)</span>
     8<span class="paren1">(<span class="default"><i><span class="symbol">define</span></i> <span class="paren2">(<span class="default">quickrep re #!key rplc</span>)</span>
    99  <span class="paren2">(<span class="default"><i><span class="symbol">let</span></i> <span class="paren3">(<span class="default"><span class="paren4">(<span class="default">line <span class="paren5">(<span class="default">read-line</span>)</span></span>)</span></span>)</span>
    1010    <span class="paren3">(<span class="default"><i><span class="symbol">if</span></i> <span class="paren4">(<span class="default">not <span class="paren5">(<span class="default">eof-object? line</span>)</span></span>)</span>
     
    1616<span class="comment">;;; Does a lousy job of error checking!
    1717</span><span class="paren1">(<span class="default"><i><span class="symbol">define</span></i> <span class="paren2">(<span class="default">main args</span>)</span>
    18   <span class="paren2">(<span class="default">quickrep <span class="paren3">(<span class="default">irregex <span class="paren4">(<span class="default">car args</span>)</span></span>)</span> <span class="paren3">(<span class="default">cadr args</span>)</span></span>)</span></span>)</span>
     18  <span class="paren2">(<span class="default">quickrep <span class="paren3">(<span class="default">irregex <span class="paren4">(<span class="default">car args</span>)</span></span>)</span> <span class="keyword">rplc:</span> <span class="paren3">(<span class="default">cadr args</span>)</span></span>)</span></span>)</span>
     19<span class="paren1">(<span class="default"><i><span class="symbol">define</span></i> <span class="paren2">(<span class="default">alternative-main args</span>)</span>
     20  <span class="paren2">(<span class="default">quickrep <span class="paren3">(<span class="default">irregex <span class="paren4">(<span class="default">car args</span>)</span></span>)</span> <span class="keyword">#:rplc</span> <span class="paren3">(<span class="default">cadr args</span>)</span></span>)</span></span>)</span>
  • release/4/colorize/trunk/tests/quickrep.scheme.in

    r26711 r27131  
    66  (irregex-replace/all re line rplc))
    77
    8 (define (quickrep re rplc)
     8(define (quickrep re #!key rplc)
    99  (let ((line (read-line)))
    1010    (if (not (eof-object? line))
     
    1616;;; Does a lousy job of error checking!
    1717(define (main args)
    18   (quickrep (irregex (car args)) (cadr args)))
     18  (quickrep (irregex (car args)) rplc: (cadr args)))
     19(define (alternative-main args)
     20  (quickrep (irregex (car args)) #:rplc (cadr args)))
Note: See TracChangeset for help on using the changeset viewer.