/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0.  If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V.
 */

#ifndef _SQL_PARSER_H_
#define _SQL_PARSER_H_

#include "sql_mvc.h"

/* the next define makes the parser output more specific error messages,
 * instead of only a dull 'parse error' */
#define YYERROR_VERBOSE 1
/* enable this to get an idea of what the parser is doing on stdout
#define YYDEBUG 1
*/

typedef enum tokens {
	SQL_CREATE_SCHEMA,
	SQL_CREATE_TABLE,
	SQL_CREATE_VIEW,
	SQL_CREATE_INDEX,
	SQL_CREATE_ROLE,
	SQL_CREATE_USER,
	SQL_CREATE_TYPE,
	SQL_CREATE_FUNC,
	SQL_CREATE_SEQ,
	SQL_CREATE_TRIGGER,
	SQL_CREATE_TABLE_LOADER,
	SQL_DROP_SCHEMA,
	SQL_DROP_TABLE,
	SQL_DROP_VIEW,
	SQL_DROP_INDEX,
	SQL_DROP_ROLE,
	SQL_DROP_USER,
	SQL_DROP_TYPE,
	SQL_DROP_FUNC,
	SQL_DROP_SEQ,
	SQL_DROP_TRIGGER,
	SQL_ALTER_TABLE,
	SQL_ALTER_SEQ,
	SQL_ALTER_USER,
	SQL_RENAME_USER,
	SQL_DROP_COLUMN,
	SQL_DROP_CONSTRAINT,
	SQL_DROP_DEFAULT,
	SQL_ANALYZE,
	SQL_DECLARE,
	SQL_COMMENT,
	SQL_SET,
	SQL_CALL,
	SQL_PREP,
	SQL_PREPARE,
	SQL_NAME,
	SQL_USER,
	SQL_PATH,
	SQL_CHARSET,
	SQL_SCHEMA,
	SQL_TABLE,
	SQL_TABLE_OPERATOR,
	SQL_VIEW,
	SQL_INDEX,
	SQL_TYPE,
	SQL_SEQUENCE,
	SQL_CASE,
	SQL_CAST,
	SQL_RETURN,
	SQL_IF,
	SQL_ELSE,
	SQL_WHILE,
	SQL_COLUMN,
	SQL_COLUMN_OPT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QL_COPYFROM,
	SQL_BINCOPYFROM,
	SQL_COPYLOADER,
	SQL_COPYTO,
	SQL_EXPORT,
	SQL_NEXT,
	SQL_MULSTMT,
	SQL_WITH,
	SQL_START,
	SQL_INC,
	SQL_MINVALUE,
	SQL_MAXVALUE,
	SQL_CACHE,
	SQL_CYCLE,
	SQL_XMLCOMMENT,
	SQL_XMLCONCAT,
	SQL_XMLDOCUMENT,
	SQL_XMLELEMENT,
	SQL_XMLATTRIBUTE,
	SQL_XMLFOREST,
	SQL_XMLPARSE,
	SQL_XMLPI,
	SQL_XMLQUERY,
	SQL_XMLTEXT,
	SQL_XMLVALIDATE,
	SQL_XMLNAMESPACES
} tokens;

typedef enum jt {
	jt_inner = 0,
	jt_left = 1,
	jt_right = 2,
	jt_full = 3,
	jt_union = 4
} jt;

extern int find_subgeometry_type(char*);
extern char *token2string(int token);
extern int sqlparse(mvc *m);
extern int sqlerror(mvc *sql, const char *s);

#include "mal_errors.h"		/* for SQLSTATE() */

#endif /*_SQL_PARSER_H_*/

