4 * Copyright (c) 2000, Jesus Castagnetto <jmcastagnetto@zkey.com>
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * This module contains functions for generating tags for the PHP web page
10 * scripting language. Only recognizes functions and classes, not methods or
13 * Parsing PHP defines by Pavel Hlousek <pavel.hlousek@seznam.cz>, Apr 2003.
19 #include "general.h" /* must always come first */
31 K_CLASS
, K_DEFINE
, K_FUNCTION
, K_VARIABLE
34 static kindOption PhpKinds
[] = {
35 { TRUE
, 'c', "class", "classes" },
36 { TRUE
, 'd', "define", "constant definitions" },
37 { TRUE
, 'f', "function", "functions" },
38 { TRUE
, 'v', "variable", "variables" }
42 * FUNCTION DEFINITIONS
45 static boolean
isLetter(const int c
)
47 return (boolean
)(isalpha(c
) || (c
>= 127 && c
<= 255));
50 static boolean
isVarChar1(const int c
)
52 return (boolean
)(isLetter (c
) || c
== '_');
55 static boolean
isVarChar(const int c
)
57 return (boolean
)(isVarChar1 (c
) || isdigit (c
));
60 static void findPhpTags (void)
62 vString
*name
= vStringNew ();
63 const unsigned char *line
;
65 while ((line
= fileReadLine ()) != NULL
)
67 const unsigned char *cp
= line
;
72 if (*(const char*)cp
== '$' && isVarChar1 (*(const char*)(cp
+1)))
76 while (isVarChar ((int) *cp
))
78 vStringPut (name
, (int) *cp
);
81 while (isspace ((int) *cp
))
83 if (*(const char*) cp
== '=')
85 vStringTerminate (name
);
86 makeSimpleTag (name
, PhpKinds
, K_VARIABLE
);
90 else if (strncmp ((const char*) cp
, "function", (size_t) 8) == 0 &&
91 isspace ((int) cp
[8]))
95 while (isspace ((int) *cp
))
98 if (*cp
== '&') /* skip reference character */
102 while (isalnum ((int) *cp
) || *cp
== '_')
104 vStringPut (name
, (int) *cp
);
107 vStringTerminate (name
);
108 makeSimpleTag (name
, PhpKinds
, K_FUNCTION
);
111 else if (strncmp ((const char*) cp
, "class", (size_t) 5) == 0 &&
112 isspace ((int) cp
[5]))
116 while (isspace ((int) *cp
))
119 while (isalnum ((int) *cp
) || *cp
== '_')
121 vStringPut (name
, (int) *cp
);
124 vStringTerminate (name
);
125 makeSimpleTag (name
, PhpKinds
, K_CLASS
);
128 else if (strncmp ((const char*) cp
, "define", (size_t) 6) == 0 &&
129 ! isalnum ((int) cp
[6]))
133 while (isspace ((int) *cp
))
139 while (isspace ((int) *cp
))
141 if ((*cp
== '\'') || (*cp
== '"'))
143 else if (! ((*cp
== '_') || isalnum ((int) *cp
)))
147 while (isalnum ((int) *cp
) || *cp
== '_')
149 vStringPut (name
, (int) *cp
);
152 vStringTerminate (name
);
153 makeSimpleTag (name
, PhpKinds
, K_DEFINE
);
157 vStringDelete (name
);
160 extern parserDefinition
* PhpParser (void)
162 static const char *const extensions
[] = { "php", "php3", "phtml", NULL
};
163 parserDefinition
* def
= parserNew ("PHP");
164 def
->kinds
= PhpKinds
;
165 def
->kindCount
= KIND_COUNT (PhpKinds
);
166 def
->extensions
= extensions
;
167 def
->parser
= findPhpTags
;
171 /* vi:set tabstop=4 shiftwidth=4: */