#line C macro equivalent in php ?

php.internals

William Candillon

20 years ago
Hello, I'd like to know, if it's possible to create a php function in C which modify the line number and the php interpreter. It will be very useful for tools generating php code (lex, yacc, smarty etc). For exemple: echo __FILE__//show parser.php __setLine(8);__setFile('parser.y'); toto(); Will show the following warning: Call to undefined function: toto() in parser.y at line 9 Best regards, William
-- William Candillon Telecom Lille Student E-mail: wcandillon@elv.enic.fr Tel: +33(0) 6 67 99 13 16 CV: http://wcandillon.netcv.org Resume: http://wcandillon.en.netcv.org

Xuefer Tinys

20 years ago
i'll second that idea, but not the syntax. template engine such smarty, and compiler compiler, need it really.

Marcus Börger

20 years ago
Hello William, as long as php has no goto no such generator is capable of generating php code. When that changes we want to have something alike of course. But actuall it is already in HEAD ... So then....Why not cimply go with this: #line <file> <line> to simple becuase the tools in question would already do that? Thursday, May 11, 2006, 9:31:49 AM, you wrote:
> Hello,
> I'd like to know, if it's possible to create a php function in C which > modify the line number and the php interpreter. It will be very useful > for tools generating php code (lex, yacc, smarty etc). > For exemple: > echo __FILE__//show parser.php > __setLine(8);__setFile('parser.y'); > toto(); > Will show the following warning: > Call to undefined function: toto() in parser.y at line 9
> Best regards,
> William
> -- > William Candillon > Telecom Lille Student > E-mail: wcandillon@elv.enic.fr > Tel: +33(0) 6 67 99 13 16 > CV: http://wcandillon.netcv.org > Resume: http://wcandillon.en.netcv.org
Best regards, Marcus

Jared Williams

20 years ago
> Hello William, > > as long as php has no goto no such generator is capable of > generating php code. > When that changes we want to have > something alike of course. But actuall it is already in HEAD > ... So then....Why not cimply go with this: > #line <file> <line> > to simple becuase the tools in question would already do that?
No such generator? ... I've have a port of Lemon that outputs PHP5, so a #line or equivalent would be nice. Jared

Sara Golemon

20 years ago
> I'd like to know, if it's possible to create a php function > in C which modify the line number and the php interpreter. > It will be very useful for tools generating php code (lex, > yacc, smarty etc). > For exemple: > echo __FILE__//show parser.php > __setLine(8);__setFile('parser.y'); > toto(); > Will show the following warning: > Call to undefined function: toto() in parser.y at line 9 >
There's a Google SoC proposal on writing a preprocessor (to eval #define statements), we could try to scope creap this sort of thing into that....(store the line references in a map then override the error handler to translate file/line based on those map entries) Whether done in that project or by someone else, this *is* something that can be done by an extension and so should probably stay out of the engine. In fact, you could do it in userspace.... /** Generated code blah blah... */ $yyfoo = $yybar; blah(); /**#line parser.y 123 */ whatever::thingymabob(); $foo = $$yy29188; Then use a set_error_handler() callback: function my_error_handler($errstr, $errno, $errfile, $errline) { list($probedfilename, $probedfileline) = scan_through_file_watching_for_line_directives_and_counting($errfile, $errline); die "Error came from {$probedfilename} on line {$probedfileline}\n"; } Of course, the userspace version doesn't deal with parse errors, but hopefully your code generator isn't generating invalid code... -Sara