Enforced use of PROJECT macro

Added "indent" directive to grammar
Added "replace" directive to grammar
This commit is contained in:
Thomas Jensen 1999-04-04 16:07:53 +00:00
parent 413528bdf0
commit f239524594

View File

@ -4,7 +4,7 @@
* Date created: March 16, 1999 (Tuesday, 17:17h) * Date created: March 16, 1999 (Tuesday, 17:17h)
* Author: Thomas Jensen * Author: Thomas Jensen
* tsjensen@stud.informatik.uni-erlangen.de * tsjensen@stud.informatik.uni-erlangen.de
* Version: $Id: parser.y,v 1.4 1999/03/30 09:37:51 tsjensen Exp tsjensen $ * Version: $Id: parser.y,v 1.5 1999/03/30 13:29:50 tsjensen Exp tsjensen $
* Language: yacc (ANSI C) * Language: yacc (ANSI C)
* Purpose: Yacc parser for boxes configuration files * Purpose: Yacc parser for boxes configuration files
* Remarks: --- * Remarks: ---
@ -12,6 +12,9 @@
* Revision History: * Revision History:
* *
* $Log: parser.y,v $ * $Log: parser.y,v $
* Revision 1.5 1999/03/30 13:29:50 tsjensen
* Added computation of minimum width/height of each design.
*
* Revision 1.4 1999/03/30 09:37:51 tsjensen * Revision 1.4 1999/03/30 09:37:51 tsjensen
* It drew a correct box for the first time! * It drew a correct box for the first time!
* *
@ -35,7 +38,7 @@
#include <string.h> #include <string.h>
#include "boxes.h" #include "boxes.h"
#ident "$Id: parser.y,v 1.4 1999/03/30 09:37:51 tsjensen Exp tsjensen $"; #ident "$Id: parser.y,v 1.5 1999/03/30 13:29:50 tsjensen Exp tsjensen $";
static int pflicht = 0; static int pflicht = 0;
@ -258,12 +261,13 @@ int perform_se_check()
%union { %union {
int num; int num;
char *s; char *s;
char c;
shape_t shape; shape_t shape;
soffset_t offset; soffset_t offset;
sentry_t sentry; sentry_t sentry;
} }
%token YSHAPES YOFFSETS YELASTIC YSAMPLE %token YSHAPES YOFFSETS YELASTIC YSAMPLE YREPLACE
%token <s> KEYWORD %token <s> KEYWORD
%token <s> WORD %token <s> WORD
%token <s> STRING %token <s> STRING
@ -273,6 +277,7 @@ int perform_se_check()
%type <sentry> slist %type <sentry> slist
%type <sentry> slist_entries %type <sentry> slist_entries
%type <c> rflag;
%% %%
@ -312,9 +317,10 @@ design: KEYWORD WORD layout KEYWORD WORD
if (tmp) { if (tmp) {
designs = tmp; designs = tmp;
memset (&(designs[design_idx]), 0, sizeof(design_t)); memset (&(designs[design_idx]), 0, sizeof(design_t));
designs[design_idx].indentmode = DEF_INDENTMODE;
} }
else { else {
perror ("boxes"); perror (PROJECT);
YYABORT; YYABORT;
} }
} }
@ -339,15 +345,28 @@ entry: KEYWORD STRING
else if (strcasecmp ($1, "revdate") == 0) { else if (strcasecmp ($1, "revdate") == 0) {
designs[design_idx].revdate = (char *) strdup ($2); designs[design_idx].revdate = (char *) strdup ($2);
} }
else if (strcasecmp ($1, "indent") == 0) {
if (strcasecmp ($2, "text") == 0 ||
strcasecmp ($2, "box") == 0 ||
strcasecmp ($2, "none") == 0) {
designs[design_idx].indentmode = $2[0];
}
else {
yyerror ("%s: indent keyword must be followed by \"text\", "
"\"box\", or \"none\"\n", PROJECT);
YYABORT;
}
}
else { else {
fprintf (stderr, "boxes: Internal parser error (unrecognized: %s)" fprintf (stderr, "%s: Internal parser error (unrecognized: %s)"
" in line %d of %s.\n", $1, __LINE__, __FILE__); " in line %d of %s.\n", PROJECT, $1, __LINE__, __FILE__);
YYABORT; YYABORT;
} }
} }
| WORD STRING | WORD STRING
{ {
fprintf (stderr, "boxes: Discarding entry [%s = %s].\n", $1, $2); fprintf (stderr, "%s: Discarding entry [%s = %s].\n", PROJECT, $1, $2);
} }
; ;
@ -383,7 +402,8 @@ block: YSAMPLE '{' STRING '}'
&& isempty (designs[design_idx].shape + W) && isempty (designs[design_idx].shape + W)
&& isempty (designs[design_idx].shape + WSW))) && isempty (designs[design_idx].shape + WSW)))
{ {
yyerror ("Must specify at least one shape per side"); yyerror ("Must specify at least one shape per side "
"(corners don\'t count as sides)");
YYABORT; YYABORT;
} }
@ -433,10 +453,65 @@ block: YSAMPLE '{' STRING '}'
} }
} }
| YREPLACE rflag STRING WORD STRING
{
int a = designs[design_idx].anz_reprules;
if (strcasecmp ($4, "with") != 0) {
yyerror ("Search pattern and replacement string must be separated"
" by \"with\"");
YYABORT;
}
#ifdef DEBUG
fprintf (stderr, "Adding replacement rule: \"%s\" with \"%s\"\n",
$3, $5);
#endif
designs[design_idx].reprules = (reprule_t *) realloc
(designs[design_idx].reprules, (a+1) * sizeof(reprule_t));
if (designs[design_idx].reprules == NULL) {
perror (PROJECT);
YYABORT;
}
memset (&(designs[design_idx].reprules[a]), 0, sizeof(reprule_t));
designs[design_idx].reprules[a].search =
(char *) strdup ($3);
designs[design_idx].reprules[a].repstr =
(char *) strdup ($5);
if (designs[design_idx].reprules[a].search == NULL
|| designs[design_idx].reprules[a].repstr == NULL)
{
perror (PROJECT);
YYABORT;
}
designs[design_idx].reprules[a].line = yylineno;
designs[design_idx].reprules[a].mode = $2;
designs[design_idx].anz_reprules = a + 1;
}
| YOFFSETS '{' the_offsets '}' | YOFFSETS '{' the_offsets '}'
; ;
rflag: WORD
{
if (strcasecmp ($1, "global") == 0)
$$ = 'g';
else if (strcasecmp ($1, "once") == 0)
$$ = 'o';
else {
yyerror ("Replace may be modified by \"global\" or \"once\"");
YYABORT;
}
}
|
{
$$ = 'g';
}
;
the_shapes: the_shapes SHAPE slist the_shapes: the_shapes SHAPE slist
{ {
#ifdef DEBUG #ifdef DEBUG
@ -563,13 +638,13 @@ slist_entries: slist_entries ',' STRING
rval.height++; rval.height++;
tmp = (char **) realloc (rval.chars, rval.height*sizeof(char*)); tmp = (char **) realloc (rval.chars, rval.height*sizeof(char*));
if (tmp == NULL) { if (tmp == NULL) {
perror ("boxes: slist_entries11"); perror (PROJECT": slist_entries11");
YYABORT; YYABORT;
} }
rval.chars = tmp; rval.chars = tmp;
rval.chars[rval.height-1] = (char *) strdup ($3); rval.chars[rval.height-1] = (char *) strdup ($3);
if (rval.chars[rval.height-1] == NULL) { if (rval.chars[rval.height-1] == NULL) {
perror ("boxes: slist_entries12"); perror (PROJECT": slist_entries12");
YYABORT; YYABORT;
} }
$$ = rval; $$ = rval;
@ -587,12 +662,12 @@ slist_entries: slist_entries ',' STRING
rval.height = 1; rval.height = 1;
rval.chars = (char **) malloc (sizeof(char*)); rval.chars = (char **) malloc (sizeof(char*));
if (rval.chars == NULL) { if (rval.chars == NULL) {
perror ("boxes: slist_entries21"); perror (PROJECT": slist_entries21");
YYABORT; YYABORT;
} }
rval.chars[0] = (char *) strdup ($1); rval.chars[0] = (char *) strdup ($1);
if (rval.chars[0] == NULL) { if (rval.chars[0] == NULL) {
perror ("boxes: slist_entries22"); perror (PROJECT": slist_entries22");
YYABORT; YYABORT;
} }
$$ = rval; $$ = rval;