Simple SML parser and writer

Posted By: Saturnus

Simple SML parser and writer - 08/28/10 14:17

This is a simple script for parsing and writing SML files.

SML is an abbreviation for Superduper Markup Language or Small Markup Language or Simple Markup Language. You can choose whatever name you prefer.

SML is similar to XML in its structure, but has a different syntax. If you are familiar with XML or a similar markup language, understanding SML should be no problem.

The syntax looks like this:
Code:
#root_node
number 123.457
string "hello world"
{
    #node
    some_text '\'escaping'\ or "double quotes"'
    {
        #node
        string_list "one", "two", "three"
        
        /* block comment */
    }
}


The parser returns the root of the SML tree. Unicode is not supported. Editing SML trees is somewhat inconvenient at the moment, as I didn't need such functions yet. All functions are slightly documented in the headerfile. Most function prototypes should be self-explanatory.

You can download the whole stuff here: sml.zip. Demo script is included. You are free to do whatever you want to do with it. Might contain traces of bugs, so beware.
Posted By: DJBMASTER

Re: Simple SML parser and writer - 08/28/10 17:54

It looks nice, but what is it for exactly? Do you write a script in SML and the parser converts it to lite-c?
Posted By: Damocles_

Re: Simple SML parser and writer - 08/28/10 18:29

Cool, will have a look at it.
Could be useful to like make a level-setup or ai script.
Posted By: Saturnus

Re: Simple SML parser and writer - 08/28/10 20:03

Originally Posted By: DJBMASTER
It looks nice, but what is it for exactly? Do you write a script in SML and the parser converts it to lite-c?

SML is just a markup language that describes hierarchically structured data. You can use it for storing game data such as configuration parameters (as Damocles mentioned), dialogues, character properties etc. By parsing a SML file its contents will not be translated to lite-C code, but mapped onto a tree structure that can be used/traversed in lite-C.

I hope this explains it better?
Posted By: Damocles_

Re: Simple SML parser and writer - 08/28/10 20:51

Maybe you can add some examples how to browse through the nodes and read out properties,

Like setting up an ini-file, placing levelobjects or a conversation with subtexts.

Just like XML, its very useful to have an external
markup definition format, to structure content.
Posted By: Saturnus

Re: Simple SML parser and writer - 08/28/10 21:30

Yes, I must admit that the current demo script is not very useful as an example.

Adding more practical examples that concentrate on certain features or tasks is a good idea. I will add some in the next days.

The script will probably be used in a dialogue system. By implementing this, some handy functions for editing the tree will probably be added, too.
© 2024 lite-C Forums