~ubuntu-branches/debian/experimental/geany/experimental

« back to all changes in this revision

Viewing changes to tagmanager/haxe.c

  • Committer: Bazaar Package Importer
  • Author(s): Damián Viano
  • Date: 2008-05-02 11:37:45 UTC
  • mfrom: (1.2.1 upstream) (3.1.6 hardy)
  • Revision ID: james.westby@ubuntu.com-20080502113745-xzp4g6dmovrpoj17
Tags: 0.14-1
New upstream release (Closes: #478126)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *       Copyright (c) 2007, Ritchie Turner
 
3
 *
 
4
 *       This source code is released for free distribution under the terms of the
 
5
 *       GNU General Public License.
 
6
 *
 
7
 *              borrowed from PHP
 
8
 */
 
9
 
 
10
/*
 
11
 *       INCLUDE FILES
 
12
 */
 
13
#include "general.h"    /* must always come first */
 
14
#include <ctype.h>      /* to define isalpha () */
 
15
#include <setjmp.h>
 
16
#ifdef DEBUG
 
17
#include <stdio.h>
 
18
#endif
 
19
#include <string.h>
 
20
#include "main.h"
 
21
#include "entry.h"
 
22
#include "keyword.h"
 
23
#include "parse.h"
 
24
#include "read.h"
 
25
#include "vstring.h"
 
26
 
 
27
/*
 
28
 *       MACROS
 
29
 */
 
30
#define isType(token,t)         (boolean) ((token)->type == (t))
 
31
#define isKeyword(token,k)      (boolean) ((token)->keyword == (k))
 
32
 
 
33
/*
 
34
 *      DATA DEFINITIONS
 
35
 */
 
36
 
 
37
/*static jmp_buf Exception;*/
 
38
 
 
39
typedef enum {
 
40
        HXTAG_METHODS,
 
41
        HXTAG_CLASS,
 
42
        HXTAG_ENUM,
 
43
        HXTAG_VARIABLE,
 
44
        HXTAG_INTERFACE,
 
45
        HXTAG_TYPEDEF,
 
46
        HXTAG_COUNT
 
47
} hxKind;
 
48
 
 
49
static kindOption HxKinds [] = {
 
50
        { TRUE,  'm', "method",         "methods" },
 
51
        { TRUE,  'c', "class",          "classes" },
 
52
        { TRUE,  'e', "enum",           "enumerations" },
 
53
        { TRUE,  'v', "variable",       "variables" },
 
54
        { TRUE,  'i', "interface",      "interfaces" },
 
55
        { TRUE,  't', "typedef",        "typedefs" },
 
56
};
 
57
 
 
58
static void findHxTags (void)
 
59
{
 
60
    vString *name = vStringNew ();
 
61
    vString *clsName = vStringNew();
 
62
    vString *scope2 = vStringNew();
 
63
    vString *laccess = vStringNew();
 
64
    const char *const priv = "private";
 
65
    const char *const pub = "public";
 
66
 
 
67
    const unsigned char *line;
 
68
 
 
69
    while ((line = fileReadLine ()) != NULL)
 
70
    {
 
71
        const unsigned char *cp = line;
 
72
another:
 
73
        while (isspace (*cp))
 
74
            cp++;
 
75
 
 
76
        vStringCopyS(laccess,priv);
 
77
 
 
78
        if (strncmp ((const char*) cp, "var", (size_t) 3) == 0  &&
 
79
            isspace ((int) cp [3]))
 
80
        {
 
81
            cp += 3;
 
82
 
 
83
            while (isspace ((int) *cp))
 
84
                ++cp;
 
85
 
 
86
            vStringClear (name);
 
87
            while (isalnum ((int) *cp)  ||  *cp == '_')
 
88
            {
 
89
                vStringPut (name, (int) *cp);
 
90
                ++cp;
 
91
            }
 
92
            vStringTerminate (name);
 
93
            makeSimpleTag (name, HxKinds, HXTAG_VARIABLE);
 
94
            /*
 
95
             makeSimpleScopedTag(name, HxKinds,
 
96
                        HXTAG_VARIABLE,vStringValue(clsName),
 
97
                        strdup(vStringValue(scope2)),strdup(vStringValue(laccess)));
 
98
             */
 
99
 
 
100
            vStringClear (name);
 
101
        }
 
102
        else if (strncmp ((const char*) cp, "function", (size_t) 8) == 0  &&
 
103
            isspace ((int) cp [8]))
 
104
        {
 
105
            cp += 8;
 
106
 
 
107
            while (isspace ((int) *cp))
 
108
                ++cp;
 
109
 
 
110
            vStringClear (name);
 
111
            while (isalnum ((int) *cp)  ||  *cp == '_')
 
112
            {
 
113
                vStringPut (name, (int) *cp);
 
114
                ++cp;
 
115
            }
 
116
            vStringTerminate (name);
 
117
            makeSimpleTag (name, HxKinds, HXTAG_METHODS);
 
118
            /*
 
119
            makeSimpleScopedTag(name, HxKinds, HXTAG_METHODS,
 
120
                strdup(vStringValue(clsName)),strdup(vStringValue(scope2)),strdup(vStringValue(laccess)));
 
121
 
 
122
            */
 
123
 
 
124
            vStringClear (name);
 
125
        }
 
126
        else if (strncmp ((const char*) cp, "class", (size_t) 5) == 0 &&
 
127
                 isspace ((int) cp [5]))
 
128
        {
 
129
            cp += 5;
 
130
 
 
131
            while (isspace ((int) *cp))
 
132
                ++cp;
 
133
            vStringClear (name);
 
134
            while (isalnum ((int) *cp)  ||  *cp == '_')
 
135
            {
 
136
                vStringPut (name, (int) *cp);
 
137
                ++cp;
 
138
            }
 
139
            vStringTerminate (name);
 
140
            makeSimpleTag (name, HxKinds, HXTAG_CLASS);
 
141
            vStringCopy(clsName,name);
 
142
            vStringClear (name);
 
143
        }
 
144
        else if (strncmp ((const char*) cp, "enum", (size_t) 4) == 0 &&
 
145
                  isspace ((int) cp [4]))
 
146
        {
 
147
            cp += 4;
 
148
 
 
149
           while (isspace ((int) *cp))
 
150
                ++cp;
 
151
            vStringClear (name);
 
152
            while (isalnum ((int) *cp)  ||  *cp == '_')
 
153
            {
 
154
                vStringPut (name, (int) *cp);
 
155
                ++cp;
 
156
            }
 
157
            vStringTerminate (name);
 
158
            makeSimpleTag (name, HxKinds, HXTAG_ENUM);
 
159
            vStringClear (name);
 
160
        } else if (strncmp ((const char*) cp, "public", (size_t) 6) == 0 &&
 
161
                 isspace((int) cp [6]))
 
162
        {
 
163
                  cp += 6;
 
164
                while (isspace ((int) *cp))
 
165
                                ++cp;
 
166
                        vStringCopyS(laccess,pub);
 
167
                 goto another;
 
168
         } else if (strncmp ((const char*) cp, "static", (size_t) 6) == 0 &&
 
169
                 isspace((int) cp [6]))
 
170
         {
 
171
                  cp += 6;
 
172
                while (isspace ((int) *cp))
 
173
                                ++cp;
 
174
                 goto another;
 
175
         } else if (strncmp ((const char*) cp, "interface", (size_t) 9) == 0 &&
 
176
                 isspace((int) cp [9]))
 
177
         {
 
178
                  cp += 9;
 
179
 
 
180
            while (isspace ((int) *cp))
 
181
                        ++cp;
 
182
            vStringClear (name);
 
183
            while (isalnum ((int) *cp)  ||  *cp == '_') {
 
184
                        vStringPut (name, (int) *cp);
 
185
                        ++cp;
 
186
            }
 
187
            vStringTerminate (name);
 
188
            makeSimpleTag (name, HxKinds, HXTAG_INTERFACE);
 
189
            vStringClear (name);
 
190
        } else if (strncmp ((const char *) cp,"typedef",(size_t) 7) == 0 && isspace(((int) cp[7]))) {
 
191
                cp += 7;
 
192
 
 
193
            while (isspace ((int) *cp))
 
194
                        ++cp;
 
195
            vStringClear (name);
 
196
            while (isalnum ((int) *cp)  ||  *cp == '_') {
 
197
                        vStringPut (name, (int) *cp);
 
198
                        ++cp;
 
199
            }
 
200
            vStringTerminate (name);
 
201
            makeSimpleTag (name, HxKinds, HXTAG_TYPEDEF);
 
202
            vStringClear (name);
 
203
        }
 
204
 
 
205
 
 
206
    }
 
207
 
 
208
    vStringDelete(name);
 
209
    vStringDelete(clsName);
 
210
    vStringDelete(scope2);
 
211
    vStringDelete(laccess);
 
212
}
 
213
 
 
214
 
 
215
/* Create parser definition stucture */
 
216
extern parserDefinition* HaxeParser (void)
 
217
{
 
218
        static const char *const extensions [] = { "hx", NULL };
 
219
 
 
220
        parserDefinition *const def = parserNew ("Haxe");
 
221
        def->extensions = extensions;
 
222
        /*
 
223
         * New definitions for parsing instead of regex
 
224
         */
 
225
        def->kinds              = HxKinds;
 
226
        def->kindCount  = KIND_COUNT (HxKinds);
 
227
        def->parser             = findHxTags;
 
228
        /*def->initialize = initialize;*/
 
229
        return def;
 
230
}
 
231
 
 
232
 
 
233