summaryrefslogtreecommitdiff
path: root/Zend/zend_highlight.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-03-15 12:36:49 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-03-21 16:27:48 +0100
commite528762c1c59bc0bd0bd6d78246c14269630cf0f (patch)
treee8ee4eec737685c2a0ea5c2ba78fb86fd54035e5 /Zend/zend_highlight.c
parent1cf84f1579c54233c69a9394a8c02d29e092e32a (diff)
downloadphp-git-e528762c1c59bc0bd0bd6d78246c14269630cf0f.tar.gz
Switch to bison location tracking
Locations for AST nodes are now tracked with the help of bison location tracking. This is more accurate than what we currently do and easier to extend with more information. A zend_ast_loc structure is introduced, which is used for the location stack. Currently it only holds the start lineno, but can be extended to also hold end lineno and offset/column information in the future. All AST constructors now accept a zend_ast_loc* as first argument, and will use it to determine their lineno. Previously this used either the CG(zend_lineno), or the smallest AST lineno of child nodes. On the parser side, the location structure for a whole rule can be obtained using the &@$ character salad.
Diffstat (limited to 'Zend/zend_highlight.c')
-rw-r--r--Zend/zend_highlight.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Zend/zend_highlight.c b/Zend/zend_highlight.c
index 5e94df0a99..168a51ca30 100644
--- a/Zend/zend_highlight.c
+++ b/Zend/zend_highlight.c
@@ -85,13 +85,14 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
{
zval token;
int token_type;
+ zend_ast_loc loc;
char *last_color = syntax_highlighter_ini->highlight_html;
char *next_color;
zend_printf("<code>");
zend_printf("<span style=\"color: %s\">\n", last_color);
/* highlight stuff coming back from zendlex() */
- while ((token_type=lex_scan(&token, NULL))) {
+ while ((token_type = lex_scan(&token, NULL, &loc))) {
switch (token_type) {
case T_INLINE_HTML:
next_color = syntax_highlighter_ini->highlight_html;
@@ -174,10 +175,11 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
ZEND_API void zend_strip(void)
{
zval token;
+ zend_ast_loc loc;
int token_type;
int prev_space = 0;
- while ((token_type=lex_scan(&token, NULL))) {
+ while ((token_type = lex_scan(&token, NULL, &loc))) {
switch (token_type) {
case T_WHITESPACE:
if (!prev_space) {
@@ -193,7 +195,7 @@ ZEND_API void zend_strip(void)
case T_END_HEREDOC:
zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
/* read the following character, either newline or ; */
- if (lex_scan(&token, NULL) != T_WHITESPACE) {
+ if (lex_scan(&token, NULL, &loc) != T_WHITESPACE) {
zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
}
zend_write("\n", sizeof("\n") - 1);