#ifndef _gammar_h
#define _gammar_h

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum
{
	  gr_type_none = 0
	, gr_type_var		// "id id" or "id id (params)"
	, gr_type_attr		// "id" or "id (params)"
	, gr_type_list          // "id [idlist]"
	, gr_type_int_prop	// "id = integer"
	, gr_type_attr_prop     // "id = attr"
	, gr_type_str_prop      // "id = \"string\""
	, gr_type_max
} gr_type;

typedef struct gr_node
{
	struct gr_node*	pnext;
	gr_type		type;
	int		line;
	int		column;
	char*		pname;
	int		ivalue;
	char*		pstring;
	struct gr_node*	pparams;
} gr_node;

typedef struct
{
	const char*	m_filename;
	gr_node*	m_ptop;
	// Work data
	FILE*		m_file;
	char*		symbuf;
	int		length;
	int		cur_line;
	int		cur_col;
	int		prev_col;
	int		cur_char;
	int		prev_char;
} gr_tree;

gr_node* var_new_var(int line, int column, char* ptype, char* pname, gr_node* pparams);
gr_node* var_new_attr(int line, int column, char* pname, gr_node* pparams);
gr_node* var_new_list(int line, int column, char* pname, gr_node* pparams);
gr_node* var_new_int_prop(int line, int column, char* pname, int value);
gr_node* var_new_attr_prop(int line, int column, char* pname, gr_node* pattr);
gr_node* var_new_str_prop(int line, int column, char* pname, char* pstring);
void var_delete(gr_node** pvar);
gr_tree* grtree_parse(const char* filename);
void grtree_delete(gr_tree* ptree);

typedef enum
{
	  grtree_type_definitions
	, grtree_type_max
} grtree_type;

#ifdef __cplusplus
}
#endif

#endif
