#ifndef ARC_STD_PARSER_PARSERLANG_H_
#define ARC_STD_PARSER_PARSERLANG_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "arc/std/bool.h"
#include "arc/std/parser.h"
#include "arc/std/string.h"
#include <stdint.h>

/*
<line>         -> <data> NEWLINE <line> | <data> | NEWLINE <line> | LAMBDA
<data>         -> <string> COMMA <data> | <string>
<string>       -> <nonCommaChar> <string> | <nonCommaChar>
<nonCommaChar> -> CHAR_BEFORE_COMMA | CHAR_AFTER_COMMA
*/

/**
 * @brief a callback for the csv parser to use to cast that data the stored data
 *
 * @note this callback will only be called on non-header data
 *
 * @param[in/out] data   the csv data casted into the users type
 * @param[in]     string an value of the csv as a string
*/
typedef void (* ARC_ParserCSV_CastTypeFn)(void **data, ARC_String *string);

/**
 * @brief a callback for the csv parser to use to free csv data
 *
 * @note this callback will only be called on non-header data
 *
 * @param[in] data the csv data to free
*/
typedef void (* ARC_ParserCSV_DestroyTypeFn)(void *data);

/**
 * @brief defines a csv data type, data is set by the callback passed in when createing a parserCSV as parser
 *
 * @note this data can be retieved after parsing by calling get data, check arc/std/parser.h for more information
*/
typedef struct ARC_ParserCSVData {
    ARC_Bool hasHeader;
    ARC_String **headers;

    uint32_t width;
    uint32_t height;
    void ***data;
} ARC_ParserCSVData;

/**
 * @brief creates a parser for the Parser Lang
 *
 * @note the rules will be inited for the parser lang
 * @note the parsed data will be saved as a vector of ARC_ParserLanguageTag
 *
 * @param[out] parser the parser to create
*/
void ARC_ParserCSV_CreateAsParser(ARC_Parser **parser, ARC_Bool header, ARC_ParserCSV_CastTypeFn castTypeFn, ARC_ParserCSV_DestroyTypeFn destroyTypeFn);

#define ARC_PARSER_CSV_CHAR_COMMA        1
#define ARC_PARSER_CSV_CHAR_NEWLINE      2
#define ARC_PARSER_CSV_CHAR_BEFORE_COMMA 3
#define ARC_PARSER_CSV_CHAR_AFTER_COMMA  4
#define ARC_PARSER_CSV_LINE              5
#define ARC_PARSER_CSV_DATA              6
#define ARC_PARSER_CSV_STRING            7
#define ARC_PARSER_CSV_NON_COMMA_CHAR    8

#ifdef __cplusplus
}
#endif

#endif //ARC_STD_PARSER_PARSERLANG_H_
