From Mark.Bravington at csiro.au  Thu Sep 16 05:21:07 2004
From: Mark.Bravington at csiro.au (Mark.Bravington@csiro.au)
Date: Thu Sep 16 05:21:15 2004
Subject: FW: [Rd] Parsing multi-line strings.  Bug?  Feature?
Message-ID: <C4178DC99E08604EA5E2BDB989F093800240A352@extas2-hba.tas.csiro.au>

>  Kevin Wright <kwright@eskimo.com> writes:
>
>  > R 1.9.1 requires multi-line strings to contain a backslash at the
>  > end of each line (except the last line).  As noted by Mark
>  > Bravington (http://tolstoy.newcastle.edu.au/R/help/02b/5199.html)
>  > this requirement appears to be undocumented.
>  > 
>  > In S-Plus 6.2, multi-line strings do not need a backslash for continuation.
>  > 
>  > I recently (http://tolstoy.newcastle.edu.au/R/devel/04b/0256.html)
>  > requested compatability with S-Plus and was told to contribute
>  > a patch and then it would be considered.  Here is the proposed patch.

<<snip>>

>  > Thanks for considering this patch.
>
> Peter Dalgaard wrote:

>  Sorry, I don't think that is good enough (notwithstanding the
>  nonstandard comment character). Notice that Splus does this:
>
>  > x <- "foo
>  Continue string: bar
>  Continue string: baz"
>
>  (and the entry is interruptible with Ctrl-C too)
>
>  There's a very good reason for the change of prompt, as anyone who has
>  debugged SAS code with stray quotes will tell you: The system would
>  appear to be completely unresponsive because all input is being eaten
>  by the string readers.

I think the following patch in StringValue might address Peter Dalgaard's point: when a bare newline is found (i.e. not preceded by a backslash), it's pushed back onto the character stack via xxungetc(c) and StringValue pretends that it's just read a backslash instead. Then, as usual, it looks for the next character which is of course a newline, and proceeds as normal.

Output is from diff gram.c on R-devel from 7/9/2004. I hope the comments look sufficiently standard now (I'm not a C programmer).

Mark

3122a3123,3124
>           /* Old behaviour was: return ERROR; */
>           /* Now pretend there was a backslash before EOL */
3124c3126
<           return ERROR;
---
>           c = '\\';



>

*******************************

Mark Bravington
CSIRO (CMIS)
PO Box 1538
Castray Esplanade
Hobart
TAS 7001

phone (61) 3 6232 5118
fax (61) 3 6232 5012
Mark.Bravington@csiro.au


FW: [Rd] Parsing multi-line strings. Bug? Feature?
Mark.Bravington@csiro.au