dlang-community / SDLang-D

An SDLang (Simple Declarative Language) library for D
http://sdlang.org
Other
120 stars 21 forks source link

should this be valid #59

Open SingingBush opened 6 years ago

SingingBush commented 6 years ago

a matrix could be defined as any of the following:

matrix {
    581 984
    321 35
}
matrix {
    581 984;
    321 35;
}
matrix {
    581 984; 321 35
}

So should matrix { 581 984; 321 35 } also be valid? It's not too clear from the mirrored docs. I'm trying to iron out issues with the Java implementation https://github.com/SingingBush/SDL/issues/5

Abscissa commented 6 years ago

In short, no.

Here's the key thing to be aware of with SDLang:

Despite the curly braces and semicolons, SDLang is NOT a free-form semicolon-terminated language like the C-family. SDLang is a newline-based language, like INI files or shell scripts.

This is the basic grammar of a the simple matrix example:

matrix { <NEWLINE>
    581 984 <NEWLINE>
    321 35 <NEWLINE>
} <NEWLINE>

That right there IS the syntax for adding children to a tag, period.

Second key point: It just so happens that SDLang allows a semicolon to be used as a substitute for a newline. This is to allow combining things onto one line.

That means, your second example:

matrix {
    581 984;
    321 35;
}

REALLY means this:

matrix {
    581 984

    321 35

}

Note the two blank lines (which just happen to be inconsequential, because blank lines are ignored in SDLang).

Therefore, if you want to put the entire matrix on one line, you don't do it the C-style way. Instead, you replace the newlines with semicolons:

matrix {; 581 984; 321 35 }

And of course, technically, you can add more semicolons if you want:

// Ugly and pointless, but valid and still means
// the same thing (just with extra blank lines)
;;;;; matrix {;;;; 581 984;;; 321 35;;;;; };;;

And you're right: This should be more clear in the docs.

SingingBush commented 6 years ago

thanks for clarifying