2
* $Id: beta.c,v 1.6 2003/02/23 17:37:48 darren Exp $
4
* Copyright (c) 1999-2000, Mj�lner Informatics
6
* Written by Erik Corry <corry@mjolner.dk>
8
* This source code is released for free distribution under the terms of the
9
* GNU General Public License.
11
* This module contains functions for generating tags for BETA language
18
#include "general.h" /* must always come first */
31
#define isbident(c) (identarray [(unsigned char) (c)])
37
K_FRAGMENT, K_PATTERN, K_SLOT, K_VIRTUAL
40
static kindOption BetaKinds [] = {
41
{ TRUE, 'f', "fragment", "fragment definitions"},
42
{ FALSE, 'p', "pattern", "all patterns"},
43
{ TRUE, 's', "slot", "slots (fragment uses)"},
44
{ TRUE, 'v', "virtual", "patterns (virtual or rebound)"}
48
static const char identarray [256] = {
49
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0-15 */
50
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16-31 */
51
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 32-47 !"#$%&'()*+'-./ */
52
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 48-63 0123456789:;<=>? */
53
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 64-79 @ABCDEFGHIJKLMNO */
54
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 80-95 PQRSTUVWXYZ [\]^_ */
55
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 96-111 `abcdefghijklmno */
56
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 112-127 pqrstuvwxyz{|}~ */
57
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 128- */
58
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
60
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; /* -255 */
67
* FUNCTION DEFINITIONS
70
static void makeBetaTag (const char* const name, const betaKind kind)
72
if (BetaKinds [kind].enabled)
75
initTagEntry (&e, name);
77
e.kindName = BetaKinds [kind].name;
78
e.kind = BetaKinds [kind].letter;
84
static void findBetaTags (void)
86
vString *line = vStringNew ();
87
boolean incomment = FALSE;
88
boolean inquote = FALSE;
89
boolean dovirtuals = BetaKinds [K_VIRTUAL].enabled;
90
boolean dopatterns = BetaKinds [K_PATTERN].enabled;
94
boolean foundfragmenthere = FALSE;
95
/* find fragment definition (line that starts and ends with --) */
102
while ((c = fileGetc ()) != EOF && c != '\n' && c != '\r')
103
vStringPut (line, c);
105
vStringTerminate (line);
107
last = vStringLength (line) - 1;
109
/* skip white space at start and end of line */
110
while (last && isspace ((int) vStringChar (line, last))) last--;
111
while (first < last && isspace ((int) vStringChar (line, first))) first++;
112
/* if line still has a reasonable length and ... */
113
if (last - first > 4 &&
114
(vStringChar (line, first) == '-' &&
115
vStringChar (line, first + 1) == '-' &&
116
vStringChar (line, last) == '-' &&
117
vStringChar (line, last - 1) == '-'))
119
if (!incomment && !inquote)
121
foundfragmenthere = TRUE;
122
/* skip past -- and whitespace. Also skip back past 'dopart'
123
or 'attributes' to the :. We have to do this because there
124
is no sensible way to include whitespace in a ctags token
125
so the conventional space after the ':' would mess us up */
128
while (last && vStringChar (line, last) != ':') last--;
129
while (last && (isspace ((int) vStringChar (line, last-1)))) last--;
130
while (first < last &&
131
(isspace ((int) vStringChar (line, first)) ||
132
vStringChar (line, first) == '-'))
134
/* If there's anything left it is a fragment title */
135
if (first < last - 1)
137
vStringChar (line, last) = 0;
138
if (strcasecmp ("LIB", vStringValue (line) + first) &&
139
strcasecmp ("PROGRAM", vStringValue (line) + first))
141
makeBetaTag (vStringValue (line) + first, K_FRAGMENT);
147
int len = vStringLength (line);
148
if (inquote) goto stringtext;
149
if (incomment) goto commenttext;
151
for ( ; pos < len; pos++)
153
if (vStringChar (line, pos) == '\'')
159
if (vStringChar (line, pos) == '{')
165
if (vStringChar (line, pos) == '(' && pos < len - 1 &&
166
vStringChar (line, pos+1) == '*')
173
* SLOT definition looks like this:
174
* <<SLOT nameofslot: dopart>>
176
* <<SLOT nameofslot: descriptor>>
178
if (!foundfragmenthere &&
179
vStringChar (line, pos) == '<' &&
181
vStringChar (line, pos+1) == '<' &&
182
strstr (vStringValue (line) + pos, ">>"))
184
/* Found slot name, get start and end */
187
pos += 2; /* skip past << */
188
/* skip past space before SLOT */
189
while (pos < len && isspace ((int) vStringChar (line, pos)))
193
!strncasecmp (vStringValue(line) + pos, "SLOT", (size_t)4))
195
/* skip past space after SLOT */
197
isspace ((int) vStringChar (line, pos)))
200
/* skip to end of name */
201
while (eoname < len &&
202
(c2 = vStringChar (line, eoname)) != '>' &&
208
vStringChar (line, eoname) = 0;
209
if (strcasecmp ("LIB", vStringValue (line) + pos) &&
210
strcasecmp ("PROGRAM", vStringValue (line) + pos) &&
211
strcasecmp ("SLOT", vStringValue (line) + pos))
213
makeBetaTag (vStringValue (line) + pos, K_SLOT);
216
if (eoname+1 < len) {
223
/* Only patterns that are virtual, extensions of virtuals or
224
* final bindings are normally included so as not to overload
226
* That means one of the forms name:: name:< or name::<
228
if (!foundfragmenthere &&
229
vStringChar (line, pos) == ':' &&
232
(vStringChar (line, pos+1) == ':' ||
233
vStringChar (line, pos+1) == '<')
238
/* Found pattern name, get start and end */
241
while (eoname && isspace ((int) vStringChar (line, eoname-1)))
244
/* terminate right after name */
245
vStringChar (line, eoname) = 0;
248
isbident (vStringChar (line, soname-1)))
252
if (soname != eoname)
254
makeBetaTag (vStringValue (line) + soname, K_PATTERN);
255
/* scan back past white space */
257
isspace ((int) vStringChar (line, soname-1)))
259
if (soname && vStringChar (line, soname-1) == ',')
261
/* we found a new pattern name before comma */
263
goto foundanothername;
270
for ( ; pos < len; pos++)
272
if (vStringChar (line, pos) == '*' && pos < len - 1 &&
273
vStringChar (line, pos+1) == ')')
279
if (vStringChar (line, pos) == '}')
288
for ( ; pos < len; pos++)
290
if (vStringChar (line, pos) == '\\')
292
if (pos < len - 1) pos++;
294
else if (vStringChar (line, pos) == '\'')
297
/* support obsolete '' syntax */
298
if (pos < len && vStringChar (line, pos) == '\'')
308
inquote = FALSE; /* This shouldn't really make a difference */
309
} while (!feof (File.fp));
312
extern parserDefinition* BetaParser (void)
314
static const char *const extensions [] = { "bet", NULL };
315
parserDefinition* def = parserNew ("BETA");
316
def->kinds = BetaKinds;
317
def->kindCount = KIND_COUNT (BetaKinds);
318
def->extensions = extensions;
319
def->parser = findBetaTags;
323
/* vi:set tabstop=8 shiftwidth=4: */