LDraw.org Discussion Forums

Full Version: Leading or trailing white space characters in file names
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Following the discussion in the Standrad Committee forum:

Allen Smith Wrote:I don't consider leading whitespace on a line to be valid. I think there's a difference between "separates" and "starts with." My parser will accept it some places by accident, but considers it a syntax error in many other places.

Why not? Indentation for clarity, separation of blocks of code, etc... is used all the time. I think this is an unnecessary restriction that most users will simply ignore.
If I read the header line we are talking about file names.
Technical it might work to have leading whitespace in filenames. But I would in any case disallow them for LDraw related files!
On a type 1 line there might be a reference to a file with leading whitespace. I have no clue how to detect that!!!
Trailing whitespace should not be a problem as you always have that between the letters of the filename and the dot.
First of all, for those who have yet to read it, here is some context:
http://forums.ldraw.org/showthread.php?tid=1996

Michael Heidemann Wrote:If I read the header line we are talking about file names.
Technical it might work to have leading whitespace in filenames. But I would in any case disallow them for LDraw related files!
On a type 1 line there might be a reference to a file with leading whitespace. I have no clue how to detect that!!!
Trailing whitespace should not be a problem as you always have that between the letters of the filename and the dot.
I'm pretty sure it's still the LSC's official stance that all leading or trailing whitespace around the file parameter on a type 1 line is to be stripped and ignored. Fear not, my friend Smile

I believe what Orion is referring to is whether or not lines in an ldraw file with leading whitespace is legal, such as the quads in the following file:
Code:
0 I believe this is the "File Name" Orion is referring to
0 Name: somepart.dat
0 Author: Gandalf

0 // here is the ring
1 4 0 0 0 1 0 0 0 1 0 -0 0 1 ring.dat

0 // these quads will protect Frodo from the orcs
    4 16 -5 5 -2 5 5 -2 5 -5 -2 -5 -5 -2
    4 16 -5 5 -3 5 5 -3 5 -5 -3 -5 -5 -3
    4 16 -5 5 -4 5 5 -4 5 -5 -4 -5 -5 -4

0 // these quads will protect Frodo from the eye of sauron
    4 16 -5 5 2 5 5 2 5 -5 2 -5 -5 2
    4 16 -5 5 3 5 5 3 5 -5 3 -5 -5 3
    4 16 -5 5 4 5 5 4 5 -5 4 -5 -5 4

I believe the current spec allows leading whitespace in all lines except the first one (possibly what Orion is perhaps misleadingly referring to as the file name?), so that it can be used to quickly identify dat files that are not LDraw files (simply beginning with "0 " obviously doesn't guarantee anything about the rest of the file). It's really not that hard to check if the first non-whitespace character is 0 and if it is followed by a space, which (I believe) is why Orion is bringing the discussion out of the LSC forum.

I could be completely wrong here, but I'm pretty sure that's whats going on.
Actually, the current spec is very ambiguous about white space in general, and leading white space in particular (which I don't think is mentioned). And as far as I know it makes no mention of the first line being special. That said, the LSC discussion is leaning towards the following rules:
  • Space and tab are the only allowed white space characters, and they must be treated the same.
  • All parameters on every line must be separated by one or more white space characters.
  • All leading and trailing white space characters around the filename portion of a type 1 line must be ignored.
  • Any number (0 or more) of white space characters are allowed at the beginning of any line in the file, except:
    • If the file contains a title (first line is a comment line), that line must not contain leading white space. (Note that part files are required to start with a comment line that is used for their title, so this means that the first two characters of all part files must be 0 followed by either space or tab.)
Orion Pobursky Wrote:
Allen Smith Wrote:I don't consider leading whitespace on a line to be valid.

Why not? Indentation for clarity, separation of blocks of code, etc... is used all the time. I think this is an unnecessary restriction that most users will simply ignore.

There's no danger of this ever becoming a restriction, because it was pointed out to me the practice is both existing and widespread.

FWIW, I had always been under the impression that the linetype number was supposed to be the first thing on the line. That impression was based on the fact that files generated by GUI editors (which are pretty much the only files I ever look at) never have leading space, and the fact that LDraw has little-to-no block or control syntax which gives rise to indentation. I erroneously assumed the language would have been implemented as trivially as possible, given that it has simple syntax (the spec didn't say otherwise). At an even deeper level, I honestly never can imagine LDraw as a format anyone would ever dream of writing by hand (although I know lots of people do it). I find the format very hostile to hand-authorship.

I do think it's kind of ironic that people use (and are very concerned about having) leading space in files for readability purposes, but absolutely despised the way Bricksmith used to format lines into fixed-space columns for readability. I always thought columnization transformed LDraw files from illegible globs of numbers into something I at least had a fighting chance of interpreting. But long-time LDraw people complained about it to no end, and now it's gone.

Allen
Allen Smith Wrote:At an even deeper level, I honestly never can imagine LDraw as a format anyone would ever dream of writing by hand (although I know lots of people do it). I find the format very hostile to hand-authorship.
On the contrary, the entire reason I was first drawn to LDraw (besides Legos Big Grin) was the fact that I was looking for a simple human-readable 3D model format that I could make 3D models with any normal text editor.

Allen Smith Wrote:I do think it's kind of ironic that people use (and are very concerned about having) leading space in files for readability purposes, but absolutely despised the way Bricksmith used to format lines into fixed-space columns for readability. I always thought columnization transformed LDraw files from illegible globs of numbers into something I at least had a fighting chance of interpreting. But long-time LDraw people complained about it to no end, and now it's gone.
I just found the 6 trailing zeroes annoying, spaces would be fine by me.
Yes, the very simple LDRAW syntax in fact also was very appealing to me when I joined - remember
that you can model anything in it, not just LEGO. The file format is also somewhat minimalistic,
just lines, triangles, quads, and transformation matrices referencing other files.
I hardly can think of anything smaller. (Maybe leaving away the quads and just using triangles.)

To contribute my 0.02 EUR to the spaces discussion, I'd like to say:

I think that at times when James invented the format, whitespace simply could be used just everywhere
to simply separate the numbers.

It seems to me that only after that some habits of putting spaces somewhere
or not have evolved, and people have developed personal taste and preference.

My request would be to everybody discussing this to not stick to personal taste here,
but instead find the solution which is the most flexible and powerful, i.e.,
which allows the space-lovers to use them, and the space-haters to not use them.
This, and the analogy between using spaces between the numbers in all lines
leads me clearly to argument towards allowing even leading spaces.
And yes, even in the first line - why not?

Even tools wanting to check the file type (e.g. by looking for the "0") stay simple.
Instead of checking the first byte only, they need to skip leading whitespace, and _then_ seek the "0".
Not so complicated, huh?

So I cannot see a real reason why we should put restrictions on us here.
However, we can at the same time of course establish a policy
that for official files from the PT, we will not be using leading whitespaces
(felt 99% of our files stick to that rule already).
Note the difference between the file format spec, and the preferred style of files on the PT. That's two (2) things.
Nearly all items that Travis listed are fully supported by me because it make sense.
Only the following I do not understand:
Travis Wrote:If the file contains a title (first line is a comment line), that line must not contain leading white space. (Note that part files are required to start with a comment line that is used for their title, so this means that the first two characters of all part files must be 0 followed by either space or tab.)

If you intend to say that the part description itself must not have leading whitespace I am with you. But I see no reason to force the people to start the file with '0' + 'whitespace'.
My parser just looks for the first non whitespace charater at each line and that is where I really start to parse that line.
I definitely don't intend to force the first line in the file to be a comment line (file title). Based on Steffen's argument, I'm not even sure at this point that we should disallow white space before that leading 0, but my intention was only to say that if the first line happens to be a comment line (which means it's the file's title), then there shouldn't be leading white space.
Example found in the wild:
[Image: screenshot.png]

I see no reason why this should be illegal.