-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.l
115 lines (90 loc) · 2.14 KB
/
format.l
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
108
109
110
111
112
113
114
115
/* Lexical analyzer for .def files for TagReport. */
%option nounput
%option noyywrap
%{
#include <string>
#include <iostream>
using namespace std;
#include "config.h"
#include "y.tab.h"
#include "templates.h"
#include "tagreport.h"
unsigned int line = 1, col = 0;
unsigned int comment_begin_line, comment_begin_col;
static void ccomment(void);
#define YY_USER_ACTION col += yyleng;
%}
VALUE \".*\"
MALSTRING \"[^\"\n]*\n
WHITE [\t ]*
COMMENT ^#.*
LONGCOMMENT "/*"
%% /* BEGIN RULES SECTION */
{VALUE} {
yytext[yyleng - 1] = '\0'; /* Kill the trailing quote */
yytext++; /* Kill the leading quote */
yylval.s = strdup(yytext);
return TYPE_VALUE;
}
{MALSTRING} {
/* yytext already contains a newline, no need for one here */
cerr << "Error: unterminated string constant in " << template_fn << " at line " << line << " (started at column " << col - yyleng + 1 << "): " << yytext;
if (!force)
exit(1);
}
{WHITE} { }
{COMMENT} { }
{LONGCOMMENT} {
comment_begin_line = line;
comment_begin_col = col - 1;
ccomment();
}
"=" { return '='; }
"title" { return TYPE_TITLE; }
"headbody" { return TYPE_HEAD_BODY; }
"header" { return TYPE_HEADER; }
"stats" { return TYPE_STATS; }
"prebody" { return TYPE_PREBODY; }
"footer" { return TYPE_FOOTER; }
"body" { return TYPE_BODY; }
"bodytag" { return TYPE_BODY_TAG; }
\n { line++; col = 0; }
. {
cerr << "Error: unrecognized token \"" << yytext[0] << "\" in " << template_fn << " at line " << line << " column " << col << endl;
if (!force)
exit(1);
}
%%
/* Ripped from ircd-hybrid/src/ircd_lexer.l */
void ccomment(void)
{
int c;
while (1)
{
while ((c = yyinput()) != '*' && c != EOF)
{
if (c == '\n')
{
col = 0;
++line;
}
else
++col;
}
if (c == '*')
{
++col;
while ((c = yyinput()) == '*') ++col;
if (c == '/') { ++col; break; }
}
if (c == EOF)
{
cerr << "Error: encountered end-of-file in comment starting on line " << comment_begin_line << ", column " << comment_begin_col << endl;
if (force)
return;
else
exit(1);
break;
}
}
}