improved parser to detect variables and members
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@327 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
138f80a69f
commit
88e763b9cc
@ -117,6 +117,27 @@ void treeviews_init_tag_list(gint idx)
|
||||
gtk_tree_store_set(doc_list[idx].tag_store, &(tv.tag_namespace), 0, _("Begin"), -1);
|
||||
gtk_tree_store_append(doc_list[idx].tag_store, &(tv.tag_other), NULL);
|
||||
gtk_tree_store_set(doc_list[idx].tag_store, &(tv.tag_other), 0, _("Other"), -1);
|
||||
*/
|
||||
break;
|
||||
}
|
||||
case GEANY_FILETYPES_RUBY:
|
||||
{
|
||||
gtk_tree_store_append(doc_list[idx].tag_store, &(tv.tag_function), NULL);
|
||||
gtk_tree_store_set(doc_list[idx].tag_store, &(tv.tag_function), 0, _("Methods"), -1);
|
||||
gtk_tree_store_append(doc_list[idx].tag_store, &(tv.tag_class), NULL);
|
||||
gtk_tree_store_set(doc_list[idx].tag_store, &(tv.tag_class), 0, _("Class"), -1);
|
||||
gtk_tree_store_append(doc_list[idx].tag_store, &(tv.tag_member), NULL);
|
||||
gtk_tree_store_set(doc_list[idx].tag_store, &(tv.tag_member), 0, _("Singleton"), -1);
|
||||
gtk_tree_store_append(doc_list[idx].tag_store, &(tv.tag_macro), NULL);
|
||||
gtk_tree_store_set(doc_list[idx].tag_store, &(tv.tag_macro), 0, _("Mixin"), -1);
|
||||
gtk_tree_store_append(doc_list[idx].tag_store, &(tv.tag_variable), NULL);
|
||||
gtk_tree_store_set(doc_list[idx].tag_store, &(tv.tag_variable), 0, _("Variables"), -1);
|
||||
gtk_tree_store_append(doc_list[idx].tag_store, &(tv.tag_struct), NULL);
|
||||
gtk_tree_store_set(doc_list[idx].tag_store, &(tv.tag_struct), 0, _("Members"), -1);
|
||||
/* gtk_tree_store_append(doc_list[idx].tag_store, &(tv.tag_namespace), NULL);
|
||||
gtk_tree_store_set(doc_list[idx].tag_store, &(tv.tag_namespace), 0, _("Begin"), -1);
|
||||
gtk_tree_store_append(doc_list[idx].tag_store, &(tv.tag_other), NULL);
|
||||
gtk_tree_store_set(doc_list[idx].tag_store, &(tv.tag_other), 0, _("Other"), -1);
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
/*
|
||||
* $Id: ruby.c,v 1.2 2001/12/18 04:30:18 darren Exp $
|
||||
*
|
||||
* Copyright (c) 2000-2001, Thaddeus Covert <sahuagin@mediaone.net>
|
||||
*
|
||||
@ -7,6 +8,10 @@
|
||||
*
|
||||
* This module contains functions for generating tags for Ruby language
|
||||
* files.
|
||||
*
|
||||
* Copyright (c) 2002, Matthias Veit <matthias_veit@yahoo.de>
|
||||
* Enable parsing of class (in ruby: singleton) methods and mixins.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -24,111 +29,166 @@
|
||||
* DATA DEFINITIONS
|
||||
*/
|
||||
typedef enum {
|
||||
K_CLASS, K_FUNCTION
|
||||
K_CLASS, K_METHOD, K_SINGLETON, K_MIXIN, K_VARIABLE, K_MEMBER
|
||||
} rubyKind;
|
||||
|
||||
static kindOption RubyKinds [] = {
|
||||
{ TRUE, 'c', "class", "classes" },
|
||||
{ TRUE, 'f', "function", "functions" },
|
||||
{ TRUE, 'm', "mixin", "mixins" }
|
||||
};
|
||||
{ TRUE, 'c', "class", "classes" },
|
||||
{ TRUE, 'f', "function", "methods" },
|
||||
{ TRUE, 'm', "member", "singleton_methods" },
|
||||
{ TRUE, 'd', "macro", "mixins" },
|
||||
{ TRUE, 'v', "variable", "variable" },
|
||||
{ TRUE, 's', "struct", "member" }
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* FUNCTION DEFINITIONS
|
||||
*/
|
||||
|
||||
static void findRubyTags (void)
|
||||
{
|
||||
static void findRubyTags (void) {
|
||||
vString *name = vStringNew ();
|
||||
const unsigned char *line;
|
||||
boolean inMultilineString = FALSE;
|
||||
|
||||
while ((line = fileReadLine ()) != NULL)
|
||||
{
|
||||
const unsigned char *cp = line;
|
||||
while ((line = fileReadLine ()) != NULL) {
|
||||
const unsigned char *cp = line;
|
||||
boolean is_singleton = FALSE;
|
||||
|
||||
while (*cp != '\0')
|
||||
{
|
||||
if (*cp=='"' &&
|
||||
strncmp ((const char*) cp, "\"\"\"", (size_t) 3) == 0)
|
||||
{
|
||||
inMultilineString = (boolean) !inMultilineString;
|
||||
cp += 3;
|
||||
}
|
||||
/* make sure you include the comments */
|
||||
if(*cp=='=' && strncmp((const char*)cp, "==begin", (size_t)7) == 0)
|
||||
{
|
||||
inMultilineString = (boolean)!inMultilineString;
|
||||
cp +=3;
|
||||
}
|
||||
/* mark the end of a comment */
|
||||
if( *cp=='=' && strncmp((const char*)cp, "==end", (size_t)5) == 0)
|
||||
{
|
||||
inMultilineString = (boolean)0;
|
||||
cp+=5;
|
||||
}
|
||||
if (inMultilineString || isspace ((int) *cp))
|
||||
++cp;
|
||||
else if (*cp == '#')
|
||||
break;
|
||||
else if (strncmp ((const char*) cp, "class", (size_t) 5) == 0)
|
||||
{
|
||||
cp += 5;
|
||||
if (isspace ((int) *cp))
|
||||
{
|
||||
while (isspace ((int) *cp))
|
||||
++cp;
|
||||
while (isalnum ((int) *cp) || *cp == '_' || *cp == ':')
|
||||
{
|
||||
vStringPut (name, (int) *cp);
|
||||
++cp;
|
||||
}
|
||||
vStringTerminate (name);
|
||||
makeSimpleTag (name, RubyKinds, K_CLASS);
|
||||
vStringClear (name);
|
||||
}
|
||||
}
|
||||
else if (strncmp ((const char*) cp, "def", (size_t) 3) == 0)
|
||||
{
|
||||
cp += 3;
|
||||
if (isspace ((int) *cp))
|
||||
{
|
||||
while (isalnum ((int) *cp) || *cp == ':')
|
||||
++cp;
|
||||
while (*cp != '\0')
|
||||
{
|
||||
if (*cp=='"' &&
|
||||
strncmp ((const char*) cp, "\"\"\"", (size_t) 3) == 0) {
|
||||
inMultilineString = (boolean) !inMultilineString;
|
||||
cp += 3;
|
||||
}
|
||||
/* make sure you include the comments */
|
||||
if(*cp=='=' && strncmp((const char*)cp, "==begin", (size_t)7) == 0) {
|
||||
inMultilineString = (boolean)!inMultilineString;
|
||||
cp +=3;
|
||||
}
|
||||
/* mark the end of a comment */
|
||||
if( *cp=='=' && strncmp((const char*)cp, "==end", (size_t)5) == 0) {
|
||||
inMultilineString = (boolean)0;
|
||||
cp+=5;
|
||||
}
|
||||
if (inMultilineString || isspace ((int) *cp))
|
||||
++cp;
|
||||
else if (*cp == '#')
|
||||
break;
|
||||
else if (*cp == '=' && *(cp+1) != '=' && (isspace((int) *(cp-1)) || isalnum((int) *(cp-1)))) {
|
||||
|
||||
/* Put the valid characters allowed in a variable name
|
||||
* in here. In ruby a variable name ENDING in ! means
|
||||
* it changes the underlying data structure in place.
|
||||
* A variable name ENDING in ? means that the function
|
||||
* returns a bool. Functions should not start with these
|
||||
* characters.
|
||||
*/
|
||||
while (isalnum ((int) *cp) || *cp == '_' ||
|
||||
*cp == '!' || *cp =='?')
|
||||
{
|
||||
vStringPut (name, (int) *cp);
|
||||
++cp;
|
||||
}
|
||||
vStringTerminate (name);
|
||||
makeSimpleTag (name, RubyKinds, K_FUNCTION);
|
||||
vStringClear (name);
|
||||
}
|
||||
}
|
||||
else if (*cp != '\0')
|
||||
{
|
||||
do
|
||||
++cp;
|
||||
while (isalnum ((int) *cp) || *cp == '_');
|
||||
}
|
||||
}
|
||||
// try to detect a variable by the = sign - enrico
|
||||
// exlude all what not look like ' = ' or 'l=b'
|
||||
const unsigned char *cur_pos = cp; // store the current position because
|
||||
// we are going backwards with cp
|
||||
// (think about what happens if we don't do this ;-))
|
||||
int is_member = 0;
|
||||
cp--;
|
||||
|
||||
while (isspace ((int) *cp)) --cp;
|
||||
|
||||
while (isalnum ((int) *cp) || *cp == '_') cp--;
|
||||
|
||||
if (*cp == '@') is_member = 1; // handle @...
|
||||
else if (!isspace((int) *cp))
|
||||
{
|
||||
cp = cur_pos + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// cp points to the char before the variable name, so go forward
|
||||
cp++;
|
||||
|
||||
while (cp != cur_pos && ! isspace((int) *cp))
|
||||
{
|
||||
vStringPut (name, (int) *cp);
|
||||
cp++;
|
||||
}
|
||||
vStringTerminate (name);
|
||||
if (vStringLength (name) > 0)
|
||||
{
|
||||
if (is_member) makeSimpleTag (name, RubyKinds, K_MEMBER);
|
||||
else makeSimpleTag (name, RubyKinds, K_VARIABLE);
|
||||
}
|
||||
vStringClear (name);
|
||||
cp = cur_pos + 1;
|
||||
|
||||
}
|
||||
else if (strncmp ((const char*) cp, "module", (size_t) 6) == 0) {
|
||||
cp += 6;
|
||||
if (isspace ((int) *cp)) {
|
||||
while (isspace ((int) *cp))
|
||||
++cp;
|
||||
while (isalnum ((int) *cp) || *cp == '_' || *cp == ':') {
|
||||
vStringPut (name, (int) *cp);
|
||||
++cp;
|
||||
}
|
||||
vStringTerminate (name);
|
||||
makeSimpleTag (name, RubyKinds, K_MIXIN);
|
||||
vStringClear (name);
|
||||
}
|
||||
} else if (strncmp ((const char*) cp, "class", (size_t) 5) == 0) {
|
||||
cp += 5;
|
||||
if (isspace ((int) *cp)) {
|
||||
while (isspace ((int) *cp))
|
||||
++cp;
|
||||
while (isalnum ((int) *cp) || *cp == '_' || *cp == ':') {
|
||||
vStringPut (name, (int) *cp);
|
||||
++cp;
|
||||
}
|
||||
vStringTerminate (name);
|
||||
makeSimpleTag (name, RubyKinds, K_CLASS);
|
||||
vStringClear (name);
|
||||
}
|
||||
} else if (strncmp ((const char*) cp, "def", (size_t) 3) == 0) {
|
||||
cp += 3;
|
||||
if (isspace ((int) *cp)) {
|
||||
while (isspace ((int) *cp))
|
||||
++cp;
|
||||
|
||||
/* Put the valid characters allowed in a variable name
|
||||
* in here. In ruby a variable name ENDING in ! means
|
||||
* it changes the underlying data structure in place.
|
||||
* A variable name ENDING in ? means that the function
|
||||
* returns a bool. Functions should not start with these
|
||||
* characters.
|
||||
*/
|
||||
while (isalnum ((int) *cp) || *cp == '_' || *cp == '!' || *cp =='?' || *cp=='.') {
|
||||
/* classmethods are accesible only via class instance instead
|
||||
* of object instance. This difference has to be outlined.
|
||||
*/
|
||||
if (*cp == '.') {
|
||||
//class method
|
||||
is_singleton = TRUE;
|
||||
vStringTerminate (name);
|
||||
vStringClear(name);
|
||||
} else {
|
||||
vStringPut (name, (int) *cp);
|
||||
}
|
||||
++cp;
|
||||
}
|
||||
vStringTerminate (name);
|
||||
if (is_singleton) {
|
||||
makeSimpleTag (name, RubyKinds, K_SINGLETON);
|
||||
} else {
|
||||
makeSimpleTag (name, RubyKinds, K_METHOD);
|
||||
}
|
||||
vStringClear (name);
|
||||
}
|
||||
} else if (*cp != '\0') {
|
||||
do
|
||||
++cp;
|
||||
while (isalnum ((int) *cp) || *cp == '_');
|
||||
}
|
||||
}
|
||||
}
|
||||
vStringDelete (name);
|
||||
}
|
||||
|
||||
extern parserDefinition* RubyParser (void)
|
||||
{
|
||||
static const char *const extensions [] = { "rb", NULL };
|
||||
static const char *const extensions [] = { "rb", "rhtml", NULL };
|
||||
parserDefinition* def = parserNew ("Ruby");
|
||||
def->kinds = RubyKinds;
|
||||
def->kindCount = KIND_COUNT (RubyKinds);
|
||||
|
Loading…
x
Reference in New Issue
Block a user