Changeset 27192 in project


Ignore:
Timestamp:
08/04/12 21:25:37 (9 years ago)
Author:
sjamaan
Message:

colorize: Add xml support (and support aliases xhtml, html too)

Location:
release/4/colorize/trunk
Files:
2 added
1 edited

Legend:

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

    r27137 r27192  
    11611161    (lambda (type s)
    11621162      (format #f "<span class=\"special\">~A</span>" s)))))
     1163
     1164(define *xml-begin-word*
     1165  (make-parameter
     1166   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:_"))
     1167
     1168(define *xml-non-constituent*
     1169  (make-parameter
     1170   '(#\space #\return #\tab #\newline #\< #\> #\" #\/ #\=)))
     1171
     1172;; TODO: Figure out if we can do "paren bouncing" for XML.
     1173;; Might be too tricky, so let's not for now.
     1174(define-coloring-type :xml "Extensible Markup Language"
     1175  :default-mode :normal
     1176  :transitions
     1177  (((:normal)
     1178    ((scan "<?")
     1179     (set-mode :pi
     1180               :until (scan "?>")))
     1181    ((scan "<!--")
     1182     (set-mode :comment
     1183               :until (scan "-->")))
     1184    ((scan "</")
     1185     (set-mode :end-tag
     1186               :until (scan #\>)))
     1187    ((scan #\<)
     1188     (set-mode :start-tag
     1189               :until (scan #\>))))
     1190   ((:normal :string)
     1191    ((scan #\&)
     1192     (set-mode :entity
     1193               :until (scan #\;))))
     1194   ((:start-tag :end-tag)
     1195    ((scan-any (*xml-begin-word*))
     1196     (set-mode :tag-name
     1197               :until (scan-any (*xml-non-constituent*))
     1198               :advancing #f)))
     1199   (:start-tag
     1200    ((and (not (peek #\>)) (advance 1))
     1201     (set-mode :attributes
     1202               :until (scan #\>)
     1203               :advancing #f)))
     1204   (:attributes
     1205    ((scan-any (*xml-begin-word*))
     1206     (set-mode :attribute-name
     1207               :until (scan-any (*xml-non-constituent*))
     1208               :advancing #f))
     1209    ((scan #\')
     1210     (set-mode :string
     1211               :until (scan #\')))
     1212    ((scan #\")
     1213     (set-mode :string
     1214               :until (scan #\")))))
     1215  ;; TODO: Add support for CDATA, ENTITY and other "obscure" things :)
     1216  :formatters
     1217  (((:normal :attributes)
     1218    (lambda (type s) s))
     1219   ((:tag-name :attribute-name)
     1220    (lambda (type s)
     1221      (format #f "<span class=\"variable\">~A</span>" s)))
     1222   (:pi
     1223    (lambda (type s)
     1224      (format #f "<span class=\"keyword\">~A</span>" s)))
     1225   (:comment
     1226    (lambda (type s)
     1227      (format #f "<span class=\"comment\">~A</span>" s)))
     1228   (:string
     1229    (lambda (type s)
     1230      (format #f "<span class=\"string\">~A</span>" s)))
     1231   (:entity
     1232    (lambda (type s)
     1233      (format #f "<span class=\"character\">~A</span>" s)))))
     1234
     1235;; So far, nothing special.  We might want to highlight
     1236;; recognised tag specially?
     1237(define-coloring-type :xhtml "Extensible HyperText Markup Language" :parent :xml)
     1238
     1239;; This should really inherit from SGML...
     1240(define-coloring-type :html "HyperText Markup Language" :parent :xml)
Note: See TracChangeset for help on using the changeset viewer.