ponedjeljak, 17. rujna 2012.

IKON and IKSTON

As mentioned before, I've designed my own data format for the Stareater data. The language has an abstract foundation and concrete version. Abstract part is called IKON (Ivan Kravarščan's object notation) and on it's own doesn't define any data format and cannot be used as such. What it does define is:
  • Identifier format (sequence of a-z, A-Z, 0-9 and _ characters).
  • Value syntax:  sign data [@ identifier]*
    • The sign is a character associated with the parser for that kind of value. 
    • Identifers after "@" are reference name, "*" means zero or more.
  • Each value should  have a type.
  • Abstract classes, interfaces and helper classes for quick development of concrete data formats.

IKSTON (Ivan Kravarščan's object notation) is concrete IKON. It resembles to JSON without double quotes in keys in key-value pairs. It has five types of values, number, text, array, compound, referenced values. Text is perhaps the simplest. Sign for text is ", the double quote. Text ends with the second double quote that is not escaped. Escape codes are:

Escape sequence Translates to
\\ \ (backslash)
\" " (double quote)
\n new line character
\r "carriage return" character
\t tab character
Standard stuff, escaping escape character, escaping "end of data" character and a few convenience options.

Numbers are slightly more complex, sign is =, equals character and number parser reads (after skipping whitespaces after sign) the input until it finds a character that not either from 0-9, a-z, A-Z or period or minus. Reason for accepting letters is that scientific notation (such as 1.5e3 instead of 1500) and special numbers such as Infinity, -Infinity and NaN should be accepted. Scientific notation is useful especially since a lot of cost values in Stareater tend to be 9 digit values and infinity "symbol" is good to have around. Also it's good to point out that a number is ambiguous terms when it comes to programming. Numeric IKSTON values do not automatically convert textual representation to numeric representation (integer, decimal, floating point) but they offer methods for getting a value as specific numeric representation.

After explaining text and number values, arrays sound are simple, sign is [, left square bracket, data are whatever IKON data there is and closing character is ], right square bracket. For example:

[ "text1" "text2" =1 =2 "text3" =1e6 ] @testData

Now you see the deal with sign characters. In many other data formats numbers are just numbers but in IKSTON numbers require equality sign. It may seen unnatural but the up side for that is there are no type guessing. Text may not accidentally end up being number. Example also shows how references are declared. Before explaining compound type, example first:

{ star
   size = 12
    x = 9
    y = 4
    name "Alpha Centaury"
    planets [
        { Planet size = 100 }
        { Planet size = 120 }
        { Planet size = 10 }
    ]
}

As you can see, the sign in {, left curly bracket. First thing in the compound value is the identifier with the name of the "class". As stated before each value has a type. Numbers, texts and array have the constant type names (IKSTON.Numeric, IKSTON.Text, IKSTON.Array respectively) while compound values have whatever that first identifier is as a type name. After type name, compound value can have key-value pairs (identifier and IKON value) before being closed with }, a right curly bracket.

Shish, that's a lot of explaining for a something that will not be used "as is" in the project. IKSTON will be used for application settings but localization and game data will use different implementations of IKON. Come to think of it, save game format might be the pure IKSTON. I've already started with localization implementation but more about that in the next post.





Nema komentara:

Objavi komentar