aboutsummaryrefslogtreecommitdiff
path: root/src/guile/skribilo/coloring
diff options
context:
space:
mode:
authorLudovic Courtes2005-11-01 16:19:34 +0000
committerLudovic Courtes2005-11-01 16:19:34 +0000
commitf553cb65b157b6df9563cefa593902d59301461b (patch)
tree00fc81c51256991c04799d79a749bbdd5b9fad30 /src/guile/skribilo/coloring
parent052c10245a523aa714489bda59e18a6c1a4f473e (diff)
downloadskribilo-f553cb65b157b6df9563cefa593902d59301461b.tar.gz
skribilo-f553cb65b157b6df9563cefa593902d59301461b.tar.lz
skribilo-f553cb65b157b6df9563cefa593902d59301461b.zip
Changes related to source-highlighting and to the manual.
* src/guile/skribilo/engine/lout.scm (lout-make-doc-cover-sheet): Fixed the definition of MULTI-COLUMN? (fixes a bug when producing multi-column documents). (lout-definitions): `@SkribeLeaders' renamed to `@SkribiloLeaders'. * doc/skr/api.skr (api-search-definition): Fixed calls to `format'. * doc/skr/manual.skr (keyword): Use `write' instead of `keyword->string'. * doc/user/start.skb: Cosmetic changes. * src/guile/skribilo/coloring/lisp.scm: First stab at its adaptation. * src/guile/skribilo/coloring/xml.scm: Rewritten "by hand". * src/guile/skribilo/evaluator.scm (skribe-include): Removed debugging statements. * src/guile/skribilo/lib.scm (new): Added a trick such that users of this macro don't have to use `(oop goops)' and `(skribilo types)'. (date): New procedure. * src/guile/skribilo/module.scm (*skribe-core-modules*): Renamed to `%skribe-core-modules'. (%skribe-core-modules): Removed `(oop goops)'. Added `(skribilo source)', `(skribilo coloring lisp)' and `(skribilo coloring xml)'. * src/guile/skribilo/skribe/api.scm (footnote): Fixed. * src/guile/skribilo/source.scm: Cosmetic changes. * src/guile/skribilo/types.scm: Export `language-extractor' and `language-fontifier'. git-archimport-id: lcourtes@laas.fr--2005-mobile/skribilo--devel--1.2--patch-11
Diffstat (limited to 'src/guile/skribilo/coloring')
-rw-r--r--src/guile/skribilo/coloring/lisp.scm113
-rw-r--r--src/guile/skribilo/coloring/xml.scm119
2 files changed, 130 insertions, 102 deletions
diff --git a/src/guile/skribilo/coloring/lisp.scm b/src/guile/skribilo/coloring/lisp.scm
index 53cf670..ad02431 100644
--- a/src/guile/skribilo/coloring/lisp.scm
+++ b/src/guile/skribilo/coloring/lisp.scm
@@ -1,46 +1,46 @@
;;;;
-;;;; lisp.stk -- Lisp Family Fontification
-;;;;
+;;;; lisp.scm -- Lisp Family Fontification
+;;;;
;;;; Copyright © 2003-2004 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
-;;;;
-;;;;
+;;;; Copyright © 2005 Ludovic Courtès <ludovic.courtes@laas.fr>
+;;;;
+;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2 of the License, or
;;;; (at your option) any later version.
-;;;;
+;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU General Public License for more details.
-;;;;
+;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program; if not, write to the Free Software
-;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
;;;; USA.
-;;;;
+;;;;
;;;; Author: Erick Gallesio [eg@essi.fr]
;;;; Creation date: 16-Oct-2003 22:17 (eg)
;;;; Last file update: 28-Oct-2004 21:14 (eg)
;;;;
-(require "lex-rt") ;; to avoid module problems
+(define-module (skribilo coloring lisp)
+ :use-module (skribilo source)
+ :use-module (skribilo lib)
+ :use-module (skribilo runtime)
+ :export (skribe scheme stklos bigloo lisp))
-(define-module (skribilo lisp)
- :export (skribe scheme stklos bigloo lisp)
- :import (skribe source))
-(include "lisp-lex.stk") ;; SILex generated
-
-(define *bracket-highlight* #f)
-(define *class-highlight* #f)
-(define *the-keys* #f)
+(define *bracket-highlight* (make-fluid))
+(define *class-highlight* (make-fluid))
+(define *the-keys* (make-fluid))
-(define *lisp-keys* #f)
-(define *scheme-keys* #f)
-(define *skribe-keys* #f)
-(define *stklos-keys* #f)
-(define *lisp-keys* #f)
+(define *lisp-keys* (make-fluid))
+(define *scheme-keys* (make-fluid))
+(define *skribe-keys* (make-fluid))
+(define *stklos-keys* (make-fluid))
+(define *lisp-keys* (make-fluid))
;;;
@@ -57,17 +57,17 @@
(define (lisp-family-fontifier s)
- (let ((lex (lisp-lex (open-input-string s))))
- (let Loop ((token (lexer-next-token lex))
+ (let ((lisp-input (open-input-string s)))
+ (let loop ((token (read lisp-input))
(res '()))
- (if (eq? token 'eof)
+ (if (eof-object? token)
(reverse! res)
- (Loop (lexer-next-token lex)
+ (loop (read lisp-input)
(cons token res))))))
;;;; ======================================================================
;;;;
-;;;; LISP
+;;;; LISP
;;;;
;;;; ======================================================================
(define (lisp-extractor iport def tab)
@@ -77,17 +77,17 @@
(lambda (exp)
(match-case exp
(((or defun defmacro) ?fun ?- . ?-)
- (and (eq? def fun) exp))
+ (and (eq? def fun) exp))
((defvar ?var . ?-)
- (and (eq? var def) exp))
+ (and (eq? var def) exp))
(else
- #f)))))
+ #f)))))
(define (init-lisp-keys)
(unless *lisp-keys*
(set! *lisp-keys*
(append ;; key
- (map (lambda (x) (cons x '&source-keyword))
+ (map (lambda (x) (cons x '&source-keyword))
'(setq if let let* letrec cond case else progn lambda))
;; define
(map (lambda (x) (cons x '&source-define))
@@ -95,9 +95,9 @@
*lisp-keys*)
(define (lisp-fontifier s)
- (fluid-let ((*the-keys* (init-lisp-keys))
- (*bracket-highlight* #f)
- (*class-highlight* #f))
+ (with-fluids ((*the-keys* (init-lisp-keys))
+ (*bracket-highlight* #f)
+ (*class-highlight* #f))
(lisp-family-fontifier s)))
@@ -109,7 +109,7 @@
;;;; ======================================================================
;;;;
-;;;; SCHEME
+;;;; SCHEME
;;;;
;;;; ======================================================================
(define (scheme-extractor iport def tab)
@@ -130,7 +130,7 @@
(unless *scheme-keys*
(set! *scheme-keys*
(append ;; key
- (map (lambda (x) (cons x '&source-keyword))
+ (map (lambda (x) (cons x '&source-keyword))
'(set! if let let* letrec quote cond case else begin do lambda))
;; define
(map (lambda (x) (cons x '&source-define))
@@ -139,11 +139,11 @@
(define (scheme-fontifier s)
- (fluid-let ((*the-keys* (init-scheme-keys))
- (*bracket-highlight* #f)
- (*class-highlight* #f))
+ (with-fluids ((*the-keys* (init-scheme-keys))
+ (*bracket-highlight* #f)
+ (*class-highlight* #f))
(lisp-family-fontifier s)))
-
+
(define scheme
(new language
@@ -153,7 +153,7 @@
;;;; ======================================================================
;;;;
-;;;; STKLOS
+;;;; STKLOS
;;;;
;;;; ======================================================================
(define (stklos-extractor iport def tab)
@@ -164,11 +164,11 @@
(match-case exp
(((or define define-generic define-method define-macro)
(?fun . ?-) . ?-)
- (and (eq? def fun) exp))
+ (and (eq? def fun) exp))
(((or define define-module) (and (? symbol?) ?var) . ?-)
- (and (eq? var def) exp))
+ (and (eq? var def) exp))
(else
- #f)))))
+ #f)))))
(define (init-stklos-keys)
@@ -192,9 +192,9 @@
(define (stklos-fontifier s)
- (fluid-let ((*the-keys* (init-stklos-keys))
- (*bracket-highlight* #t)
- (*class-highlight* #t))
+ (with-fluids ((*the-keys* (init-stklos-keys))
+ (*bracket-highlight* #t)
+ (*class-highlight* #t))
(lisp-family-fontifier s)))
@@ -206,7 +206,7 @@
;;;; ======================================================================
;;;;
-;;;; SKRIBE
+;;;; SKRIBE
;;;;
;;;; ======================================================================
(define (skribe-extractor iport def tab)
@@ -250,12 +250,12 @@
(map (lambda (x) (cons x '&source-define))
'(define-markup)))))
*skribe-keys*)
-
+
(define (skribe-fontifier s)
- (fluid-let ((*the-keys* (init-skribe-keys))
- (*bracket-highlight* #t)
- (*class-highlight* #t))
+ (with-fluids ((*the-keys* (init-skribe-keys))
+ (*bracket-highlight* #t)
+ (*class-highlight* #t))
(lisp-family-fontifier s)))
@@ -267,7 +267,7 @@
;;;; ======================================================================
;;;;
-;;;; BIGLOO
+;;;; BIGLOO
;;;;
;;;; ======================================================================
(define (bigloo-extractor iport def tab)
@@ -279,15 +279,14 @@
(((or define define-inline define-generic
define-method define-macro define-expander)
(?fun . ?-) . ?-)
- (and (eq? def fun) exp))
+ (and (eq? def fun) exp))
(((or define define-struct define-library) (and (? symbol?) ?var) . ?-)
- (and (eq? var def) exp))
+ (and (eq? var def) exp))
(else
- #f)))))
+ #f)))))
(define bigloo
(new language
(name "bigloo")
(fontifier scheme-fontifier)
(extractor bigloo-extractor)))
-
diff --git a/src/guile/skribilo/coloring/xml.scm b/src/guile/skribilo/coloring/xml.scm
index d71e98c..e3db36f 100644
--- a/src/guile/skribilo/coloring/xml.scm
+++ b/src/guile/skribilo/coloring/xml.scm
@@ -1,53 +1,82 @@
-;;;;
-;;;; xml.stk -- XML Fontification stuff
-;;;;
-;;;; Copyright © 2003 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
-;;;;
-;;;;
-;;;; This program is free software; you can redistribute it and/or modify
-;;;; it under the terms of the GNU General Public License as published by
-;;;; the Free Software Foundation; either version 2 of the License, or
-;;;; (at your option) any later version.
-;;;;
-;;;; This program is distributed in the hope that it will be useful,
-;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;;;; GNU General Public License for more details.
-;;;;
-;;;; You should have received a copy of the GNU General Public License
-;;;; along with this program; if not, write to the Free Software
-;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-;;;; USA.
-;;;;
-;;;; Author: Erick Gallesio [eg@essi.fr]
-;;;; Creation date: 16-Oct-2003 22:33 (eg)
-;;;; Last file update: 28-Dec-2003 17:33 (eg)
-;;;;
-
-
-;(require "lex-rt") ;; to avoid module problems
-
-
-(define-module (skribilo xml)
- :export (xml))
-
-(use-modules (skribilo source))
-
-(include "xml-lex.stk") ;; SILex generated
-
-(define (xml-fontifier s)
- (let ((lex (xml-lex (open-input-string s))))
- (let Loop ((token (lexer-next-token lex))
- (res '()))
- (if (eq? token 'eof)
- (reverse! res)
- (Loop (lexer-next-token lex)
- (cons token res))))))
+;;; xml.scm -- XML syntax highlighting.
+;;;
+;;; Copyright 2005 Ludovic Courtès <ludovic.courtes@laas.fr>
+;;;
+;;;
+;;; This program is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 2 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program; if not, write to the Free Software
+;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+(define-module (skribilo coloring xml)
+ :export (xml)
+ :use-module (skribilo source)
+ :use-module (skribilo lib)
+ :use-module (ice-9 rdelim)
+ :use-module (ice-9 regex))
+
+
+(define %comment-rx (make-regexp "<!--(.|\\n)*-->" regexp/extended))
+
+(define (xml-fontifier str)
+ (let loop ((start 0)
+ (result '()))
+ (if (>= start (string-length str))
+ (reverse! result)
+ (case (string-ref str start)
+ ((#\")
+ (let ((end (string-index str start #\")))
+ (if (not end)
+ (skribe-error 'xml-fontifier
+ "unterminated XML string"
+ (string-drop str start))
+ (loop end
+ (cons (new markup
+ (markup '&source-string)
+ (body (substring str start end)))
+ result)))))
+ ((#\<)
+ (let ((end (string-index str #\> start)))
+ (if (not end)
+ (skribe-error 'xml-fontifier
+ "unterminated XML tag"
+ (string-drop str start))
+ (let ((comment? (regexp-exec %comment-rx
+ (substring str start end))))
+ (loop end
+ (cons (if comment?
+ (new markup
+ (markup '&source-comment)
+ (body (substring str start end)))
+ (new markup
+ (markup '&source-module)
+ (body (substring str start end))))
+ result))))))
+
+ (else
+ (loop (+ 1 start)
+ (if (or (null? result)
+ (not (string? (car result))))
+ (cons (string (string-ref str start)) result)
+ (cons (string-append (car result)
+ (string (string-ref str start)))
+ (cdr result)))))))))
+
+
(define xml
(new language
(name "xml")
(fontifier xml-fontifier)
(extractor #f)))
+;;; xml.scm ends here