#ifndef V_PARSE_H
#define V_PARSE_H

#ifdef  CONFIG_SCANNER

typedef vhandle_t   scanner_t;

#ifdef  __cplusplus
extern  "C" {
#endif  /* __cplusplus */
    /*
     * Different constructors
     */
    /* Create scanner for in-memory buffer; 'buffer' must be valid while scanning */
    scanner_t V_GLOBAL  tokParseBuffer(char *buffer,u32_t buffer_len,char *delim);
    /* Same as above, buffer_len determined as strlen(buffer) */
    scanner_t V_GLOBAL  tokParseString(char *buffer,char *delim);
    /* File scanner */
    scanner_t V_GLOBAL  tokParseFile(char *filename,char *delim);
    /* Resets position to start, optionally (if args != NULL) 
     * sets new source and delimiters. */
    void        V_GLOBAL    tokRestartEx(scanner_t tok,
        char *new_buffer,char *new_delim);
    void        V_GLOBAL    tokRestart(scanner_t tok);
    /* Saving/restoring scanner's cursor position */
    vboolean    V_GLOBAL    tokPush(scanner_t tok);
    vboolean    V_GLOBAL    tokPop(scanner_t tok);
    void    	V_GLOBAL	tokClearStateStack(scanner_t tok);
    /* Returns current line number (number of passed 0x0A's) */
    u32_t       V_GLOBAL    tokCurrentLine(scanner_t tok);
    /* Returns line number of last parsed token */
	u32_t		V_GLOBAL	tokLastLine(scanner_t tok);
    /* Sets char for single-line comments (0 means 'not defined'),
       returns old comment char */
	char		V_GLOBAL	tokCommentChar(scanner_t handle,
		char comment_char);
    /*
     * Returns next token or NULL if no more tokens
     */
    char_p      V_GLOBAL    tokNext(scanner_t tok);
    /*
    TODO
    char_p      V_GLOBAL    tokNextEx(scanner_t tok,vboolean crossline);
    */
    /*
     *  Same as tokNext(), whitespace and quotes handled as usual chars.
     */
    char_p      V_GLOBAL    tokStrict(scanner_t tok);
    /*  Returns next string (i.e. sequence ended with EOL);
     *  EOL itself NOT stored in result.
     */
    char_p      V_GLOBAL    tokString(scanner_t tok);
    /*
     *  Returns last result of tok[Next | Strict | String], or
     *  NULL if:
     *      - was no previous call to mentioned functions;
     *      - no more chars (or something else wrong).
     */
    char_p      V_GLOBAL    tokLast(scanner_t tok);
    /*
     * if tokNext() returns non-NULL, copies token to 'buf'.
     * Returns number of copied chars.
     */
	u32_t V_GLOBAL tokCopyNextToken(vhandle_t scanner,char *buf,u32_t buf_len);
    /*
     * if tokLast() returns non-NULL, copies token to 'buf'.
     * Returns number of copied chars.
     */
	u32_t V_GLOBAL tokCopyLastToken(vhandle_t scanner,char *buf,u32_t buf_len);

    /*	Reads words while the pair to 'skip_from' not reached */
	vboolean V_GLOBAL	tokSkipBlock(scanner_t scanner,char skip_from);
	/*	Reads words while 'token' not reached */
	vboolean V_GLOBAL	tokSkipTo(vhandle_t scanner,char *token);
	vboolean V_GLOBAL	tokSkipToEx(vhandle_t scanner,char *token,
		int (*str_comp)(const char *s1,const char *s2));
	/*	Returns true if tokNext() returns 'expected_token' */
	vboolean V_GLOBAL	tokNextIs(scanner_t scanner,char *expected_token);
	/*	Returns true if tokLast() returns 'expected_token' */
	vboolean V_GLOBAL	tokLastWas(scanner_t scanner,char *expected_token);
	/*	Returns true if tokNext() returns 'expected_token' */
	vboolean V_GLOBAL	tokNextIsEx(scanner_t scanner,char *expected_token,
		int (*str_comp)(const char *s1,const char *s2));
	/*	Returns true if tokLast() returns 'expected_token' */
	vboolean V_GLOBAL	tokLastWasEx(scanner_t scanner,char *expected_token,
		int (*str_comp)(const char *s1,const char *s2));
	/*	Reads integer */
	vboolean V_GLOBAL	tokNextInteger(scanner_t scanner,s32_t *ret_val);
	/*	Returns last read integer */
	vboolean V_GLOBAL	tokLastInteger(scanner_t scanner,s32_t *ret_val);
	/*	Reads float */
	vboolean V_GLOBAL	tokNextFloat(scanner_t scanner,vec_t *ret_val);
	/*	Returns last read float */
	vboolean V_GLOBAL	tokLastFloat(scanner_t scanner,vec_t *ret_val);
    /*  Destroys scanner */
    void        V_GLOBAL    tokDestroy(scanner_t tok);
#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* CONFIG_SCANNER */

#endif /* V_PARSE_H */
