EOL on last line.

 new new list compose Reply to this message Top page
Attachments:
+ (text/plain)
+ (text/html)
+ gettysburg.txt (text/plain)
+ gettysburg-noextra.txr (application/octet-stream)
+ gettysburg-extra.txr (application/octet-stream)
+ 21-19-19-selection.png (image/png)
+ 21-20-37-selection.png (image/png)

Delete this message
Author: Kaz Kylheku
Date:  
To: Kyle Andrews
CC: TXR Users
Old topics: Re: Version 149 is out.
Subject: EOL on last line.

Ah yes; the TXR parser is strict in insisting that the last line of a source file must be properly terminated by a newline. (If it has lines, that is; i.e. isn't empty).  It's not that the file has to be terminated, but that the syntax rules include mandatory newlines as part of the phrase structure.

The newline on the last line is not "extra", by the way; it's part of the representation of text files.

The strictness is relaxed for queries that are specified in the command line via -c:

$txr -c '@score score and @years
years ago.' gettys.txt
          ^ no newline OK here!

It's not actually relaxed; rather, the code which prepares the "string stream" for parsing out of a striing adds the newline if it is missing, in the txr_main function in txr.c:

    if (gt(length_str(specstring), zero) &&
        chr_str(specstring, minus(length_str(specstring), one)) != chr('\n'))
      specstring = cat_str(list(specstring, string(L"\n"), nao), nil);
    parse_stream = make_string_byte_input_stream(specstring);

(TXR Lisp has no such forms that require a trailing newline; you can end a file with an object not followed by a newline, or even have the file end in the middle of a comment.)

On 24.09.2016 18:25, Kyle Andrews wrote:

Sorry for the delay in my response.

Let me clarify what I meant when I said the program needed an "extra line". The Creating the extra line in emacs 24.5 creates a line ending. Without that line ending, I get a script error.​

I have attached two scripts, one with and one without the final line ending. I've also attached screenshots of what these files look like using M-x whitespace-mode.

Running the one without the line ending (suffixed noextra) returns the syntax error.
 
Once I figured out I needed the extra line ending, it wasn't a big deal to put it in, but it did trip me up for a few minutes.
 

 

 
Four score and seven
years ago.