This repository has been archived by the owner. It is now read-only.
a simple data/config format with strong typing
C++
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Mallard
.gitignore
README.md

README.md

Mallard

Mallard is a simple data/config format with strong typing, this format can be used for many things, such as saving and loading game settings, application configuration files, e.t.c.

About Mallard Lang

Syntax

Mallard has a simplistic syntax made for easy writing and reading. A simple line of Mallard is below.

string mallardString: "test string!"

With Mallard, each data definition follows the pattern of type key: value;, with a colon seperating the key and value, and a semicolon ending the definiton.

Comments are represented with two forward slashes, and then the comment text. An example is below.

// this is a comment

Types

Mallard currently has support for integers, strings, decimal numbers, and boolean values. These are described as follows below.

Booleans are represented by the keyword bool and can have a value of either true or false.

Integers are represented by the keyword int and can have a value of any digit, though decimal points are not allowed with an int type. For example, 100 is a valid value for an int, but 100.0 is not.

Decimals are represented by the keyword decimal, and can have a value of any digit, as well as with a decimal point. For example, both 100 and 100.0 are valid for a decimal.

Strings are represented by the keyword string, and can have a value of any character, symbol, or digit, so long as it's within one set of quotes. For example, string appName: "my cool app";, string appName: ""my cool app"";, and string appName: ""my cool app"" 1"; are all valid strings.

About Mallard API

The official Mallard API is written in C++ using only the standard library, as well as C++11 features, such as auto. The Mallard API was designed with simple reading and writing of Mallard files in mind, but also with speed.

Compiling Mallard

Mallard has been tested with VC++ on Visual Studio 2015 Update 1, but it should compile on anything with C++11 support.

With Mallard, for most cases you'll want to compile in Release mode, as Debug logs some info that will only be useful in debug, such as the data that has been found and added. If you need to see that, use the Debug compiled version, if not, stick to Release.

Using Mallard

To use Mallard, you can either include the individual files, in the Mallard folder, or just include Mallard.hpp which includes every Mallard header.

The most simple example for using Mallard is below.

#include "Mallard.hpp"
#include <iostream>

int main() {
	Mallard::Parser parser;
	Mallard::Container container;
	parser.ParseLine(&container, "int mInt: 1;");
	std::cout << container.GetInteger("mInt") << std::endl;
	return 0;
}

This file creates a Parser and Container for Mallard, and then parses a single line of Mallard into the container, which just adds an int with the name mInt. Afterward, the int is logged to the console by using Mallard::Container::GetInteger(key).

Every Mallard type follows the same Mallard::Container::Get*(key) method. Just replace the asterisk with the type to get. For example Mallard::Container::GetBoolean(key) will return the correct boolean value if it is a bool, if it isn't, it just returns a default value, and logs an error.

You can also parse whole files with the Mallard::Parser, this is done in the example below.

#include "Mallard.hpp"

int main() {
	Mallard::Parser parser;
	Mallard::Container container;
	parser.ParseFile(&container, "test.mld");
	std::cout << container.GetInteger("mInt") << std::endl;
	std::cout << container.GetInteger("useMInt") << std::endl;
	return 0;
}

The contents of test.mld are below.

// a test mallard file
int mInt: 1;
bool useMInt: true;

Both of these examples only add the data to the Mallard::Container instance, this data is currently not manipulated/shown in the example.