mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Port tokenizer extension
This commit is contained in:
parent
a6be32f59a
commit
c6eba25571
1 changed files with 20 additions and 24 deletions
|
@ -104,7 +104,7 @@ PHP_MINFO_FUNCTION(tokenizer)
|
|||
static void tokenize(zval *return_value TSRMLS_DC)
|
||||
{
|
||||
zval token;
|
||||
zval *keyword;
|
||||
zval keyword;
|
||||
int token_type;
|
||||
zend_bool destroy;
|
||||
int token_line = 1;
|
||||
|
@ -130,18 +130,17 @@ static void tokenize(zval *return_value TSRMLS_DC)
|
|||
}
|
||||
|
||||
if (token_type >= 256) {
|
||||
MAKE_STD_ZVAL(keyword);
|
||||
array_init(keyword);
|
||||
add_next_index_long(keyword, token_type);
|
||||
array_init(&keyword);
|
||||
add_next_index_long(&keyword, token_type);
|
||||
if (token_type == T_END_HEREDOC) {
|
||||
if (CG(increment_lineno)) {
|
||||
token_line = ++CG(zend_lineno);
|
||||
CG(increment_lineno) = 0;
|
||||
}
|
||||
}
|
||||
add_next_index_stringl(keyword, (char *)zendtext, zendleng, 1);
|
||||
add_next_index_long(keyword, token_line);
|
||||
add_next_index_zval(return_value, keyword);
|
||||
add_next_index_stringl(&keyword, (char *)zendtext, zendleng, 1);
|
||||
add_next_index_long(&keyword, token_line);
|
||||
add_next_index_zval(return_value, &keyword);
|
||||
} else {
|
||||
add_next_index_stringl(return_value, (char *)zendtext, zendleng, 1);
|
||||
}
|
||||
|
@ -158,12 +157,11 @@ static void tokenize(zval *return_value TSRMLS_DC)
|
|||
) {
|
||||
// fetch the rest into a T_INLINE_HTML
|
||||
if (zendcursor != zendlimit) {
|
||||
MAKE_STD_ZVAL(keyword);
|
||||
array_init(keyword);
|
||||
add_next_index_long(keyword, T_INLINE_HTML);
|
||||
add_next_index_stringl(keyword, (char *)zendcursor, zendlimit - zendcursor, 1);
|
||||
add_next_index_long(keyword, token_line);
|
||||
add_next_index_zval(return_value, keyword);
|
||||
array_init(&keyword);
|
||||
add_next_index_long(&keyword, T_INLINE_HTML);
|
||||
add_next_index_stringl(&keyword, (char *)zendcursor, zendlimit - zendcursor, 1);
|
||||
add_next_index_long(&keyword, token_line);
|
||||
add_next_index_zval(return_value, &keyword);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -179,20 +177,18 @@ static void tokenize(zval *return_value TSRMLS_DC)
|
|||
*/
|
||||
PHP_FUNCTION(token_get_all)
|
||||
{
|
||||
char *source = NULL;
|
||||
int argc = ZEND_NUM_ARGS();
|
||||
int source_len;
|
||||
zval source_z;
|
||||
zend_string *source;
|
||||
zval source_zval;
|
||||
zend_lex_state original_lex_state;
|
||||
|
||||
if (zend_parse_parameters(argc TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &source) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ZVAL_STRINGL(&source_z, source, source_len, 1);
|
||||
ZVAL_STR(&source_zval, STR_COPY(source));
|
||||
zend_save_lexical_state(&original_lex_state TSRMLS_CC);
|
||||
|
||||
if (zend_prepare_string_for_scanning(&source_z, "" TSRMLS_CC) == FAILURE) {
|
||||
if (zend_prepare_string_for_scanning(&source_zval, "" TSRMLS_CC) == FAILURE) {
|
||||
zend_restore_lexical_state(&original_lex_state TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
@ -202,7 +198,7 @@ PHP_FUNCTION(token_get_all)
|
|||
tokenize(return_value TSRMLS_CC);
|
||||
|
||||
zend_restore_lexical_state(&original_lex_state TSRMLS_CC);
|
||||
zval_dtor(&source_z);
|
||||
zval_dtor(&source_zval);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -210,13 +206,13 @@ PHP_FUNCTION(token_get_all)
|
|||
*/
|
||||
PHP_FUNCTION(token_name)
|
||||
{
|
||||
int argc = ZEND_NUM_ARGS();
|
||||
long type;
|
||||
|
||||
if (zend_parse_parameters(argc TSRMLS_CC, "l", &type) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
RETVAL_STRING(get_token_type_name(type), 1);
|
||||
|
||||
RETVAL_STRING(get_token_type_name(type));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue