Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Thu, 15 May 2014 14:58:04 UTC Commit: f6068d0e86331e65422bd6542b010f2d2ca08203 https://github.com/geany/geany/commit/f6068d0e86331e65422bd6542b010f2d2ca082...
Log Message: ----------- Add a Zephir tag parser
This Zephir parser uses the PHP parser with minor tweaking not to require the initial PHP open tag and skip function return type hints.
Modified Paths: -------------- tagmanager/ctags/parsers.h tagmanager/ctags/php.c tagmanager/src/tm_parser.h
Modified: tagmanager/ctags/parsers.h 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -61,7 +61,8 @@ ObjcParser, \ AsciidocParser, \ AbaqusParser, \ - RustParser + RustParser, \ + ZephirParser
#endif /* _PARSERS_H */
Modified: tagmanager/ctags/php.c 57 lines changed, 49 insertions(+), 8 deletions(-) =================================================================== @@ -227,6 +227,7 @@ typedef struct { } tokenInfo;
static langType Lang_php; +static langType Lang_zephir;
static boolean InPhp = FALSE; /* whether we are between <? ?> */
@@ -240,14 +241,14 @@ static struct { static vString *CurrentNamesapce;
-static void buildPhpKeywordHash (void) +static void buildPhpKeywordHash (const langType language) { const size_t count = sizeof (PhpKeywordTable) / sizeof (PhpKeywordTable[0]); size_t i; for (i = 0; i < count ; i++) { const keywordDesc* const p = &PhpKeywordTable[i]; - addKeyword (p->name, Lang_php, (int) p->id); + addKeyword (p->name, language, (int) p->id); } }
@@ -974,7 +975,7 @@ static void readToken (tokenInfo *const token) else { parseIdentifier (token->string, c); - token->keyword = analyzeToken (token->string, Lang_php); + token->keyword = analyzeToken (token->string, getSourceLanguage ()); if (token->keyword == KEYWORD_NONE) token->type = TOKEN_IDENTIFIER; else @@ -1180,6 +1181,17 @@ static boolean parseFunction (tokenInfo *const token, const tokenInfo *name) readToken (token); /* normally it's an open brace or "use" keyword */ }
+ /* if parsing Zephir, skip function return type hint */ + if (getSourceLanguage () == Lang_zephir && token->type == TOKEN_OPERATOR) + { + do + readToken (token); + while (token->type != TOKEN_EOF && + token->type != TOKEN_OPEN_CURLY && + token->type != TOKEN_CLOSE_CURLY && + token->type != TOKEN_SEMICOLON); + } + /* skip use(...) */ if (token->type == TOKEN_KEYWORD && token->keyword == KEYWORD_use) { @@ -1435,11 +1447,10 @@ static void enterScope (tokenInfo *const parentToken, deleteToken (token); }
-static void findPhpTags (void) +static void findTags (void) { tokenInfo *const token = newToken ();
- InPhp = FALSE; CurrentStatement.access = ACCESS_UNDEFINED; CurrentStatement.impl = IMPL_UNDEFINED; CurrentNamesapce = vStringNew (); @@ -1454,10 +1465,28 @@ static void findPhpTags (void) deleteToken (token); }
-static void initialize (const langType language) +static void findPhpTags (void) +{ + InPhp = FALSE; + findTags (); +} + +static void findZephirTags (void) +{ + InPhp = TRUE; + findTags (); +} + +static void initializePhpParser (const langType language) { Lang_php = language; - buildPhpKeywordHash (); + buildPhpKeywordHash (language); +} + +static void initializeZephirParser (const langType language) +{ + Lang_zephir = language; + buildPhpKeywordHash (language); }
extern parserDefinition* PhpParser (void) @@ -1468,7 +1497,19 @@ extern parserDefinition* PhpParser (void) def->kindCount = KIND_COUNT (PhpKinds); def->extensions = extensions; def->parser = findPhpTags; - def->initialize = initialize; + def->initialize = initializePhpParser; + return def; +} + +extern parserDefinition* ZephirParser (void) +{ + static const char *const extensions [] = { "zep", NULL }; + parserDefinition* def = parserNew ("Zephir"); + def->kinds = PhpKinds; + def->kindCount = KIND_COUNT (PhpKinds); + def->extensions = extensions; + def->parser = findZephirTags; + def->initialize = initializeZephirParser; return def; }
Modified: tagmanager/src/tm_parser.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -68,6 +68,7 @@ typedef enum TM_PARSER_ASCIIDOC, TM_PARSER_ABAQUS, TM_PARSER_RUST, + TM_PARSER_ZEPHIR, TM_PARSER_COUNT } TMParserType;
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).