Commit 52905d57 authored by Erick Gallesio's avatar Erick Gallesio

Added here-strings

parent ef0c1d44
......@@ -18,7 +18,7 @@
;; USA.
;; Author: Erick Gallesio [eg@unice.fr]
;; Creation date: 26-Nov-2000 18:19 (eg)
;; Last file update: 22-Aug-2005 11:10 (eg)
;; Last file update: 20-Apr-2007 16:00 (eg)
;;
;; ======================================================================
......@@ -131,6 +131,30 @@ keywords ,(q (code ":key")), ,(q (code ":optional")) and
accepts keywords and optional arguments, to be compatible with
DSSSL lambdas ,(ref :bib "dsssl:96").])) ))
;; ----------------------------------------------------------------------
;; Here Strings
;; ----------------------------------------------------------------------
(subsection :title "Here Strings"
(index "here string")
(index "string" :note "here")
(p [Here strings permit to easily enter multilines strings in programs.
The sequence of characters ,(emph "#<<") starts a here string. The characters
following this sequence #<< until a newline character define a terminator for
the here string. The content of the string includes all characters between
the ,(emph "#<<") line and a line whose only content is the specified terminator.
No escape sequences are recognized between the starting and terminating lines.])
(p (bold "Example: ") "the sequence")
(pre [
#<<EOF
abc
def
ghi
EOF])
(p [is equivalent to the string ])
(pre ["abc\\ndef\\n ghi"]))
;; ----------------------------------------------------------------------
;; Subsection "Other Notations"
;; ----------------------------------------------------------------------
......
......@@ -21,7 +21,7 @@
;;;;
;;;; Author: Erick Gallesio [eg@unice.fr]
;;;; Creation date: 14-Jun-2000 17:24 (eg)
;;;; Last file update: 14-Apr-2007 15:37 (eg)
;;;; Last file update: 20-Apr-2007 15:58 (eg)
;;;;
;;
......@@ -1200,6 +1200,7 @@ doc>
* (file-suffix "./foo.tar.gz") => "gz"
* (file-suffix "./a.b/c") => ""
* @end lisp
doc>
|#
(define (file-suffix pathname)
(let ((end (string-length pathname)))
......@@ -1224,6 +1225,7 @@ doc>
* (file-prefix "./foo.tar.gz") => "./foo.tar"
* (file-prefix "./a.b/c") => "./a.b/c"
* @end lisp
doc>
|#
(define (file-prefix pathname)
(let ((end (string-length pathname)))
......
/*
* r e a d . c -- reading stuff
*
* Copyright 1993-2006 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
* Copyright 1993-2007 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.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
......@@ -20,7 +20,7 @@
*
* Author: Erick Gallesio [eg@unice.fr]
* Creation date: ??-Oct-1993 ??:??
* Last file update: 20-Dec-2006 09:59 (eg)
* Last file update: 19-Apr-2007 16:24 (eg)
*
*/
......@@ -261,6 +261,38 @@ static SCM read_address(SCM port)
return (SCM) address;
}
static SCM read_here_string(SCM port)
{
SCM eof_token = read_token(port, STk_getc(port), TRUE);
SCM res, line;
int ch, first_line = TRUE;
if (!SYMBOLP(eof_token)) STk_error("bad symbol for here string ~S", eof_token);
/* skip the end of line */
line = STk_read_line(port);
if (!STRINGP(line) || (STRING_SIZE(line) != 0))
STk_error("enf of line expected after the ~S delimiter", eof_token);
res = STk_open_output_string();
while (1) {
line = STk_read_line(port);
if (line == STk_eof)
STk_error("eof seen while reading an here-string");
else
if (strcmp(STRING_CHARS(line), SYMBOL_PNAME(eof_token)) == 0)
break;
/* Append the read string to the result */
if (first_line)
first_line = FALSE;
else
STk_putc('\n', res);
STk_putstring(line, res);
}
return STk_get_output_string(res);
}
static SCM read_cycle(SCM port, int c, int case_significant, int constant)
/* read a #xx# or #xx= cycle item whose 1st char is in c. */
......@@ -593,6 +625,15 @@ static SCM read_rec(SCM port, int case_significant, int constant, int inlist)
continue;
}
}
case '<': {
char c2 = STk_getc(port);
if (c2 == '<' )
return read_here_string(port);
else {
STk_ungetc(c2, port);
goto unknown_sharp;
}
}
case 'p':
case 'P': return read_address(port);
case 'S':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment