#ifndef _lexer

#define _lexer


#include <array.h>

#include <string.h>

#include <text.h>

#include <lexer.h>

#include <stdio.h>

#include <string.h>

#include <pcre.h>

#define OVECCOUNT 30    /* should be a multiple of 3 */


typedef struct lexer{

	int * keys;

	char * * tokens;

    int capacity;

    int total;

    int index;

} lexer;



lexer * lexer_new();

int lexer_length( lexer * v );

void lexer_resize( lexer * currentLexer, int capacity );

void lexer_add( lexer * currentLexer, int key, char * token  );

char * lexer_getToken( lexer * currentLexer, int index  );

int lexer_getKey( lexer * currentLexer, int index );

void lexer_setIndex( lexer * currentLexer, int index );

int lexer_tokenize( lexer * currentLexer, char * haystack, char * needle );

void lexer_sortKeys(  lexer * currentLexer );

int lexer_findNextToken( lexer * currentLexer, int fromKey, char * token );

int lexer_findPreviousTokenIndex( lexer * currentLexer, int fromKey, char * token );

int lexer_tokenizeRegex( lexer * currentLexer, char * haystack, char * needle, char * token );

void lexer_getTokens( lexer * currentLexer, char * source );

int lexer_findBodyCloseIndex( lexer * currentLexer, int fromKey );

int lexer_findPreviouseTokenIndex( lexer * currentLexer, int fromIndex, struct array * validPreviousTokens );

int lexer_findNextTokenIndex( lexer * currentLexer, int fromKey, char * token );

int lexer_findPreviousKeyByToken( lexer * currentLexer, int fromKey, char * token );

void lexer_setSource( lexer * currentLexer, char * source );

int lexer_findPreviousToken( lexer * currentLexer, int fromKey, char * token );

void lexer_sortKeys_separate( struct array * keys, struct array * tokens );

#endif