dlang-community / SDLang-D

An SDLang (Simple Declarative Language) library for D

Home Page:http://sdlang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

should this be valid

SingingBush opened this issue · comments

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 sdlang-dev/SDL#5

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.

thanks for clarifying