-
Notifications
You must be signed in to change notification settings - Fork 1
/
external_l.l
145 lines (123 loc) · 3.48 KB
/
external_l.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
%{
/*
* external_l.l -- lexer for external interface
*
* by Jørn Thyssen <[email protected]>, 2003.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 3 or later of the GNU General Public License as
* published by the Free Software Foundation.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: external_l.l,v 1.17 2012/05/18 20:15:00 mdpetch Exp $
*/
#include "config.h"
#include <string.h>
#include "external_y.h"
extern int extparse(void);
int prc_lineno = 1;
void escapes(const char *cp, char *tp);
%}
%option noyywrap
%option prefix="ext"
%option nounput
%option 7bit
%option case-insensitive
%option outfile="lex.yy.c"
%option noinput
NUMSTR -?[0-9]+
%%
(\"[^\"]*\")|(\'[^\']*\') {
char *buf = malloc( strlen( exttext ) + 1 );
exttext[strlen(exttext)-1] = '\0';
escapes(exttext+1, buf);
extlval.sval = buf;
BEGIN(INITIAL);
return STRING;
}
jacobyrule { return JACOBYRULE; }
crawfordrule { return CRAWFORDRULE; }
evaluation { return EVALUATION; }
fibsboard { return FIBSBOARD; }
cubeful { return CUBEFUL; }
cubeless { return CUBELESS; }
cube { return CUBE; }
plies { return PLIES; }
noise { return NOISE; }
reduced { return REDUCED; }
prune { return PRUNE; }
yes { return ON; }
on { return ON; }
no { return OFF; }
off { return OFF; }
board:[[:alnum:]_]+:[[:alnum:]_]+(:{NUMSTR})+ {
char *buf = malloc( strlen( exttext ) + 1 );
escapes(exttext, buf);
extlval.sval = buf;
return AFIBSBOARD;
}
(#.*)?\\?\n { prc_lineno++; } /* newline is ignored */
{NUMSTR} { extlval.number = atoi(exttext); return NUMBER; }
[^=;:, \t\r\n]+ {
char *buf = malloc( strlen( exttext ) + 1 );
escapes(exttext, buf);
extlval.sval = buf;
return STRING;
}
[ \t\r]+ ; /* whitespace */
%%
void escapes(const char *cp, char *tp)
{
while (*cp)
{
int cval = 0;
if (*cp == '\\' && strchr("0123456789xX", cp[1]))
{
char *dp;
const char *hex = "00112233445566778899aAbBcCdDeEfF";
int dcount = 0;
if (*++cp == 'x' || *cp == 'X')
for (++cp; (dp = strchr(hex, *cp)) && (dcount++ < 2); cp++)
cval = (cval * 16) + (dp - hex) / 2;
else if (*cp == '0')
while (strchr("01234567",*cp) != (char*)NULL && (dcount++ < 3))
cval = (cval * 8) + (*cp++ - '0');
else
while ((strchr("0123456789",*cp)!=(char*)NULL)&&(dcount++ < 3))
cval = (cval * 10) + (*cp++ - '0');
}
else if (*cp == '\\') /* C-style character escapes */
{
switch (*++cp)
{
case '\\': cval = '\\'; break;
case 'n': cval = '\n'; break;
case 't': cval = '\t'; break;
case 'b': cval = '\b'; break;
case 'r': cval = '\r'; break;
default: cval = *cp;
}
cp++;
}
else
cval = *cp++;
*tp++ = cval;
}
*tp = '\0';
}
extern void ExtStartParse(const char* szCommand);
void ExtStartParse(const char* szCommand)
{
YY_BUFFER_STATE buf_state;
buf_state = ext_scan_string(szCommand);
extparse();
ext_delete_buffer(buf_state);
}