/*
 * Copyright (c) 2011-2012 Balabit
 * Copyright (c) 2011-2012 Gergely Nagy <algernon@balabit.hu>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * As an additional exemption you are allowed to compile & link against the
 * OpenSSL libraries as published by the OpenSSL project. See the file
 * COPYING for details.
 */

%code top {
#include "json-parser-parser.h"

}


%code {

#include "json-parser.h"
#include "cfg-parser.h"
#include "syslog-names.h"
#include "messages.h"
#include "cfg-grammar-internal.h"

}

%define api.prefix {json_parser_}

/* this parameter is needed in order to instruct bison to use a complete
 * argument list for yylex/yyerror */

%lex-param {CfgLexer *lexer}
%parse-param {CfgLexer *lexer}
%parse-param {LogParser **instance}
%parse-param {gpointer arg}

/* INCLUDE_DECLS */

%token KW_JSON_PARSER
%token KW_PREFIX
%token KW_MARKER
%token KW_EXTRACT_PREFIX

%type	<ptr> parser_expr_json

%%

start
	: LL_CONTEXT_PARSER parser_expr_json                  { YYACCEPT; }
	;


parser_expr_json
	: KW_JSON_PARSER '('
	  {
	    last_parser = *instance = (LogParser *) json_parser_new(configuration);
	  }
	  parser_json_opts
	  ')'					{ $$ = last_parser; }
	;

parser_json_opts
	: parser_json_opt parser_json_opts
	|
	;

parser_json_opt
	: KW_PREFIX '(' string ')'		{ json_parser_set_prefix(last_parser, $3); free($3); }
	| KW_MARKER '(' string ')'		{ json_parser_set_marker(last_parser, $3); free($3); }
	| KW_EXTRACT_PREFIX '(' string  ')'      { json_parser_set_extract_prefix(last_parser, $3); free($3); }
	| parser_opt
	;

/* INCLUDE_RULES */

%%
