> 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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to