/* chess-pgn.c generated by valac 0.27.1.15-b1df0, the Vala compiler
 * generated from chess-pgn.vala, do not modify */

/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * Copyright (C) 2010-2013 Robert Ancell
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 2 of the License, or (at your option) any later
 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <stdio.h>


#define TYPE_PGN_GAME (pgn_game_get_type ())
#define PGN_GAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PGN_GAME, PGNGame))
#define PGN_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PGN_GAME, PGNGameClass))
#define IS_PGN_GAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PGN_GAME))
#define IS_PGN_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PGN_GAME))
#define PGN_GAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PGN_GAME, PGNGameClass))

typedef struct _PGNGame PGNGame;
typedef struct _PGNGameClass PGNGameClass;
typedef struct _PGNGamePrivate PGNGamePrivate;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define __g_list_free__g_free0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_free0_ (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_list_free0(var) ((var == NULL) ? NULL : (var = (g_list_free (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

#define TYPE_STATE (state_get_type ())

#define TYPE_PGN (pgn_get_type ())
#define PGN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PGN, PGN))
#define PGN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PGN, PGNClass))
#define IS_PGN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PGN))
#define IS_PGN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PGN))
#define PGN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PGN, PGNClass))

typedef struct _PGN PGN;
typedef struct _PGNClass PGNClass;
typedef struct _PGNPrivate PGNPrivate;
#define __g_list_free__g_object_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_object_unref0_ (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

typedef enum  {
	PGN_ERROR_LOAD_ERROR
} PGNError;
#define PGN_ERROR pgn_error_quark ()
struct _PGNGame {
	GObject parent_instance;
	PGNGamePrivate * priv;
	GHashTable* tags;
	GList* moves;
};

struct _PGNGameClass {
	GObjectClass parent_class;
};

typedef enum  {
	STATE_TAGS,
	STATE_MOVE_TEXT,
	STATE_LINE_COMMENT,
	STATE_BRACE_COMMENT,
	STATE_TAG_START,
	STATE_TAG_NAME,
	STATE_PRE_TAG_VALUE,
	STATE_TAG_VALUE,
	STATE_POST_TAG_VALUE,
	STATE_SYMBOL,
	STATE_PERIOD,
	STATE_NAG,
	STATE_ERROR
} State;

struct _PGN {
	GObject parent_instance;
	PGNPrivate * priv;
	GList* games;
};

struct _PGNClass {
	GObjectClass parent_class;
};


static gpointer pgn_game_parent_class = NULL;
extern gchar* pgn_game_RESULT_IN_PROGRESS;
gchar* pgn_game_RESULT_IN_PROGRESS = NULL;
extern gchar* pgn_game_RESULT_DRAW;
gchar* pgn_game_RESULT_DRAW = NULL;
extern gchar* pgn_game_RESULT_WHITE;
gchar* pgn_game_RESULT_WHITE = NULL;
extern gchar* pgn_game_RESULT_BLACK;
gchar* pgn_game_RESULT_BLACK = NULL;
extern gchar* pgn_game_TERMINATE_ABANDONED;
gchar* pgn_game_TERMINATE_ABANDONED = NULL;
extern gchar* pgn_game_TERMINATE_ADJUDICATION;
gchar* pgn_game_TERMINATE_ADJUDICATION = NULL;
extern gchar* pgn_game_TERMINATE_DEATH;
gchar* pgn_game_TERMINATE_DEATH = NULL;
extern gchar* pgn_game_TERMINATE_EMERGENCY;
gchar* pgn_game_TERMINATE_EMERGENCY = NULL;
extern gchar* pgn_game_TERMINATE_NORMAL;
gchar* pgn_game_TERMINATE_NORMAL = NULL;
extern gchar* pgn_game_TERMINATE_RULES_INFRACTION;
gchar* pgn_game_TERMINATE_RULES_INFRACTION = NULL;
extern gchar* pgn_game_TERMINATE_TIME_FORFEIT;
gchar* pgn_game_TERMINATE_TIME_FORFEIT = NULL;
extern gchar* pgn_game_TERMINATE_UNTERMINATED;
gchar* pgn_game_TERMINATE_UNTERMINATED = NULL;
static gpointer pgn_parent_class = NULL;

gint str_index (const gchar* name);
gint compare_tag (const gchar* name0, const gchar* name1);
GQuark pgn_error_quark (void);
GType pgn_game_get_type (void) G_GNUC_CONST;
enum  {
	PGN_GAME_DUMMY_PROPERTY,
	PGN_GAME_EVENT,
	PGN_GAME_SITE,
	PGN_GAME_DATE,
	PGN_GAME_TIME,
	PGN_GAME_ROUND,
	PGN_GAME_WHITE,
	PGN_GAME_BLACK,
	PGN_GAME_RESULT,
	PGN_GAME_ANNOTATOR,
	PGN_GAME_TIME_CONTROL,
	PGN_GAME_WHITE_TIME_LEFT,
	PGN_GAME_BLACK_TIME_LEFT,
	PGN_GAME_SET_UP,
	PGN_GAME_FEN,
	PGN_GAME_TERMINATION,
	PGN_GAME_WHITE_AI,
	PGN_GAME_WHITE_LEVEL,
	PGN_GAME_BLACK_AI,
	PGN_GAME_BLACK_LEVEL
};
static void _g_free0_ (gpointer var);
static void _g_list_free__g_free0_ (GList* self);
PGNGame* pgn_game_new (void);
PGNGame* pgn_game_construct (GType object_type);
gchar* pgn_game_escape (PGNGame* self, const gchar* value);
void pgn_game_write (PGNGame* self, GFile* file, GError** error);
const gchar* pgn_game_get_result (PGNGame* self);
const gchar* pgn_game_get_event (PGNGame* self);
void pgn_game_set_event (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_site (PGNGame* self);
void pgn_game_set_site (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_date (PGNGame* self);
void pgn_game_set_date (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_time (PGNGame* self);
void pgn_game_set_time (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_round (PGNGame* self);
void pgn_game_set_round (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_white (PGNGame* self);
void pgn_game_set_white (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_black (PGNGame* self);
void pgn_game_set_black (PGNGame* self, const gchar* value);
void pgn_game_set_result (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_annotator (PGNGame* self);
void pgn_game_set_annotator (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_time_control (PGNGame* self);
void pgn_game_set_time_control (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_white_time_left (PGNGame* self);
void pgn_game_set_white_time_left (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_black_time_left (PGNGame* self);
void pgn_game_set_black_time_left (PGNGame* self, const gchar* value);
gboolean pgn_game_get_set_up (PGNGame* self);
void pgn_game_set_set_up (PGNGame* self, gboolean value);
const gchar* pgn_game_get_fen (PGNGame* self);
void pgn_game_set_fen (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_termination (PGNGame* self);
void pgn_game_set_termination (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_white_ai (PGNGame* self);
void pgn_game_set_white_ai (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_white_level (PGNGame* self);
void pgn_game_set_white_level (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_black_ai (PGNGame* self);
void pgn_game_set_black_ai (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_black_level (PGNGame* self);
void pgn_game_set_black_level (PGNGame* self, const gchar* value);
static void pgn_game_finalize (GObject* obj);
static void _vala_pgn_game_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_pgn_game_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
GType state_get_type (void) G_GNUC_CONST;
GType pgn_get_type (void) G_GNUC_CONST;
enum  {
	PGN_DUMMY_PROPERTY
};
static void _g_object_unref0_ (gpointer var);
static void _g_list_free__g_object_unref0_ (GList* self);
PGN* pgn_new_from_string (const gchar* data, GError** error);
PGN* pgn_construct_from_string (GType object_type, const gchar* data, GError** error);
PGN* pgn_new_from_file (GFile* file, GError** error);
PGN* pgn_construct_from_file (GType object_type, GFile* file, GError** error);
PGN* pgn_new (void);
PGN* pgn_construct (GType object_type);
static void pgn_finalize (GObject* obj);


gint str_index (const gchar* name) {
	gint result = 0;
	const gchar* _tmp0_ = NULL;
	g_return_val_if_fail (name != NULL, 0);
	_tmp0_ = name;
	if (g_strcmp0 (_tmp0_, "Event") == 0) {
		result = 0;
		return result;
	} else {
		const gchar* _tmp1_ = NULL;
		_tmp1_ = name;
		if (g_strcmp0 (_tmp1_, "Site") == 0) {
			result = 1;
			return result;
		} else {
			const gchar* _tmp2_ = NULL;
			_tmp2_ = name;
			if (g_strcmp0 (_tmp2_, "Date") == 0) {
				result = 2;
				return result;
			} else {
				const gchar* _tmp3_ = NULL;
				_tmp3_ = name;
				if (g_strcmp0 (_tmp3_, "Round") == 0) {
					result = 3;
					return result;
				} else {
					const gchar* _tmp4_ = NULL;
					_tmp4_ = name;
					if (g_strcmp0 (_tmp4_, "White") == 0) {
						result = 4;
						return result;
					} else {
						const gchar* _tmp5_ = NULL;
						_tmp5_ = name;
						if (g_strcmp0 (_tmp5_, "Black") == 0) {
							result = 5;
							return result;
						} else {
							const gchar* _tmp6_ = NULL;
							_tmp6_ = name;
							if (g_strcmp0 (_tmp6_, "Result") == 0) {
								result = 6;
								return result;
							} else {
								result = 7;
								return result;
							}
						}
					}
				}
			}
		}
	}
}


gint compare_tag (const gchar* name0, const gchar* name1) {
	gint result = 0;
	gint str_index0 = 0;
	const gchar* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gint str_index1 = 0;
	const gchar* _tmp2_ = NULL;
	gint _tmp3_ = 0;
	gboolean _tmp4_ = FALSE;
	gint _tmp5_ = 0;
	g_return_val_if_fail (name0 != NULL, 0);
	g_return_val_if_fail (name1 != NULL, 0);
	_tmp0_ = name0;
	_tmp1_ = str_index (_tmp0_);
	str_index0 = _tmp1_;
	_tmp2_ = name1;
	_tmp3_ = str_index (_tmp2_);
	str_index1 = _tmp3_;
	_tmp5_ = str_index0;
	if (_tmp5_ == 7) {
		gint _tmp6_ = 0;
		_tmp6_ = str_index1;
		_tmp4_ = _tmp6_ == 7;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		GCompareFunc _tmp7_ = NULL;
		const gchar* _tmp8_ = NULL;
		const gchar* _tmp9_ = NULL;
		gint _tmp10_ = 0;
		_tmp7_ = g_strcmp0;
		_tmp8_ = name0;
		_tmp9_ = name1;
		_tmp10_ = _tmp7_ (_tmp8_, _tmp9_);
		result = _tmp10_;
		return result;
	} else {
		gint _tmp11_ = 0;
		gint _tmp12_ = 0;
		_tmp11_ = str_index0;
		_tmp12_ = str_index1;
		result = _tmp11_ - _tmp12_;
		return result;
	}
}


GQuark pgn_error_quark (void) {
	return g_quark_from_static_string ("pgn_error-quark");
}


static void _g_free0_ (gpointer var) {
	var = (g_free (var), NULL);
}


static void _g_list_free__g_free0_ (GList* self) {
	g_list_foreach (self, (GFunc) _g_free0_, NULL);
	g_list_free (self);
}


PGNGame* pgn_game_construct (GType object_type) {
	PGNGame * self = NULL;
	GHashFunc _tmp0_ = NULL;
	GEqualFunc _tmp1_ = NULL;
	GHashTable* _tmp2_ = NULL;
	GHashTable* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	GHashTable* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_ = NULL;
	GHashTable* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	GHashTable* _tmp12_ = NULL;
	gchar* _tmp13_ = NULL;
	gchar* _tmp14_ = NULL;
	GHashTable* _tmp15_ = NULL;
	gchar* _tmp16_ = NULL;
	gchar* _tmp17_ = NULL;
	GHashTable* _tmp18_ = NULL;
	gchar* _tmp19_ = NULL;
	gchar* _tmp20_ = NULL;
	GHashTable* _tmp21_ = NULL;
	gchar* _tmp22_ = NULL;
	const gchar* _tmp23_ = NULL;
	gchar* _tmp24_ = NULL;
	self = (PGNGame*) g_object_new (object_type, NULL);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_free0_);
	_g_hash_table_unref0 (self->tags);
	self->tags = _tmp2_;
	_tmp3_ = self->tags;
	_tmp4_ = g_strdup ("Event");
	_tmp5_ = g_strdup ("?");
	g_hash_table_insert (_tmp3_, _tmp4_, _tmp5_);
	_tmp6_ = self->tags;
	_tmp7_ = g_strdup ("Site");
	_tmp8_ = g_strdup ("?");
	g_hash_table_insert (_tmp6_, _tmp7_, _tmp8_);
	_tmp9_ = self->tags;
	_tmp10_ = g_strdup ("Date");
	_tmp11_ = g_strdup ("????.??.??");
	g_hash_table_insert (_tmp9_, _tmp10_, _tmp11_);
	_tmp12_ = self->tags;
	_tmp13_ = g_strdup ("Round");
	_tmp14_ = g_strdup ("?");
	g_hash_table_insert (_tmp12_, _tmp13_, _tmp14_);
	_tmp15_ = self->tags;
	_tmp16_ = g_strdup ("White");
	_tmp17_ = g_strdup ("?");
	g_hash_table_insert (_tmp15_, _tmp16_, _tmp17_);
	_tmp18_ = self->tags;
	_tmp19_ = g_strdup ("Black");
	_tmp20_ = g_strdup ("?");
	g_hash_table_insert (_tmp18_, _tmp19_, _tmp20_);
	_tmp21_ = self->tags;
	_tmp22_ = g_strdup ("Result");
	_tmp23_ = pgn_game_RESULT_IN_PROGRESS;
	_tmp24_ = g_strdup (_tmp23_);
	g_hash_table_insert (_tmp21_, _tmp22_, _tmp24_);
	return self;
}


PGNGame* pgn_game_new (void) {
	return pgn_game_construct (TYPE_PGN_GAME);
}


static gchar* string_replace (const gchar* self, const gchar* old, const gchar* replacement) {
	gchar* result = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	{
		GRegex* regex = NULL;
		const gchar* _tmp0_ = NULL;
		gchar* _tmp1_ = NULL;
		gchar* _tmp2_ = NULL;
		GRegex* _tmp3_ = NULL;
		GRegex* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		GRegex* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		_tmp0_ = old;
		_tmp1_ = g_regex_escape_string (_tmp0_, -1);
		_tmp2_ = _tmp1_;
		_tmp3_ = g_regex_new (_tmp2_, 0, 0, &_inner_error_);
		_tmp4_ = _tmp3_;
		_g_free0 (_tmp2_);
		regex = _tmp4_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
		_tmp6_ = regex;
		_tmp7_ = replacement;
		_tmp8_ = g_regex_replace_literal (_tmp6_, self, (gssize) (-1), 0, _tmp7_, 0, &_inner_error_);
		_tmp5_ = _tmp8_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_regex_unref0 (regex);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
		_tmp9_ = _tmp5_;
		_tmp5_ = NULL;
		result = _tmp9_;
		_g_free0 (_tmp5_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
}


gchar* pgn_game_escape (PGNGame* self, const gchar* value) {
	gchar* result = NULL;
	gchar* a = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (value != NULL, NULL);
	_tmp0_ = value;
	_tmp1_ = string_replace (_tmp0_, "\\", "\\\\");
	a = _tmp1_;
	_tmp2_ = string_replace (a, "\"", "\\\"");
	result = _tmp2_;
	_g_free0 (a);
	return result;
}


static guint8* string_get_data (const gchar* self, int* result_length1) {
	guint8* result;
	guint8* res = NULL;
	gint res_length1 = 0;
	gint _res_size_ = 0;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	guint8* _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	guint8* _tmp4_ = NULL;
	gint _tmp4__length1 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res_length1;
	_tmp3_ = res;
	_tmp3__length1 = res_length1;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = _tmp3__length1;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	return result;
}


void pgn_game_write (PGNGame* self, GFile* file, GError** error) {
	GString* data = NULL;
	GString* _tmp0_ = NULL;
	GList* keys = NULL;
	GHashTable* _tmp1_ = NULL;
	GList* _tmp2_ = NULL;
	GList* _tmp3_ = NULL;
	GString* _tmp13_ = NULL;
	gint i = 0;
	GList* _tmp14_ = NULL;
	GString* _tmp25_ = NULL;
	const gchar* _tmp26_ = NULL;
	const gchar* _tmp27_ = NULL;
	GString* _tmp28_ = NULL;
	GFile* _tmp29_ = NULL;
	GString* _tmp30_ = NULL;
	const gchar* _tmp31_ = NULL;
	guint8* _tmp32_ = NULL;
	gint _tmp32__length1 = 0;
	guint8* _tmp33_ = NULL;
	gint _tmp33__length1 = 0;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (file != NULL);
	_tmp0_ = g_string_new ("");
	data = _tmp0_;
	_tmp1_ = self->tags;
	_tmp2_ = g_hash_table_get_keys (_tmp1_);
	keys = _tmp2_;
	keys = g_list_sort (keys, (GCompareFunc) compare_tag);
	_tmp3_ = keys;
	{
		GList* key_collection = NULL;
		GList* key_it = NULL;
		key_collection = _tmp3_;
		for (key_it = key_collection; key_it != NULL; key_it = key_it->next) {
			const gchar* key = NULL;
			key = (const gchar*) key_it->data;
			{
				GString* _tmp4_ = NULL;
				const gchar* _tmp5_ = NULL;
				GHashTable* _tmp6_ = NULL;
				const gchar* _tmp7_ = NULL;
				gconstpointer _tmp8_ = NULL;
				gchar* _tmp9_ = NULL;
				gchar* _tmp10_ = NULL;
				gchar* _tmp11_ = NULL;
				gchar* _tmp12_ = NULL;
				_tmp4_ = data;
				_tmp5_ = key;
				_tmp6_ = self->tags;
				_tmp7_ = key;
				_tmp8_ = g_hash_table_lookup (_tmp6_, _tmp7_);
				_tmp9_ = pgn_game_escape (self, (const gchar*) _tmp8_);
				_tmp10_ = _tmp9_;
				_tmp11_ = g_strdup_printf ("[%s \"%s\"]\n", _tmp5_, _tmp10_);
				_tmp12_ = _tmp11_;
				g_string_append (_tmp4_, _tmp12_);
				_g_free0 (_tmp12_);
				_g_free0 (_tmp10_);
			}
		}
	}
	_tmp13_ = data;
	g_string_append (_tmp13_, "\n");
	i = 0;
	_tmp14_ = self->moves;
	{
		GList* move_collection = NULL;
		GList* move_it = NULL;
		move_collection = _tmp14_;
		for (move_it = move_collection; move_it != NULL; move_it = move_it->next) {
			gchar* _tmp15_ = NULL;
			gchar* move = NULL;
			_tmp15_ = g_strdup ((const gchar*) move_it->data);
			move = _tmp15_;
			{
				gint _tmp16_ = 0;
				GString* _tmp21_ = NULL;
				const gchar* _tmp22_ = NULL;
				GString* _tmp23_ = NULL;
				gint _tmp24_ = 0;
				_tmp16_ = i;
				if ((_tmp16_ % 2) == 0) {
					GString* _tmp17_ = NULL;
					gint _tmp18_ = 0;
					gchar* _tmp19_ = NULL;
					gchar* _tmp20_ = NULL;
					_tmp17_ = data;
					_tmp18_ = i;
					_tmp19_ = g_strdup_printf ("%d. ", (_tmp18_ / 2) + 1);
					_tmp20_ = _tmp19_;
					g_string_append (_tmp17_, _tmp20_);
					_g_free0 (_tmp20_);
				}
				_tmp21_ = data;
				_tmp22_ = move;
				g_string_append (_tmp21_, _tmp22_);
				_tmp23_ = data;
				g_string_append (_tmp23_, " ");
				_tmp24_ = i;
				i = _tmp24_ + 1;
				_g_free0 (move);
			}
		}
	}
	_tmp25_ = data;
	_tmp26_ = pgn_game_get_result (self);
	_tmp27_ = _tmp26_;
	g_string_append (_tmp25_, _tmp27_);
	_tmp28_ = data;
	g_string_append (_tmp28_, "\n");
	_tmp29_ = file;
	_tmp30_ = data;
	_tmp31_ = _tmp30_->str;
	_tmp32_ = string_get_data (_tmp31_, &_tmp32__length1);
	_tmp33_ = _tmp32_;
	_tmp33__length1 = _tmp32__length1;
	g_file_replace_contents (_tmp29_, _tmp33_, (gsize) _tmp33__length1, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_list_free0 (keys);
		_g_string_free0 (data);
		return;
	}
	_g_list_free0 (keys);
	_g_string_free0 (data);
}


const gchar* pgn_game_get_event (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Event");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_event (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Event");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "event");
}


const gchar* pgn_game_get_site (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Site");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_site (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Site");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "site");
}


const gchar* pgn_game_get_date (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Date");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_date (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Date");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "date");
}


const gchar* pgn_game_get_time (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Time");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_time (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Time");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "time");
}


const gchar* pgn_game_get_round (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Round");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_round (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Round");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "round");
}


const gchar* pgn_game_get_white (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "White");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_white (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("White");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "white");
}


const gchar* pgn_game_get_black (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Black");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_black (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Black");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "black");
}


const gchar* pgn_game_get_result (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Result");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_result (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Result");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "result");
}


const gchar* pgn_game_get_annotator (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Annotator");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_annotator (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Annotator");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "annotator");
}


const gchar* pgn_game_get_time_control (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "TimeControl");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_time_control (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("TimeControl");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "time-control");
}


const gchar* pgn_game_get_white_time_left (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "WhiteTimeLeft");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_white_time_left (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("WhiteTimeLeft");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "white-time-left");
}


const gchar* pgn_game_get_black_time_left (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "BlackTimeLeft");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_black_time_left (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("BlackTimeLeft");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "black-time-left");
}


gboolean pgn_game_get_set_up (PGNGame* self) {
	gboolean result;
	gchar* v = NULL;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "SetUp");
	_tmp2_ = g_strdup ((const gchar*) _tmp1_);
	v = _tmp2_;
	_tmp5_ = v;
	if (_tmp5_ != NULL) {
		const gchar* _tmp6_ = NULL;
		_tmp6_ = v;
		_tmp4_ = g_strcmp0 (_tmp6_, "1") == 0;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		_tmp3_ = TRUE;
	} else {
		_tmp3_ = FALSE;
	}
	result = _tmp3_;
	_g_free0 (v);
	return result;
}


void pgn_game_set_set_up (PGNGame* self, gboolean value) {
	const gchar* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	GHashTable* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp1_ = value;
	if (_tmp1_) {
		_tmp0_ = "1";
	} else {
		_tmp0_ = "0";
	}
	_tmp2_ = self->tags;
	_tmp3_ = g_strdup ("SetUp");
	_tmp4_ = g_strdup (_tmp0_);
	g_hash_table_insert (_tmp2_, _tmp3_, _tmp4_);
	g_object_notify ((GObject *) self, "set-up");
}


const gchar* pgn_game_get_fen (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "FEN");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_fen (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("FEN");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "fen");
}


const gchar* pgn_game_get_termination (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Termination");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_termination (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Termination");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "termination");
}


const gchar* pgn_game_get_white_ai (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "WhiteAI");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_white_ai (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("WhiteAI");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "white-ai");
}


const gchar* pgn_game_get_white_level (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "WhiteLevel");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_white_level (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("WhiteLevel");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "white-level");
}


const gchar* pgn_game_get_black_ai (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "BlackAI");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_black_ai (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("BlackAI");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "black-ai");
}


const gchar* pgn_game_get_black_level (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "BlackLevel");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_black_level (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("BlackLevel");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "black-level");
}


static void pgn_game_class_init (PGNGameClass * klass) {
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	pgn_game_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->get_property = _vala_pgn_game_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_pgn_game_set_property;
	G_OBJECT_CLASS (klass)->finalize = pgn_game_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_EVENT, g_param_spec_string ("event", "event", "event", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_SITE, g_param_spec_string ("site", "site", "site", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_DATE, g_param_spec_string ("date", "date", "date", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_TIME, g_param_spec_string ("time", "time", "time", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_ROUND, g_param_spec_string ("round", "round", "round", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_WHITE, g_param_spec_string ("white", "white", "white", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_BLACK, g_param_spec_string ("black", "black", "black", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_RESULT, g_param_spec_string ("result", "result", "result", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_ANNOTATOR, g_param_spec_string ("annotator", "annotator", "annotator", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_TIME_CONTROL, g_param_spec_string ("time-control", "time-control", "time-control", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_WHITE_TIME_LEFT, g_param_spec_string ("white-time-left", "white-time-left", "white-time-left", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_BLACK_TIME_LEFT, g_param_spec_string ("black-time-left", "black-time-left", "black-time-left", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_SET_UP, g_param_spec_boolean ("set-up", "set-up", "set-up", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_FEN, g_param_spec_string ("fen", "fen", "fen", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_TERMINATION, g_param_spec_string ("termination", "termination", "termination", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_WHITE_AI, g_param_spec_string ("white-ai", "white-ai", "white-ai", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_WHITE_LEVEL, g_param_spec_string ("white-level", "white-level", "white-level", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_BLACK_AI, g_param_spec_string ("black-ai", "black-ai", "black-ai", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_BLACK_LEVEL, g_param_spec_string ("black-level", "black-level", "black-level", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	_tmp0_ = g_strdup ("*");
	pgn_game_RESULT_IN_PROGRESS = _tmp0_;
	_tmp1_ = g_strdup ("1/2-1/2");
	pgn_game_RESULT_DRAW = _tmp1_;
	_tmp2_ = g_strdup ("1-0");
	pgn_game_RESULT_WHITE = _tmp2_;
	_tmp3_ = g_strdup ("0-1");
	pgn_game_RESULT_BLACK = _tmp3_;
	_tmp4_ = g_strdup ("abandoned");
	pgn_game_TERMINATE_ABANDONED = _tmp4_;
	_tmp5_ = g_strdup ("adjudication");
	pgn_game_TERMINATE_ADJUDICATION = _tmp5_;
	_tmp6_ = g_strdup ("death");
	pgn_game_TERMINATE_DEATH = _tmp6_;
	_tmp7_ = g_strdup ("emergency");
	pgn_game_TERMINATE_EMERGENCY = _tmp7_;
	_tmp8_ = g_strdup ("normal");
	pgn_game_TERMINATE_NORMAL = _tmp8_;
	_tmp9_ = g_strdup ("rules infraction");
	pgn_game_TERMINATE_RULES_INFRACTION = _tmp9_;
	_tmp10_ = g_strdup ("time forfeit");
	pgn_game_TERMINATE_TIME_FORFEIT = _tmp10_;
	_tmp11_ = g_strdup ("unterminated");
	pgn_game_TERMINATE_UNTERMINATED = _tmp11_;
}


static void pgn_game_instance_init (PGNGame * self) {
}


static void pgn_game_finalize (GObject* obj) {
	PGNGame * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_PGN_GAME, PGNGame);
	_g_hash_table_unref0 (self->tags);
	__g_list_free__g_free0_0 (self->moves);
	G_OBJECT_CLASS (pgn_game_parent_class)->finalize (obj);
}


GType pgn_game_get_type (void) {
	static volatile gsize pgn_game_type_id__volatile = 0;
	if (g_once_init_enter (&pgn_game_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (PGNGameClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pgn_game_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PGNGame), 0, (GInstanceInitFunc) pgn_game_instance_init, NULL };
		GType pgn_game_type_id;
		pgn_game_type_id = g_type_register_static (G_TYPE_OBJECT, "PGNGame", &g_define_type_info, 0);
		g_once_init_leave (&pgn_game_type_id__volatile, pgn_game_type_id);
	}
	return pgn_game_type_id__volatile;
}


static void _vala_pgn_game_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	PGNGame * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_PGN_GAME, PGNGame);
	switch (property_id) {
		case PGN_GAME_EVENT:
		g_value_set_string (value, pgn_game_get_event (self));
		break;
		case PGN_GAME_SITE:
		g_value_set_string (value, pgn_game_get_site (self));
		break;
		case PGN_GAME_DATE:
		g_value_set_string (value, pgn_game_get_date (self));
		break;
		case PGN_GAME_TIME:
		g_value_set_string (value, pgn_game_get_time (self));
		break;
		case PGN_GAME_ROUND:
		g_value_set_string (value, pgn_game_get_round (self));
		break;
		case PGN_GAME_WHITE:
		g_value_set_string (value, pgn_game_get_white (self));
		break;
		case PGN_GAME_BLACK:
		g_value_set_string (value, pgn_game_get_black (self));
		break;
		case PGN_GAME_RESULT:
		g_value_set_string (value, pgn_game_get_result (self));
		break;
		case PGN_GAME_ANNOTATOR:
		g_value_set_string (value, pgn_game_get_annotator (self));
		break;
		case PGN_GAME_TIME_CONTROL:
		g_value_set_string (value, pgn_game_get_time_control (self));
		break;
		case PGN_GAME_WHITE_TIME_LEFT:
		g_value_set_string (value, pgn_game_get_white_time_left (self));
		break;
		case PGN_GAME_BLACK_TIME_LEFT:
		g_value_set_string (value, pgn_game_get_black_time_left (self));
		break;
		case PGN_GAME_SET_UP:
		g_value_set_boolean (value, pgn_game_get_set_up (self));
		break;
		case PGN_GAME_FEN:
		g_value_set_string (value, pgn_game_get_fen (self));
		break;
		case PGN_GAME_TERMINATION:
		g_value_set_string (value, pgn_game_get_termination (self));
		break;
		case PGN_GAME_WHITE_AI:
		g_value_set_string (value, pgn_game_get_white_ai (self));
		break;
		case PGN_GAME_WHITE_LEVEL:
		g_value_set_string (value, pgn_game_get_white_level (self));
		break;
		case PGN_GAME_BLACK_AI:
		g_value_set_string (value, pgn_game_get_black_ai (self));
		break;
		case PGN_GAME_BLACK_LEVEL:
		g_value_set_string (value, pgn_game_get_black_level (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_pgn_game_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	PGNGame * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_PGN_GAME, PGNGame);
	switch (property_id) {
		case PGN_GAME_EVENT:
		pgn_game_set_event (self, g_value_get_string (value));
		break;
		case PGN_GAME_SITE:
		pgn_game_set_site (self, g_value_get_string (value));
		break;
		case PGN_GAME_DATE:
		pgn_game_set_date (self, g_value_get_string (value));
		break;
		case PGN_GAME_TIME:
		pgn_game_set_time (self, g_value_get_string (value));
		break;
		case PGN_GAME_ROUND:
		pgn_game_set_round (self, g_value_get_string (value));
		break;
		case PGN_GAME_WHITE:
		pgn_game_set_white (self, g_value_get_string (value));
		break;
		case PGN_GAME_BLACK:
		pgn_game_set_black (self, g_value_get_string (value));
		break;
		case PGN_GAME_RESULT:
		pgn_game_set_result (self, g_value_get_string (value));
		break;
		case PGN_GAME_ANNOTATOR:
		pgn_game_set_annotator (self, g_value_get_string (value));
		break;
		case PGN_GAME_TIME_CONTROL:
		pgn_game_set_time_control (self, g_value_get_string (value));
		break;
		case PGN_GAME_WHITE_TIME_LEFT:
		pgn_game_set_white_time_left (self, g_value_get_string (value));
		break;
		case PGN_GAME_BLACK_TIME_LEFT:
		pgn_game_set_black_time_left (self, g_value_get_string (value));
		break;
		case PGN_GAME_SET_UP:
		pgn_game_set_set_up (self, g_value_get_boolean (value));
		break;
		case PGN_GAME_FEN:
		pgn_game_set_fen (self, g_value_get_string (value));
		break;
		case PGN_GAME_TERMINATION:
		pgn_game_set_termination (self, g_value_get_string (value));
		break;
		case PGN_GAME_WHITE_AI:
		pgn_game_set_white_ai (self, g_value_get_string (value));
		break;
		case PGN_GAME_WHITE_LEVEL:
		pgn_game_set_white_level (self, g_value_get_string (value));
		break;
		case PGN_GAME_BLACK_AI:
		pgn_game_set_black_ai (self, g_value_get_string (value));
		break;
		case PGN_GAME_BLACK_LEVEL:
		pgn_game_set_black_level (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


GType state_get_type (void) {
	static volatile gsize state_type_id__volatile = 0;
	if (g_once_init_enter (&state_type_id__volatile)) {
		static const GEnumValue values[] = {{STATE_TAGS, "STATE_TAGS", "tags"}, {STATE_MOVE_TEXT, "STATE_MOVE_TEXT", "move-text"}, {STATE_LINE_COMMENT, "STATE_LINE_COMMENT", "line-comment"}, {STATE_BRACE_COMMENT, "STATE_BRACE_COMMENT", "brace-comment"}, {STATE_TAG_START, "STATE_TAG_START", "tag-start"}, {STATE_TAG_NAME, "STATE_TAG_NAME", "tag-name"}, {STATE_PRE_TAG_VALUE, "STATE_PRE_TAG_VALUE", "pre-tag-value"}, {STATE_TAG_VALUE, "STATE_TAG_VALUE", "tag-value"}, {STATE_POST_TAG_VALUE, "STATE_POST_TAG_VALUE", "post-tag-value"}, {STATE_SYMBOL, "STATE_SYMBOL", "symbol"}, {STATE_PERIOD, "STATE_PERIOD", "period"}, {STATE_NAG, "STATE_NAG", "nag"}, {STATE_ERROR, "STATE_ERROR", "error"}, {0, NULL, NULL}};
		GType state_type_id;
		state_type_id = g_enum_register_static ("State", values);
		g_once_init_leave (&state_type_id__volatile, state_type_id);
	}
	return state_type_id__volatile;
}


static void _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


static void _g_list_free__g_object_unref0_ (GList* self) {
	g_list_foreach (self, (GFunc) _g_object_unref0_, NULL);
	g_list_free (self);
}


static gchar string_get (const gchar* self, glong index) {
	gchar result = '\0';
	glong _tmp0_ = 0L;
	gchar _tmp1_ = '\0';
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = index;
	_tmp1_ = ((gchar*) self)[_tmp0_];
	result = _tmp1_;
	return result;
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static gchar* string_slice (const gchar* self, glong start, glong end) {
	gchar* result = NULL;
	glong string_length = 0L;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	glong _tmp2_ = 0L;
	glong _tmp5_ = 0L;
	gboolean _tmp8_ = FALSE;
	glong _tmp9_ = 0L;
	gboolean _tmp12_ = FALSE;
	glong _tmp13_ = 0L;
	glong _tmp16_ = 0L;
	glong _tmp17_ = 0L;
	glong _tmp18_ = 0L;
	glong _tmp19_ = 0L;
	glong _tmp20_ = 0L;
	gchar* _tmp21_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	_tmp2_ = start;
	if (_tmp2_ < ((glong) 0)) {
		glong _tmp3_ = 0L;
		glong _tmp4_ = 0L;
		_tmp3_ = string_length;
		_tmp4_ = start;
		start = _tmp3_ + _tmp4_;
	}
	_tmp5_ = end;
	if (_tmp5_ < ((glong) 0)) {
		glong _tmp6_ = 0L;
		glong _tmp7_ = 0L;
		_tmp6_ = string_length;
		_tmp7_ = end;
		end = _tmp6_ + _tmp7_;
	}
	_tmp9_ = start;
	if (_tmp9_ >= ((glong) 0)) {
		glong _tmp10_ = 0L;
		glong _tmp11_ = 0L;
		_tmp10_ = start;
		_tmp11_ = string_length;
		_tmp8_ = _tmp10_ <= _tmp11_;
	} else {
		_tmp8_ = FALSE;
	}
	g_return_val_if_fail (_tmp8_, NULL);
	_tmp13_ = end;
	if (_tmp13_ >= ((glong) 0)) {
		glong _tmp14_ = 0L;
		glong _tmp15_ = 0L;
		_tmp14_ = end;
		_tmp15_ = string_length;
		_tmp12_ = _tmp14_ <= _tmp15_;
	} else {
		_tmp12_ = FALSE;
	}
	g_return_val_if_fail (_tmp12_, NULL);
	_tmp16_ = start;
	_tmp17_ = end;
	g_return_val_if_fail (_tmp16_ <= _tmp17_, NULL);
	_tmp18_ = start;
	_tmp19_ = end;
	_tmp20_ = start;
	_tmp21_ = g_strndup (((gchar*) self) + _tmp18_, (gsize) (_tmp19_ - _tmp20_));
	result = _tmp21_;
	return result;
}


PGN* pgn_construct_from_string (GType object_type, const gchar* data, GError** error) {
	PGN * self = NULL;
	State state = 0;
	State home_state = 0;
	PGNGame* game = NULL;
	PGNGame* _tmp0_ = NULL;
	gboolean in_escape = FALSE;
	gsize token_start = 0UL;
	gsize line_offset = 0UL;
	gchar* tag_name = NULL;
	gchar* _tmp1_ = NULL;
	GString* tag_value = NULL;
	GString* _tmp2_ = NULL;
	gint line = 0;
	gint rav_level = 0;
	gboolean _tmp168_ = FALSE;
	PGNGame* _tmp169_ = NULL;
	GList* _tmp170_ = NULL;
	guint _tmp171_ = 0U;
	GList* _tmp177_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (data != NULL, NULL);
	self = (PGN*) g_object_new (object_type, NULL);
	state = STATE_TAGS;
	home_state = STATE_TAGS;
	_tmp0_ = pgn_game_new ();
	game = _tmp0_;
	in_escape = FALSE;
	token_start = (gsize) 0;
	line_offset = (gsize) 0;
	_tmp1_ = g_strdup ("");
	tag_name = _tmp1_;
	_tmp2_ = g_string_new ("");
	tag_value = _tmp2_;
	line = 1;
	rav_level = 0;
	{
		gsize offset = 0UL;
		offset = (gsize) 0;
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				gsize _tmp5_ = 0UL;
				const gchar* _tmp6_ = NULL;
				gint _tmp7_ = 0;
				gint _tmp8_ = 0;
				gunichar c = 0U;
				const gchar* _tmp9_ = NULL;
				gsize _tmp10_ = 0UL;
				gchar _tmp11_ = '\0';
				gunichar _tmp12_ = 0U;
				State _tmp15_ = 0;
				if (!_tmp3_) {
					gsize _tmp4_ = 0UL;
					_tmp4_ = offset;
					offset = _tmp4_ + 1;
				}
				_tmp3_ = FALSE;
				_tmp5_ = offset;
				_tmp6_ = data;
				_tmp7_ = strlen (_tmp6_);
				_tmp8_ = _tmp7_;
				if (!(_tmp5_ <= ((gsize) _tmp8_))) {
					break;
				}
				_tmp9_ = data;
				_tmp10_ = offset;
				_tmp11_ = string_get (_tmp9_, (glong) _tmp10_);
				c = (gunichar) _tmp11_;
				_tmp12_ = c;
				if (_tmp12_ == ((gunichar) '\n')) {
					gint _tmp13_ = 0;
					gsize _tmp14_ = 0UL;
					_tmp13_ = line;
					line = _tmp13_ + 1;
					_tmp14_ = offset;
					line_offset = _tmp14_ + 1;
				}
				_tmp15_ = state;
				switch (_tmp15_) {
					case STATE_TAGS:
					{
						gunichar _tmp16_ = 0U;
						gboolean _tmp17_ = FALSE;
						home_state = STATE_TAGS;
						_tmp16_ = c;
						_tmp17_ = g_unichar_isspace (_tmp16_);
						if (_tmp17_) {
						} else {
							gunichar _tmp18_ = 0U;
							_tmp18_ = c;
							if (_tmp18_ == ((gunichar) ';')) {
								state = STATE_LINE_COMMENT;
							} else {
								gunichar _tmp19_ = 0U;
								_tmp19_ = c;
								if (_tmp19_ == ((gunichar) '{')) {
									state = STATE_BRACE_COMMENT;
								} else {
									gunichar _tmp20_ = 0U;
									_tmp20_ = c;
									if (_tmp20_ == ((gunichar) '[')) {
										state = STATE_TAG_START;
									} else {
										gsize _tmp21_ = 0UL;
										_tmp21_ = offset;
										offset = _tmp21_ - 1;
										state = STATE_MOVE_TEXT;
										continue;
									}
								}
							}
						}
						break;
					}
					case STATE_MOVE_TEXT:
					{
						gunichar _tmp22_ = 0U;
						gboolean _tmp23_ = FALSE;
						home_state = STATE_MOVE_TEXT;
						_tmp22_ = c;
						_tmp23_ = g_unichar_isspace (_tmp22_);
						if (_tmp23_) {
						} else {
							gunichar _tmp24_ = 0U;
							_tmp24_ = c;
							if (_tmp24_ == ((gunichar) ';')) {
								state = STATE_LINE_COMMENT;
							} else {
								gunichar _tmp25_ = 0U;
								_tmp25_ = c;
								if (_tmp25_ == ((gunichar) '{')) {
									state = STATE_BRACE_COMMENT;
								} else {
									gunichar _tmp26_ = 0U;
									_tmp26_ = c;
									if (_tmp26_ == ((gunichar) '*')) {
										gint _tmp27_ = 0;
										_tmp27_ = rav_level;
										if (_tmp27_ == 0) {
											PGNGame* _tmp28_ = NULL;
											const gchar* _tmp29_ = NULL;
											PGNGame* _tmp30_ = NULL;
											PGNGame* _tmp31_ = NULL;
											PGNGame* _tmp32_ = NULL;
											_tmp28_ = game;
											_tmp29_ = pgn_game_RESULT_IN_PROGRESS;
											pgn_game_set_result (_tmp28_, _tmp29_);
											_tmp30_ = game;
											_tmp31_ = _g_object_ref0 (_tmp30_);
											self->games = g_list_append (self->games, _tmp31_);
											_tmp32_ = pgn_game_new ();
											_g_object_unref0 (game);
											game = _tmp32_;
											state = STATE_TAGS;
										}
									} else {
										gunichar _tmp33_ = 0U;
										_tmp33_ = c;
										if (_tmp33_ == ((gunichar) '.')) {
											gsize _tmp34_ = 0UL;
											_tmp34_ = offset;
											offset = _tmp34_ - 1;
											state = STATE_PERIOD;
										} else {
											gunichar _tmp35_ = 0U;
											gboolean _tmp36_ = FALSE;
											_tmp35_ = c;
											_tmp36_ = g_unichar_isalnum (_tmp35_);
											if (_tmp36_) {
												gsize _tmp37_ = 0UL;
												_tmp37_ = offset;
												token_start = _tmp37_;
												state = STATE_SYMBOL;
											} else {
												gunichar _tmp38_ = 0U;
												_tmp38_ = c;
												if (_tmp38_ == ((gunichar) '$')) {
													gsize _tmp39_ = 0UL;
													_tmp39_ = offset;
													token_start = _tmp39_ + 1;
													state = STATE_NAG;
												} else {
													gunichar _tmp40_ = 0U;
													_tmp40_ = c;
													if (_tmp40_ == ((gunichar) '(')) {
														gint _tmp41_ = 0;
														_tmp41_ = rav_level;
														rav_level = _tmp41_ + 1;
														continue;
													} else {
														gunichar _tmp42_ = 0U;
														_tmp42_ = c;
														if (_tmp42_ == ((gunichar) ')')) {
															gint _tmp43_ = 0;
															_tmp43_ = rav_level;
															if (_tmp43_ == 0) {
																state = STATE_ERROR;
															} else {
																gint _tmp44_ = 0;
																_tmp44_ = rav_level;
																rav_level = _tmp44_ - 1;
															}
														} else {
															state = STATE_ERROR;
														}
													}
												}
											}
										}
									}
								}
							}
						}
						break;
					}
					case STATE_LINE_COMMENT:
					{
						gunichar _tmp45_ = 0U;
						_tmp45_ = c;
						if (_tmp45_ == ((gunichar) '\n')) {
							State _tmp46_ = 0;
							_tmp46_ = home_state;
							state = _tmp46_;
						}
						break;
					}
					case STATE_BRACE_COMMENT:
					{
						gunichar _tmp47_ = 0U;
						_tmp47_ = c;
						if (_tmp47_ == ((gunichar) '}')) {
							State _tmp48_ = 0;
							_tmp48_ = home_state;
							state = _tmp48_;
						}
						break;
					}
					case STATE_TAG_START:
					{
						gunichar _tmp49_ = 0U;
						gboolean _tmp50_ = FALSE;
						_tmp49_ = c;
						_tmp50_ = g_unichar_isspace (_tmp49_);
						if (_tmp50_) {
							continue;
						} else {
							gunichar _tmp51_ = 0U;
							gboolean _tmp52_ = FALSE;
							_tmp51_ = c;
							_tmp52_ = g_unichar_isalnum (_tmp51_);
							if (_tmp52_) {
								gsize _tmp53_ = 0UL;
								_tmp53_ = offset;
								token_start = _tmp53_;
								state = STATE_TAG_NAME;
							} else {
								state = STATE_ERROR;
							}
						}
						break;
					}
					case STATE_TAG_NAME:
					{
						gunichar _tmp54_ = 0U;
						gboolean _tmp55_ = FALSE;
						_tmp54_ = c;
						_tmp55_ = g_unichar_isspace (_tmp54_);
						if (_tmp55_) {
							const gchar* _tmp56_ = NULL;
							gsize _tmp57_ = 0UL;
							gsize _tmp58_ = 0UL;
							gchar* _tmp59_ = NULL;
							_tmp56_ = data;
							_tmp57_ = token_start;
							_tmp58_ = offset;
							_tmp59_ = string_slice (_tmp56_, (glong) _tmp57_, (glong) _tmp58_);
							_g_free0 (tag_name);
							tag_name = _tmp59_;
							state = STATE_PRE_TAG_VALUE;
						} else {
							gboolean _tmp60_ = FALSE;
							gboolean _tmp61_ = FALSE;
							gboolean _tmp62_ = FALSE;
							gboolean _tmp63_ = FALSE;
							gboolean _tmp64_ = FALSE;
							gboolean _tmp65_ = FALSE;
							gunichar _tmp66_ = 0U;
							gboolean _tmp67_ = FALSE;
							_tmp66_ = c;
							_tmp67_ = g_unichar_isalnum (_tmp66_);
							if (_tmp67_) {
								_tmp65_ = TRUE;
							} else {
								gunichar _tmp68_ = 0U;
								_tmp68_ = c;
								_tmp65_ = _tmp68_ == ((gunichar) '_');
							}
							if (_tmp65_) {
								_tmp64_ = TRUE;
							} else {
								gunichar _tmp69_ = 0U;
								_tmp69_ = c;
								_tmp64_ = _tmp69_ == ((gunichar) '+');
							}
							if (_tmp64_) {
								_tmp63_ = TRUE;
							} else {
								gunichar _tmp70_ = 0U;
								_tmp70_ = c;
								_tmp63_ = _tmp70_ == ((gunichar) '#');
							}
							if (_tmp63_) {
								_tmp62_ = TRUE;
							} else {
								gunichar _tmp71_ = 0U;
								_tmp71_ = c;
								_tmp62_ = _tmp71_ == ((gunichar) '=');
							}
							if (_tmp62_) {
								_tmp61_ = TRUE;
							} else {
								gunichar _tmp72_ = 0U;
								_tmp72_ = c;
								_tmp61_ = _tmp72_ == ((gunichar) ':');
							}
							if (_tmp61_) {
								_tmp60_ = TRUE;
							} else {
								gunichar _tmp73_ = 0U;
								_tmp73_ = c;
								_tmp60_ = _tmp73_ == ((gunichar) '-');
							}
							if (_tmp60_) {
								continue;
							} else {
								state = STATE_ERROR;
							}
						}
						break;
					}
					case STATE_PRE_TAG_VALUE:
					{
						gunichar _tmp74_ = 0U;
						gboolean _tmp75_ = FALSE;
						_tmp74_ = c;
						_tmp75_ = g_unichar_isspace (_tmp74_);
						if (_tmp75_) {
							continue;
						} else {
							gunichar _tmp76_ = 0U;
							_tmp76_ = c;
							if (_tmp76_ == ((gunichar) '"')) {
								GString* _tmp77_ = NULL;
								state = STATE_TAG_VALUE;
								_tmp77_ = tag_value;
								g_string_erase (_tmp77_, (gssize) 0, (gssize) (-1));
								in_escape = FALSE;
							} else {
								state = STATE_ERROR;
							}
						}
						break;
					}
					case STATE_TAG_VALUE:
					{
						gboolean _tmp78_ = FALSE;
						gunichar _tmp79_ = 0U;
						_tmp79_ = c;
						if (_tmp79_ == ((gunichar) '\\')) {
							gboolean _tmp80_ = FALSE;
							_tmp80_ = in_escape;
							_tmp78_ = !_tmp80_;
						} else {
							_tmp78_ = FALSE;
						}
						if (_tmp78_) {
							in_escape = TRUE;
						} else {
							gboolean _tmp81_ = FALSE;
							gunichar _tmp82_ = 0U;
							_tmp82_ = c;
							if (_tmp82_ == ((gunichar) '"')) {
								gboolean _tmp83_ = FALSE;
								_tmp83_ = in_escape;
								_tmp81_ = !_tmp83_;
							} else {
								_tmp81_ = FALSE;
							}
							if (_tmp81_) {
								state = STATE_POST_TAG_VALUE;
							} else {
								gunichar _tmp84_ = 0U;
								gboolean _tmp85_ = FALSE;
								_tmp84_ = c;
								_tmp85_ = g_unichar_isprint (_tmp84_);
								if (_tmp85_) {
									GString* _tmp86_ = NULL;
									gunichar _tmp87_ = 0U;
									_tmp86_ = tag_value;
									_tmp87_ = c;
									g_string_append_unichar (_tmp86_, _tmp87_);
									in_escape = FALSE;
								} else {
									state = STATE_ERROR;
								}
							}
						}
						break;
					}
					case STATE_POST_TAG_VALUE:
					{
						gunichar _tmp88_ = 0U;
						gboolean _tmp89_ = FALSE;
						_tmp88_ = c;
						_tmp89_ = g_unichar_isspace (_tmp88_);
						if (_tmp89_) {
							continue;
						} else {
							gunichar _tmp90_ = 0U;
							_tmp90_ = c;
							if (_tmp90_ == ((gunichar) ']')) {
								PGNGame* _tmp91_ = NULL;
								GHashTable* _tmp92_ = NULL;
								const gchar* _tmp93_ = NULL;
								gchar* _tmp94_ = NULL;
								GString* _tmp95_ = NULL;
								const gchar* _tmp96_ = NULL;
								gchar* _tmp97_ = NULL;
								_tmp91_ = game;
								_tmp92_ = _tmp91_->tags;
								_tmp93_ = tag_name;
								_tmp94_ = g_strdup (_tmp93_);
								_tmp95_ = tag_value;
								_tmp96_ = _tmp95_->str;
								_tmp97_ = g_strdup (_tmp96_);
								g_hash_table_insert (_tmp92_, _tmp94_, _tmp97_);
								state = STATE_TAGS;
							} else {
								state = STATE_ERROR;
							}
						}
						break;
					}
					case STATE_SYMBOL:
					{
						gboolean _tmp98_ = FALSE;
						gboolean _tmp99_ = FALSE;
						gboolean _tmp100_ = FALSE;
						gboolean _tmp101_ = FALSE;
						gboolean _tmp102_ = FALSE;
						gboolean _tmp103_ = FALSE;
						gboolean _tmp104_ = FALSE;
						gunichar _tmp105_ = 0U;
						gboolean _tmp106_ = FALSE;
						_tmp105_ = c;
						_tmp106_ = g_unichar_isalnum (_tmp105_);
						if (_tmp106_) {
							_tmp104_ = TRUE;
						} else {
							gunichar _tmp107_ = 0U;
							_tmp107_ = c;
							_tmp104_ = _tmp107_ == ((gunichar) '_');
						}
						if (_tmp104_) {
							_tmp103_ = TRUE;
						} else {
							gunichar _tmp108_ = 0U;
							_tmp108_ = c;
							_tmp103_ = _tmp108_ == ((gunichar) '+');
						}
						if (_tmp103_) {
							_tmp102_ = TRUE;
						} else {
							gunichar _tmp109_ = 0U;
							_tmp109_ = c;
							_tmp102_ = _tmp109_ == ((gunichar) '#');
						}
						if (_tmp102_) {
							_tmp101_ = TRUE;
						} else {
							gunichar _tmp110_ = 0U;
							_tmp110_ = c;
							_tmp101_ = _tmp110_ == ((gunichar) '=');
						}
						if (_tmp101_) {
							_tmp100_ = TRUE;
						} else {
							gunichar _tmp111_ = 0U;
							_tmp111_ = c;
							_tmp100_ = _tmp111_ == ((gunichar) ':');
						}
						if (_tmp100_) {
							_tmp99_ = TRUE;
						} else {
							gunichar _tmp112_ = 0U;
							_tmp112_ = c;
							_tmp99_ = _tmp112_ == ((gunichar) '-');
						}
						if (_tmp99_) {
							_tmp98_ = TRUE;
						} else {
							gunichar _tmp113_ = 0U;
							_tmp113_ = c;
							_tmp98_ = _tmp113_ == ((gunichar) '/');
						}
						if (_tmp98_) {
							continue;
						} else {
							gchar* symbol = NULL;
							const gchar* _tmp114_ = NULL;
							gsize _tmp115_ = 0UL;
							gsize _tmp116_ = 0UL;
							gchar* _tmp117_ = NULL;
							gboolean is_number = FALSE;
							gsize _tmp128_ = 0UL;
							gboolean _tmp129_ = FALSE;
							gboolean _tmp130_ = FALSE;
							const gchar* _tmp131_ = NULL;
							const gchar* _tmp132_ = NULL;
							_tmp114_ = data;
							_tmp115_ = token_start;
							_tmp116_ = offset;
							_tmp117_ = string_slice (_tmp114_, (glong) _tmp115_, (glong) _tmp116_);
							symbol = _tmp117_;
							is_number = TRUE;
							{
								gint i = 0;
								i = 0;
								{
									gboolean _tmp118_ = FALSE;
									_tmp118_ = TRUE;
									while (TRUE) {
										gint _tmp120_ = 0;
										const gchar* _tmp121_ = NULL;
										gint _tmp122_ = 0;
										gint _tmp123_ = 0;
										const gchar* _tmp124_ = NULL;
										gint _tmp125_ = 0;
										gchar _tmp126_ = '\0';
										gboolean _tmp127_ = FALSE;
										if (!_tmp118_) {
											gint _tmp119_ = 0;
											_tmp119_ = i;
											i = _tmp119_ + 1;
										}
										_tmp118_ = FALSE;
										_tmp120_ = i;
										_tmp121_ = symbol;
										_tmp122_ = strlen (_tmp121_);
										_tmp123_ = _tmp122_;
										if (!(_tmp120_ < _tmp123_)) {
											break;
										}
										_tmp124_ = symbol;
										_tmp125_ = i;
										_tmp126_ = string_get (_tmp124_, (glong) _tmp125_);
										_tmp127_ = g_ascii_isdigit (_tmp126_);
										if (!_tmp127_) {
											is_number = FALSE;
										}
									}
								}
							}
							state = STATE_MOVE_TEXT;
							_tmp128_ = offset;
							offset = _tmp128_ - 1;
							_tmp131_ = symbol;
							_tmp132_ = pgn_game_RESULT_DRAW;
							if (g_strcmp0 (_tmp131_, _tmp132_) == 0) {
								_tmp130_ = TRUE;
							} else {
								const gchar* _tmp133_ = NULL;
								const gchar* _tmp134_ = NULL;
								_tmp133_ = symbol;
								_tmp134_ = pgn_game_RESULT_WHITE;
								_tmp130_ = g_strcmp0 (_tmp133_, _tmp134_) == 0;
							}
							if (_tmp130_) {
								_tmp129_ = TRUE;
							} else {
								const gchar* _tmp135_ = NULL;
								const gchar* _tmp136_ = NULL;
								_tmp135_ = symbol;
								_tmp136_ = pgn_game_RESULT_BLACK;
								_tmp129_ = g_strcmp0 (_tmp135_, _tmp136_) == 0;
							}
							if (_tmp129_) {
								gint _tmp137_ = 0;
								_tmp137_ = rav_level;
								if (_tmp137_ == 0) {
									PGNGame* _tmp138_ = NULL;
									const gchar* _tmp139_ = NULL;
									PGNGame* _tmp140_ = NULL;
									PGNGame* _tmp141_ = NULL;
									PGNGame* _tmp142_ = NULL;
									_tmp138_ = game;
									_tmp139_ = symbol;
									pgn_game_set_result (_tmp138_, _tmp139_);
									_tmp140_ = game;
									_tmp141_ = _g_object_ref0 (_tmp140_);
									self->games = g_list_append (self->games, _tmp141_);
									_tmp142_ = pgn_game_new ();
									_g_object_unref0 (game);
									game = _tmp142_;
									state = STATE_TAGS;
								}
							} else {
								gboolean _tmp143_ = FALSE;
								_tmp143_ = is_number;
								if (!_tmp143_) {
									gint _tmp144_ = 0;
									_tmp144_ = rav_level;
									if (_tmp144_ == 0) {
										PGNGame* _tmp145_ = NULL;
										const gchar* _tmp146_ = NULL;
										gchar* _tmp147_ = NULL;
										_tmp145_ = game;
										_tmp146_ = symbol;
										_tmp147_ = g_strdup (_tmp146_);
										_tmp145_->moves = g_list_append (_tmp145_->moves, _tmp147_);
									}
								}
							}
							_g_free0 (symbol);
						}
						break;
					}
					case STATE_PERIOD:
					{
						state = STATE_MOVE_TEXT;
						break;
					}
					case STATE_NAG:
					{
						gunichar _tmp148_ = 0U;
						gboolean _tmp149_ = FALSE;
						_tmp148_ = c;
						_tmp149_ = g_unichar_isdigit (_tmp148_);
						if (_tmp149_) {
							continue;
						} else {
							gsize _tmp150_ = 0UL;
							state = STATE_MOVE_TEXT;
							_tmp150_ = offset;
							offset = _tmp150_ - 1;
						}
						break;
					}
					case STATE_ERROR:
					{
						gsize char_offset = 0UL;
						gsize _tmp151_ = 0UL;
						gsize _tmp152_ = 0UL;
						FILE* _tmp153_ = NULL;
						gint _tmp154_ = 0;
						gsize _tmp155_ = 0UL;
						FILE* _tmp156_ = NULL;
						const gchar* _tmp157_ = NULL;
						gsize _tmp158_ = 0UL;
						gsize _tmp159_ = 0UL;
						gchar* _tmp160_ = NULL;
						gchar* _tmp161_ = NULL;
						FILE* _tmp167_ = NULL;
						_tmp151_ = offset;
						_tmp152_ = line_offset;
						char_offset = (_tmp151_ - _tmp152_) - 1;
						_tmp153_ = stderr;
						_tmp154_ = line;
						_tmp155_ = char_offset;
						fprintf (_tmp153_, "%d.%d: error: Unexpected character\n", _tmp154_, (gint) (_tmp155_ + 1));
						_tmp156_ = stderr;
						_tmp157_ = data;
						_tmp158_ = line_offset;
						_tmp159_ = offset;
						_tmp160_ = string_slice (_tmp157_, (glong) _tmp158_, (glong) _tmp159_);
						_tmp161_ = _tmp160_;
						fprintf (_tmp156_, "%s\n", _tmp161_);
						_g_free0 (_tmp161_);
						{
							gint i = 0;
							i = 0;
							{
								gboolean _tmp162_ = FALSE;
								_tmp162_ = TRUE;
								while (TRUE) {
									gint _tmp164_ = 0;
									gsize _tmp165_ = 0UL;
									FILE* _tmp166_ = NULL;
									if (!_tmp162_) {
										gint _tmp163_ = 0;
										_tmp163_ = i;
										i = _tmp163_ + 1;
									}
									_tmp162_ = FALSE;
									_tmp164_ = i;
									_tmp165_ = char_offset;
									if (!(((gsize) _tmp164_) < _tmp165_)) {
										break;
									}
									_tmp166_ = stderr;
									fprintf (_tmp166_, " ");
								}
							}
						}
						_tmp167_ = stderr;
						fprintf (_tmp167_, "^\n");
						_g_string_free0 (tag_value);
						_g_free0 (tag_name);
						_g_object_unref0 (game);
						return self;
					}
					default:
					break;
				}
			}
		}
	}
	_tmp169_ = game;
	_tmp170_ = _tmp169_->moves;
	_tmp171_ = g_list_length (_tmp170_);
	if (_tmp171_ > ((guint) 0)) {
		_tmp168_ = TRUE;
	} else {
		PGNGame* _tmp172_ = NULL;
		GHashTable* _tmp173_ = NULL;
		guint _tmp174_ = 0U;
		_tmp172_ = game;
		_tmp173_ = _tmp172_->tags;
		_tmp174_ = g_hash_table_size (_tmp173_);
		_tmp168_ = _tmp174_ > ((guint) 0);
	}
	if (_tmp168_) {
		PGNGame* _tmp175_ = NULL;
		PGNGame* _tmp176_ = NULL;
		_tmp175_ = game;
		_tmp176_ = _g_object_ref0 (_tmp175_);
		self->games = g_list_append (self->games, _tmp176_);
	}
	_tmp177_ = self->games;
	if (_tmp177_ == NULL) {
		GError* _tmp178_ = NULL;
		_tmp178_ = g_error_new_literal (PGN_ERROR, PGN_ERROR_LOAD_ERROR, "No games in PGN file");
		_inner_error_ = _tmp178_;
		if (_inner_error_->domain == PGN_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_string_free0 (tag_value);
			_g_free0 (tag_name);
			_g_object_unref0 (game);
			_g_object_unref0 (self);
			return NULL;
		} else {
			_g_string_free0 (tag_value);
			_g_free0 (tag_name);
			_g_object_unref0 (game);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_g_string_free0 (tag_value);
	_g_free0 (tag_name);
	_g_object_unref0 (game);
	return self;
}


PGN* pgn_new_from_string (const gchar* data, GError** error) {
	return pgn_construct_from_string (TYPE_PGN, data, error);
}


PGN* pgn_construct_from_file (GType object_type, GFile* file, GError** error) {
	PGN * self = NULL;
	guint8* contents = NULL;
	gint contents_length1 = 0;
	gint _contents_size_ = 0;
	GFile* _tmp0_ = NULL;
	guint8* _tmp1_ = NULL;
	gsize _tmp2_;
	guint8* _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (file != NULL, NULL);
	_tmp0_ = file;
	g_file_load_contents (_tmp0_, NULL, &_tmp1_, &_tmp2_, NULL, &_inner_error_);
	contents = (g_free (contents), NULL);
	contents = _tmp1_;
	contents_length1 = _tmp2_;
	_contents_size_ = contents_length1;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		contents = (g_free (contents), NULL);
		_g_object_unref0 (self);
		return NULL;
	}
	_tmp3_ = contents;
	_tmp3__length1 = contents_length1;
	self = (PGN*) pgn_construct_from_string (object_type, (const gchar*) _tmp3_, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		contents = (g_free (contents), NULL);
		_g_object_unref0 (self);
		return NULL;
	}
	contents = (g_free (contents), NULL);
	return self;
}


PGN* pgn_new_from_file (GFile* file, GError** error) {
	return pgn_construct_from_file (TYPE_PGN, file, error);
}


PGN* pgn_construct (GType object_type) {
	PGN * self = NULL;
	self = (PGN*) g_object_new (object_type, NULL);
	return self;
}


PGN* pgn_new (void) {
	return pgn_construct (TYPE_PGN);
}


static void pgn_class_init (PGNClass * klass) {
	pgn_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = pgn_finalize;
}


static void pgn_instance_init (PGN * self) {
}


static void pgn_finalize (GObject* obj) {
	PGN * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_PGN, PGN);
	__g_list_free__g_object_unref0_0 (self->games);
	G_OBJECT_CLASS (pgn_parent_class)->finalize (obj);
}


GType pgn_get_type (void) {
	static volatile gsize pgn_type_id__volatile = 0;
	if (g_once_init_enter (&pgn_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (PGNClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pgn_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PGN), 0, (GInstanceInitFunc) pgn_instance_init, NULL };
		GType pgn_type_id;
		pgn_type_id = g_type_register_static (G_TYPE_OBJECT, "PGN", &g_define_type_info, 0);
		g_once_init_leave (&pgn_type_id__volatile, pgn_type_id);
	}
	return pgn_type_id__volatile;
}



