PHP: parse traits
http://www.php.net/manual/en/language.oop5.traits.php
This commit is contained in:
parent
77c45aa82b
commit
33c84f739d
@ -105,6 +105,7 @@ typedef enum {
|
|||||||
K_INTERFACE,
|
K_INTERFACE,
|
||||||
K_LOCAL_VARIABLE,
|
K_LOCAL_VARIABLE,
|
||||||
K_NAMESPACE,
|
K_NAMESPACE,
|
||||||
|
K_TRAIT,
|
||||||
K_VARIABLE,
|
K_VARIABLE,
|
||||||
COUNT_KIND
|
COUNT_KIND
|
||||||
} phpKind;
|
} phpKind;
|
||||||
@ -116,6 +117,7 @@ static kindOption PhpKinds[COUNT_KIND] = {
|
|||||||
{ TRUE, 'i', "interface", "interfaces" },
|
{ TRUE, 'i', "interface", "interfaces" },
|
||||||
{ FALSE, 'l', "local", "local variables" },
|
{ FALSE, 'l', "local", "local variables" },
|
||||||
{ TRUE, 'n', "namespace", "namespaces" },
|
{ TRUE, 'n', "namespace", "namespaces" },
|
||||||
|
{ TRUE, 't', "trait", "traits" },
|
||||||
{ TRUE, 'v', "variable", "variables" }
|
{ TRUE, 'v', "variable", "variables" }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -957,6 +959,33 @@ static boolean parseClassOrIface (tokenInfo *const token, const phpKind kind)
|
|||||||
return readNext;
|
return readNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* parses a trait:
|
||||||
|
* trait Foo {} */
|
||||||
|
static boolean parseTrait (tokenInfo *const token)
|
||||||
|
{
|
||||||
|
boolean readNext = TRUE;
|
||||||
|
tokenInfo *name;
|
||||||
|
|
||||||
|
readToken (token);
|
||||||
|
if (token->type != TOKEN_IDENTIFIER)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
name = newToken ();
|
||||||
|
copyToken (name, token, TRUE);
|
||||||
|
|
||||||
|
makeSimplePhpTag (name, K_TRAIT, ACCESS_UNDEFINED);
|
||||||
|
|
||||||
|
readToken (token);
|
||||||
|
if (token->type == TOKEN_OPEN_CURLY)
|
||||||
|
enterScope (token, name->string, K_TRAIT);
|
||||||
|
else
|
||||||
|
readNext = FALSE;
|
||||||
|
|
||||||
|
deleteToken (name);
|
||||||
|
|
||||||
|
return readNext;
|
||||||
|
}
|
||||||
|
|
||||||
/* parse a function
|
/* parse a function
|
||||||
*
|
*
|
||||||
* if @name is NULL, parses a normal function
|
* if @name is NULL, parses a normal function
|
||||||
@ -1253,6 +1282,7 @@ static void enterScope (tokenInfo *const parentToken,
|
|||||||
{
|
{
|
||||||
case KEYWORD_class: readNext = parseClassOrIface (token, K_CLASS); break;
|
case KEYWORD_class: readNext = parseClassOrIface (token, K_CLASS); break;
|
||||||
case KEYWORD_interface: readNext = parseClassOrIface (token, K_INTERFACE); break;
|
case KEYWORD_interface: readNext = parseClassOrIface (token, K_INTERFACE); break;
|
||||||
|
case KEYWORD_trait: readNext = parseTrait (token); break;
|
||||||
case KEYWORD_function: readNext = parseFunction (token, NULL); break;
|
case KEYWORD_function: readNext = parseFunction (token, NULL); break;
|
||||||
case KEYWORD_const: readNext = parseConstant (token); break;
|
case KEYWORD_const: readNext = parseConstant (token); break;
|
||||||
case KEYWORD_define: readNext = parseDefine (token); break;
|
case KEYWORD_define: readNext = parseDefine (token); break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user