summaryrefslogtreecommitdiff
path: root/src/bigloo/xml.scm
blob: d4c662ee8ed0d552b3b08e85a22e17437ebab521 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;*=====================================================================*/
;*    serrano/prgm/project/skribe/src/bigloo/xml.scm                   */
;*    -------------------------------------------------------------    */
;*    Author      :  Manuel Serrano                                    */
;*    Creation    :  Mon Sep  1 12:08:39 2003                          */
;*    Last change :  Mon May 17 10:14:24 2004 (serrano)                */
;*    Copyright   :  2003-04 Manuel Serrano                            */
;*    -------------------------------------------------------------    */
;*    XML fontification                                                */
;*=====================================================================*/

;*---------------------------------------------------------------------*/
;*    The module                                                       */
;*---------------------------------------------------------------------*/
(module skribe_xml

   (include "new.sch")
   
   (import  skribe_types
	    skribe_lib
	    skribe_resolve
	    skribe_eval
	    skribe_api
	    skribe_param
	    skribe_source)

   (export  xml))

;*---------------------------------------------------------------------*/
;*    xml ...                                                          */
;*---------------------------------------------------------------------*/
(define xml 
   (new language
      (name "xml")
      (fontifier xml-fontifier)
      (extractor #f)))

;*---------------------------------------------------------------------*/
;*    xml-fontifier ...                                                */
;*---------------------------------------------------------------------*/
(define (xml-fontifier s)
   (let ((g (regular-grammar ()
	       ((: #\; (in "<!--") (* (or all #\Newline)) "-->")
		;; italic comments
		(let ((str (split-string-newline (the-string))))
		   (append (map (lambda (s)
				   (if (eq? s 'eol)
				       "\n"
				       (new markup
					  (markup '&source-line-comment)
					  (body s))))
				str)
			   (ignore))))
	       ((+ (or #\Newline #\Space))
		;; separators
		(let ((str (the-string)))
		   (cons str (ignore))))
	       ((or (: #\< (+ (out #\> #\space #\tab #\Newline))) #\>)
		;; markup
		(let ((str (the-string)))
		   (let ((c (new markup
			       (markup '&source-module)
			       (body (the-string)))))
		      (cons c (ignore)))))
	       ((+ (out #\< #\> #\Space #\Tab #\= #\"))
		;; regular text
		(let ((string (the-string)))
		   (cons string (ignore))))
	       ((or (: "\"" (* (or (out #a000 #\\ #\") (: #\\ all))) "\"")
		    (: "\'" (* (or (out #a000 #\\ #\') (: #\\ all))) "\'"))
		;; strings
		(let ((str (split-string-newline (the-string))))
		   (append (map (lambda (s)
				   (if (eq? s 'eol)
				       "\n"
				       (new markup
					  (markup '&source-string)
					  (body s))))
				str)
			   (ignore))))
	       ((in "\"=")
		(let ((str (the-string)))
		   (cons str (ignore))))
	       (else
		(let ((c (the-failure)))
		   (if (eof-object? c)
		       '()
		       (error "source(xml)" "Unexpected character" c)))))))
      (with-input-from-string s
	 (lambda ()
	    (read/rp g (current-input-port))))))