Re: [Rd] parse():ing a unclosed string

From: Henrik Bengtsson <hb_at_maths.lth.se>
Date: Mon 15 Aug 2005 - 11:44:02 GMT

Prof Brian Ripley wrote:
> On Sun, 14 Aug 2005, Henrik Bengtsson wrote:
>

>> When parse():ing R code from *file* with a unclosed string, that is, a
>> string that has an open quoation mark, but not a ending one, the string
>> seems to be closed automagically.  Is this a "bug"?

>
>
> It's clearly intentional from the comments in the sources: EOF during
> parsing is treated specially.
>
> Generally the parser has not been written to find all syntactic errors:
> in any case one would need a formal language definition to do that.
> Prior to R-devel quite a few mal-formed constants were accepted, for
> example.
>
>> Example:
>>
>> > code <- "x <- '123";
>> > parse(text=code)           # Gives an error as expected
>> Error in parse(file, n, text, prompt) : parse error
>>
>> > cat(file="foo.R", code)

>
>
> What exactly is in this file?

I'm write the contents of character variable 'code' to file 'foo.R', that is, I'm generating a file containing the nine characters "x <- '123", then parsing it below.

>

>> > expr <- parse("foo.R")     # Closes the open string
>> > print(expr)
>> expression(x <- "123\n")
>>
>> Parsing from stdin(), that is parse(), gives an error too.

>
>
> Those are _not_ the same thing. I am not clear what you actually tried,
> as you cannot generate an EOF this way.

 > parse()
?x <- '123
Error in parse(file, n, text, prompt) : parse error  >

where press ENTER directly after "123". I'm not exactly sure what is happen when I press enter and when or if a EOF is generated, but this was the only test I did for stdin().

>

>> Platform: Windows XP Pro SP2, R Version 2.1.1 Patched (2005-07-20) as
>> well as R Version 2.2.0 Under development (unstable) (2005-07-19 r34991).

>
>
> These are rather old for non-released versions: there have been many
> changes since then (especially in R-devel).

I know, but behind a 56k-modem (again) ;( and though was better to report anything than nothing.

/Henrik



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon Aug 15 21:52:02 2005

This archive was generated by hypermail 2.1.8 : Mon 24 Oct 2005 - 22:27:37 GMT