<commit_before>
// -*- C++ -*-

// (c) COPYRIGHT URI/MIT 1996
// Please read the full copyright statement in the file COPYRIGH.  
//
// Authors:
//      jhrg,jimg       <NAME> (<EMAIL>)


// $Log: Error.y,v $
// Revision 1.4  1996/10/16 22:35:56  jimg
// Fixed bad operator in DODS_BISON_VER preprocessor statement.
//
// Revision 1.3  1996/10/08 17:04:39  jimg
// Added a fix for Bison 1.25 so that PARSE_PARAM will still work
//
// Revision 1.2  1996/08/13 18:21:19  jimg
// Switched to parser_arg object for communication with caller.
// Fixed bogus declaration of Errorerror() (from int to void).
//
// Revision 1.1  1996/05/31 23:18:17  jimg
// Added.

%{

#include "config_dap.h"

static char rcsid[] __unused__ = {"$Id: Error.y,v 1.4 1996/10/16 22:35:56 jimg Exp $"};

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <iostream.h>

#include "Error.h"

#include "parser.h"
#include "debug.h"

// These macros are used to access the `arguments' passed to the parser. A
// pointer to an error object and a pointer to an integer status variable are
// passed in to the parser within a strucutre (which itself is passed as a
// pointer). Note that the ERROR macro explicitly casts OBJ to an ERROR *. 

#define ERROR_OBJ(arg) ((Error *)((parser_arg *)(arg))->_object)
#define STATUS(arg) ((parser_arg *)(arg))->_status
#if DODS_BISON_VER > 124
#define YYPARSE_PARAM arg
#else
#define YYPARSE_PARAM void *arg
#endif

extern int error_line_num;	// defined in Error.lex

int Errorlex();			// the scanner
void Errorerror(char *s);	// gotta love automatically generated names...

%}

%union {
    bool boolean;
    int integer;
    char *string;
}

%token <integer> INT
%token <string> STR

%token <integer> ERROR
%token <integer> CODE
%token <integer> PTYPE
%token <string> MSG
%token <string> PROGRAM

%type <boolean> error_object contents description program
%type <boolean> code program_type message program_code

%%

// The parser is called through a function named ERRORPARSE which takes a
// pointer to a structure and returns a boolean. The structure contains a
// pointer to an Error object which is empty and an integer which contains
// status information. In addition the parser_arg strucuture contains a
// pointer to an error object. However, the `error' member of parser_arg is
// not yet used here.

error_object:	ERROR '{' contents '}' ';' { $$ = $3; STATUS(arg) = $3; }
;

contents:	description program { $$ = $1 && $2; }
;

description:	code message { $$ = $1 && $2; }
;

program:	program_type program_code { $$ = $1 && $2; }
;

code:		CODE '=' INT ';' 
		{ 
		    ERROR_OBJ(arg)->error_code((ErrorCode)$3);
		    $$ = true; 
		}
;

message:	MSG '=' STR 
		{ 
		    ERROR_OBJ(arg)->error_message($3);
		    $$ = true; 
		} <commit_msg>Changed grammar to allow Error objects which have no `program' component. That is, the program part is absent. Previously the program part had to be there even if the fields had null values.<commit_after>
// -*- C++ -*-

// (c) COPYRIGHT URI/MIT 1996
// Please read the full copyright statement in the file COPYRIGH.  
//
// Authors:
//      jhrg,jimg       <NAME> (<EMAIL>)


// $Log: Error.y,v $
// Revision 1.5  1997/02/14 23:56:11  jimg
// Changed grammar to allow Error objects which have no `program' component.
// That is, the program part is absent. Previously the program part had to be
// there even if the fields had null values.
//
// Revision 1.4  1996/10/16 22:35:56  jimg
// Fixed bad operator in DODS_BISON_VER preprocessor statement.
//
// Revision 1.3  1996/10/08 17:04:39  jimg
// Added a fix for Bison 1.25 so that PARSE_PARAM will still work
//
// Revision 1.2  1996/08/13 18:21:19  jimg
// Switched to parser_arg object for communication with caller.
// Fixed bogus declaration of Errorerror() (from int to void).
//
// Revision 1.1  1996/05/31 23:18:17  jimg
// Added.

%{

#include "config_dap.h"

static char rcsid[] __unused__ = {"$Id: Error.y,v 1.5 1997/02/14 23:56:11 jimg Exp $"};

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <iostream.h>

#include "Error.h"

#include "parser.h"
#include "debug.h"

// These macros are used to access the `arguments' passed to the parser. A
// pointer to an error object and a pointer to an integer status variable are
// passed in to the parser within a strucutre (which itself is passed as a
// pointer). Note that the ERROR macro explicitly casts OBJ to an ERROR *. 

#define ERROR_OBJ(arg) ((Error *)((parser_arg *)(arg))->_object)
#define STATUS(arg) ((parser_arg *)(arg))->_status
#if DODS_BISON_VER > 124
#define YYPARSE_PARAM arg
#else
#define YYPARSE_PARAM void *arg
#endif

extern int error_line_num;	// defined in Error.lex

int Errorlex();			// the scanner
void Errorerror(char *s);	// gotta love automatically generated names...

%}

%union {
    bool boolean;
    int integer;
    char *string;
}

%token <integer> INT
%token <string> STR

%token <integer> ERROR
%token <integer> CODE
%token <integer> PTYPE
%token <string> MSG
%token <string> PROGRAM

%type <boolean> error_object contents description program
%type <boolean> code program_type message program_code

%%

// The parser is called through a function named ERRORPARSE which takes a
// pointer to a structure and returns a boolean. The structure contains a
// pointer to an Error object which is empty and an integer which contains
// status information. In addition the parser_arg strucuture contains a
// pointer to an error object. However, the `error' member of parser_arg is
// not yet used here.

error_object:	ERROR '{' contents '}' ';' { $$ = $3; STATUS(arg) = $3; }
;

contents:	description program { $$ = $1 && $2; }
                | description { $$ = $1; }
;

description:	code message { $$ = $1 && $2; }
;

program:	program_type program_code { $$ = $1 && $2; }
;

code:		CODE '=' INT ';' 
		{ 
		    ERROR_OBJ(arg)->error_code((ErrorCode)$3);
		    $$ = true; 
		}
;

message:	MSG '=' STR 
		{ 
		    ERROR_OBJ(arg)->error_message($3);
		    $$ = true; 
		} 
{'fraction_non_alphanumeric': 0.13116109824677472, 'fraction_numerical': 0.0358914985114125, 'mean_word_length': 3.356628242074928, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6654443', 'n_tokens_mistral': 2204, 'n_tokens_neox': 2006, 'n_words': 740}