Php-parser: Question: Inline parent node?

Created on 30 May 2018  路  3Comments  路  Source: glayzzle/php-parser

From https://github.com/prettier/plugin-php/pull/407#issuecomment-393327568

for something like this

<div>
  <div>
    <?php
    echo '<';
    echo '<';
    ?>
  </div>
</div>

The ast currently has both echo nodes at the same hierarchy level as the inline html. If this is the "right" solution thats fine, but just wanted to get people's opinions to see if a parent program node or something should be considered every time php tags are opened.

question

All 3 comments

(for me) How it's currently implemented it's the right solution syntactically speaking, but from a usability perspective it could be really useful to have hierarchical blocks when a new php tag is opened with all the code "grouped" inside.

For sure in simple code could improve readability and grouping but I wonder in that messy php codes out there if it's going to be really useful or just creates levels of complexity.

That was my two cents

Hi,

Let's take another code sample :

<body>
  <h1>A list</h1>
  <?php foreach($listing as $i => $entry): ?>
  <div class="item" class="<?= ($i % 2 === 0) ? 'paire' : 'impaire'; ?>">
    <h2><?php echo $entry->title; ?></h2>
    <?php if ($entry->data): ?>
      <div class="body">...</div>
    <?php endif; ?>
  </div>
  <?php endforeach; ?>
  <?php echo "another node"; ?>
</body>

Not sure how to represent AST node tree with this sample ? Both nodes foreach and echo are on the same level (as the inline) + inside the foreach node (inlines & echo & if are at the same level)

Ah yup good point :) I'm sold, closing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexander-akait picture alexander-akait  路  3Comments

alexander-akait picture alexander-akait  路  9Comments

chris-l picture chris-l  路  7Comments

mgrip picture mgrip  路  3Comments

Rivendall picture Rivendall  路  6Comments