forked from universal-ctags/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfalcon.c
147 lines (127 loc) · 3.28 KB
/
falcon.c
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
146
147
/*
* Copyright (c) 2011, 2012 Steven Oliver <[email protected]>
*
* This source code is released for free distribution under the terms of the
* GNU General Public License version 2 or (at your option) any later version.
*
* This module contains functions for generating tags for Falcon language
* files.
*/
/*
* INCLUDE FILES
*/
#include "general.h"
#include <string.h>
#include <ctype.h>
#include "read.h"
#include "kind.h"
#include "parse.h"
#include "routines.h"
/*
* Data Definitions
*/
typedef enum eFalconKinds {
K_CLASS,
K_FUNCTION,
K_MEMBER,
K_VARIABLE,
K_NAMESPACE
} falconKind;
static kindDefinition FalconKinds [] = {
{true, 'c', "class", "classes" },
{true, 'f', "function", "functions"},
{true, 'm', "member", "class members"},
{true, 'v', "variable", "variables"},
{true, 'i', "namespace", "imports"}
};
/*
* Function Definitions
*/
static bool isIdentifierChar (int c)
{
return (bool) (isalnum (c));
}
static const unsigned char *skipSpace (const unsigned char *cp)
{
while (isspace (*cp))
++cp;
return cp;
}
/*
* Main parsing function
*/
static void findFalconTags (void)
{
vString *name = vStringNew ();
const unsigned char *line;
while ((line = readLineFromInputFile ()) != NULL)
{
const unsigned char *cp = line;
// Skip lines starting with # which in falcon
// would only be the "crunch bang" statement
if (*cp == '#')
continue;
if (strncmp ((const char*) cp, "function", (size_t) 8) == 0)
{
cp += 8;
cp = skipSpace (cp);
while (isIdentifierChar (*cp))
{
vStringPut (name, *cp);
++cp;
}
makeSimpleTag (name, K_FUNCTION);
vStringClear (name);
}
else if (strncmp ((const char*) cp, "class", (size_t) 5) == 0)
{
cp += 5;
cp = skipSpace (cp);
while (isIdentifierChar (*cp))
{
vStringPut (name, *cp);
++cp;
}
makeSimpleTag (name, K_CLASS);
vStringClear (name);
}
else if (strncmp ((const char*) cp, "load", (size_t) 4) == 0)
{
cp += 4;
cp = skipSpace (cp);
while (isIdentifierChar (*cp))
{
vStringPut (name, *cp);
++cp;
}
makeSimpleTag (name, K_NAMESPACE);
vStringClear (name);
}
else if (strncmp ((const char*) cp, "import from", (size_t) 11) == 0)
{
cp += 12;
cp = skipSpace (cp);
while (isIdentifierChar (*cp))
{
vStringPut (name, *cp);
++cp;
}
makeSimpleTag (name, K_NAMESPACE);
vStringClear (name);
}
}
vStringDelete (name);
}
/*
* Parser definition structure
*/
extern parserDefinition* FalconParser (void)
{
static const char *const extensions [] = { "fal", "ftd", NULL };
parserDefinition *def = parserNew ("Falcon");
def->kindTable = FalconKinds;
def->kindCount = ARRAY_SIZE (FalconKinds);
def->extensions = extensions;
def->parser = findFalconTags;
return def;
}