Skip to content

Commit 3d435ba

Browse files
committed
Added ability to enable YYDEBUG on fly
1 parent 87bee46 commit 3d435ba

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
8+
### Added
9+
- Added ability to enable `YYDEBUG` on fly by exporting `ZEPHIR_YYDEBUG`
10+
environment variable with the value of 1.
11+
812
### Fixed
913
- Fixed syntax error with final class and use of extends and implements
1014
[#48](https://github.com/phalcon/php-zephir-parser/issues/48)

parser/scanner.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
#ifndef PHP_ZEPHIR_SCANNER_H
12-
#define PHP_ZEPHIR_SCANNER_H
12+
#define PHP_ZEPHIR_SCANNER_H 1
1313

1414
#define XX_SCANNER_RETCODE_EOF -1
1515
#define XX_SCANNER_RETCODE_ERR -2
@@ -160,14 +160,4 @@
160160
#define XX_T_ASSIGN_BITWISE_SHIFTLEFT 457
161161
#define XX_T_ASSIGN_BITWISE_SHIFTRIGHT 458
162162

163-
#ifdef YYDEBUG
164-
#undef YYDEBUG
165-
#endif
166-
167-
#if 0
168-
#define YYDEBUG(s, c) printf("State: %d char: %c\n", s, c)
169-
#else
170-
#define YYDEBUG(s, c)
171-
#endif
172-
173-
#endif
163+
#endif // PHP_ZEPHIR_SCANNER_H

parser/xx.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#ifndef PHP_ZEPHIR_XX_H
1010
#define PHP_ZEPHIR_XX_H 1
1111

12-
// to pull in the definition for zval
13-
#include <Zend/zend_types.h>
12+
#include <Zend/zend_types.h> // zval
13+
#include <Zend/zend_operators.h> // zend_atoi
14+
#include <stdlib.h> // getenv
15+
#include <stdio.h> // fprintf, stderr
1416

1517
/* List of tokens and their names */
1618
typedef struct _xx_token_names {
@@ -27,6 +29,7 @@ typedef struct _xx_token_names {
2729
* that any time you want to read data into the buffer, you need to cast the
2830
* pointers to be nonconst.
2931
*/
32+
3033
typedef struct _xx_scanner_state {
3134
/* The current character being looked at by the scanner.
3235
* This is the same as re2c's YYCURSOR. */
@@ -84,4 +87,23 @@ int parser_is_tracked(xx_scanner_state *state, zval **var);
8487
void parser_free_variable(xx_scanner_state *state, zval **var);
8588
int xx_get_token(xx_scanner_state *state, xx_scanner_token *token);
8689

90+
/* The YYDEBUG macro is designed to produce of trace information,
91+
* that will be written on stderr.
92+
*
93+
* To enable this feature just export ZEPHIR_YYDEBUG environment
94+
* variable with the value of 1.
95+
*/
96+
97+
#ifdef YYDEBUG
98+
#undef YYDEBUG
8799
#endif
100+
101+
#define YYDEBUG(s, c) do { \
102+
char *tmp; \
103+
tmp = getenv("ZEPHIR_YYDEBUG"); \
104+
if (tmp && zend_atoi(tmp, 1)) { \
105+
fprintf(stderr, "State: %d char: %c\n", s, c); \
106+
} \
107+
} while(0);
108+
109+
#endif // PHP_ZEPHIR_XX_H

0 commit comments

Comments
 (0)