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.
This commit is contained in:
parent
c1aba3862d
commit
f6068d0e86
@ -61,7 +61,8 @@
|
|||||||
ObjcParser, \
|
ObjcParser, \
|
||||||
AsciidocParser, \
|
AsciidocParser, \
|
||||||
AbaqusParser, \
|
AbaqusParser, \
|
||||||
RustParser
|
RustParser, \
|
||||||
|
ZephirParser
|
||||||
|
|
||||||
#endif /* _PARSERS_H */
|
#endif /* _PARSERS_H */
|
||||||
|
|
||||||
|
@ -227,6 +227,7 @@ typedef struct {
|
|||||||
} tokenInfo;
|
} tokenInfo;
|
||||||
|
|
||||||
static langType Lang_php;
|
static langType Lang_php;
|
||||||
|
static langType Lang_zephir;
|
||||||
|
|
||||||
static boolean InPhp = FALSE; /* whether we are between <? ?> */
|
static boolean InPhp = FALSE; /* whether we are between <? ?> */
|
||||||
|
|
||||||
@ -240,14 +241,14 @@ static struct {
|
|||||||
static vString *CurrentNamesapce;
|
static vString *CurrentNamesapce;
|
||||||
|
|
||||||
|
|
||||||
static void buildPhpKeywordHash (void)
|
static void buildPhpKeywordHash (const langType language)
|
||||||
{
|
{
|
||||||
const size_t count = sizeof (PhpKeywordTable) / sizeof (PhpKeywordTable[0]);
|
const size_t count = sizeof (PhpKeywordTable) / sizeof (PhpKeywordTable[0]);
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < count ; i++)
|
for (i = 0; i < count ; i++)
|
||||||
{
|
{
|
||||||
const keywordDesc* const p = &PhpKeywordTable[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 @@ getNextChar:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
parseIdentifier (token->string, c);
|
parseIdentifier (token->string, c);
|
||||||
token->keyword = analyzeToken (token->string, Lang_php);
|
token->keyword = analyzeToken (token->string, getSourceLanguage ());
|
||||||
if (token->keyword == KEYWORD_NONE)
|
if (token->keyword == KEYWORD_NONE)
|
||||||
token->type = TOKEN_IDENTIFIER;
|
token->type = TOKEN_IDENTIFIER;
|
||||||
else
|
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 */
|
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(...) */
|
/* skip use(...) */
|
||||||
if (token->type == TOKEN_KEYWORD && token->keyword == KEYWORD_use)
|
if (token->type == TOKEN_KEYWORD && token->keyword == KEYWORD_use)
|
||||||
{
|
{
|
||||||
@ -1435,11 +1447,10 @@ static void enterScope (tokenInfo *const parentToken,
|
|||||||
deleteToken (token);
|
deleteToken (token);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void findPhpTags (void)
|
static void findTags (void)
|
||||||
{
|
{
|
||||||
tokenInfo *const token = newToken ();
|
tokenInfo *const token = newToken ();
|
||||||
|
|
||||||
InPhp = FALSE;
|
|
||||||
CurrentStatement.access = ACCESS_UNDEFINED;
|
CurrentStatement.access = ACCESS_UNDEFINED;
|
||||||
CurrentStatement.impl = IMPL_UNDEFINED;
|
CurrentStatement.impl = IMPL_UNDEFINED;
|
||||||
CurrentNamesapce = vStringNew ();
|
CurrentNamesapce = vStringNew ();
|
||||||
@ -1454,10 +1465,28 @@ static void findPhpTags (void)
|
|||||||
deleteToken (token);
|
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;
|
Lang_php = language;
|
||||||
buildPhpKeywordHash ();
|
buildPhpKeywordHash (language);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initializeZephirParser (const langType language)
|
||||||
|
{
|
||||||
|
Lang_zephir = language;
|
||||||
|
buildPhpKeywordHash (language);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern parserDefinition* PhpParser (void)
|
extern parserDefinition* PhpParser (void)
|
||||||
@ -1468,7 +1497,19 @@ extern parserDefinition* PhpParser (void)
|
|||||||
def->kindCount = KIND_COUNT (PhpKinds);
|
def->kindCount = KIND_COUNT (PhpKinds);
|
||||||
def->extensions = extensions;
|
def->extensions = extensions;
|
||||||
def->parser = findPhpTags;
|
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;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ typedef enum
|
|||||||
TM_PARSER_ASCIIDOC,
|
TM_PARSER_ASCIIDOC,
|
||||||
TM_PARSER_ABAQUS,
|
TM_PARSER_ABAQUS,
|
||||||
TM_PARSER_RUST,
|
TM_PARSER_RUST,
|
||||||
|
TM_PARSER_ZEPHIR,
|
||||||
TM_PARSER_COUNT
|
TM_PARSER_COUNT
|
||||||
} TMParserType;
|
} TMParserType;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user