-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.y
107 lines (82 loc) · 2.3 KB
/
format.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
%{
#include <string>
#include <iostream>
#include <vector>
#include "templates.h"
#include "tagreport.h"
#define WARN_SHADOW_AND_SET(e, f, g) \
if (!(e).is_default() && (e).is_set()) \
cerr << "Warning: additional definition of '" << f \
<< "' shadows previous" << endl; \
DEBUG("Reading template value in for", f); \
(e).set (g)
using namespace std;
extern int yylex(void);
extern void yyerror(const char*);
extern char *yytext;
extern unsigned int line, col;
%}
%union {
char* s;
int kt;
}
%token TYPE_TITLE TYPE_HEADER TYPE_STATS TYPE_PREBODY TYPE_FOOTER TYPE_BODY
%token TYPE_BODY_TAG TYPE_HEAD_BODY
%token <s> TYPE_VALUE
%type <kt> KeyType
%%
Template: KeyPairs
| { cerr << "Error: " << template_fn << " has no settings, continuing with defaults." << endl << "This is probably not what you want!" << endl; }
;
KeyPairs: KeyPairs KeyPair
| KeyPair
;
KeyPair: KeyType '=' TYPE_VALUE {
switch ($1)
{
case TYPE_TITLE:
WARN_SHADOW_AND_SET(template_title, "title", $3);
break;
case TYPE_HEADER:
WARN_SHADOW_AND_SET(template_header, "header", $3);
break;
case TYPE_STATS:
WARN_SHADOW_AND_SET(template_stats, "stats", $3);
break;
case TYPE_PREBODY:
WARN_SHADOW_AND_SET(template_prebody, "prebody", $3);
break;
case TYPE_BODY:
WARN_SHADOW_AND_SET(template_body, "body", $3);
break;
case TYPE_BODY_TAG:
WARN_SHADOW_AND_SET(template_body_tag, "bodytag", $3);
break;
case TYPE_HEAD_BODY:
WARN_SHADOW_AND_SET(template_head_body, "headbody", $3);
break;
case TYPE_FOOTER:
WARN_SHADOW_AND_SET(template_footer, "footer", $3);
break;
default: /* should NEVER ever ever happen */
cout << "FATAL: received unexpected " << $1 << " in switch" << endl;
abort();
}
free($3);
};
KeyType : TYPE_TITLE { $$ = TYPE_TITLE; }
| TYPE_HEAD_BODY { $$ = TYPE_HEAD_BODY; }
| TYPE_HEADER { $$ = TYPE_HEADER; }
| TYPE_STATS { $$ = TYPE_STATS; }
| TYPE_PREBODY { $$ = TYPE_PREBODY; }
| TYPE_FOOTER { $$ = TYPE_FOOTER; }
| TYPE_BODY { $$ = TYPE_BODY; }
| TYPE_BODY_TAG { $$ = TYPE_BODY_TAG; }
;
%%
void yyerror(char const* s)
{
cerr << "Couldn't parse \"" << yytext << "\" at line " << line << " column " << col << ": " << s << endl;
if (!force)
exit(1);
}