We have problem when printing statement and inline nodes.
Example:
<?php echo 'test'; ?>
<?php
echo 'test;
echo 'test';
echo 'test';
?>
We need information when php tag opening and closing. Any idea how best we can get this information? Maybe add node.hasOpenTag and node.hasCloseTag (or maybe best names). It is allow output all tags as is.
<?php if (...): ?>
<div>foo</div>
<?php endif; ?>
But, for control structure it is not good solution :disappointed:
Maybe you can export tags array as comment with position? I think it will be solve our problem :+1:
I could provide an option in order to export tokens into an array, so it would be more generic. By joining all tokens you have exactly the same output as the original file.
The implementation is compliant with this function : http://php.net/manual/en/function.token-get-all.php
Hi @evilebottnawi,
You can try the new tokens extraction here - https://glayzzle.com/php-parser/
Here a sample code that has no nodes, but can be serialized with tokens :
The offsets on tokens are :
token name - if it's not defined, it's plain text nodetext - the token inner textline - the line (keeped from php get_tokens_all)start offsetend offset PHP Script :
<?php /** **/ ?>
AST Structure :
{
"kind": "program",
"children": [],
"errors": [],
"comments": [
{
"kind": "commentblock",
"value": "/** **/"
}
],
"tokens": [
[
"T_OPEN_TAG",
"<?php ",
1,
0,
6
],
[
"T_DOC_COMMENT",
"/** **/",
1,
6,
13
],
[
"T_WHITESPACE",
" ",
1,
13,
14
],
[
"T_CLOSE_TAG",
"?>",
1,
14,
16
]
]
}