Page MenuHomePhabricator

XHPAST array_function_derefence support
ClosedPublic

Authored by Firehed on Feb 6 2014, 5:27 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 20, 6:22 PM
Unknown Object (File)
Tue, Apr 16, 6:20 AM
Unknown Object (File)
Tue, Apr 16, 2:56 AM
Unknown Object (File)
Fri, Apr 12, 9:14 PM
Unknown Object (File)
Mon, Apr 1, 5:30 PM
Unknown Object (File)
Mon, Apr 1, 4:03 PM
Unknown Object (File)
Sat, Mar 30, 11:03 AM
Unknown Object (File)
Mar 18 2024, 5:41 PM
Tokens
"Manufacturing Defect?" token, awarded by epriestley.

Details

Summary

Ref. T4334. Makes "isset(foo()[1])" syntax work, which was added in 5.4

Test Plan

arc unit
Added test case for known-good syntax, TDD'd the grammar file until it worked (mostly scraped from Zend)
generate_php_symbols.php of WePay's entire codebase with updated XHPAST, no errors at all.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Oh, nice! This is way less messy than I thought it would be.

I'd expect these to generate an n_INDEX_ACCESS node, similar to this rule:

object_dim_list '[' dim_offset ']' {
  $$ = NNEW(n_INDEX_ACCESS);
  $$->appendChild($1);
  $$->appendChild($3);
  NMORE($$, $4);
}

Is that crazy?

Also, can we remove this block (near line 2607) without effect / breaking tests? I think it's a vestigial effort to fix part of this issue from XHP, which was written before PHP changed the grammar:

// Fix the "bug" in PHP's grammar where you can't chain the [] operator on a
// function call.
// This introduces some shift/reduce conflicts. We want the shift here to fall
// back to regular PHP grammar. In the case where it's an extension of the PHP
// grammar our code gets picked up.
expr_without_variable:
  expr '[' dim_offset ']' {
    if (yyextra->idx_expr) {
      yyextra->used = true;
    }
    $$ = NNEW(n_INDEX_ACCESS);
    $$->appendChild($1);
    $$->appendChild($3);
    NMORE($$, $4);
  }
;

I would guess it is now redundant with these more-complete rules. If it can be removed, that probably leaves the "idx_expr" and "used" properties on yyextra unused.

Sure, I'll give it a try and see what happens. I was mostly jumping around the Zend grammar and adding in stuff that looked missing - I was wondering about that second definition of expr_without_variable. It would be great if removing it reduced some conflicts as the comment suggests; there are only three in zend_language_parser.y and this is up to fifteen now.

Firehed updated this revision to Unknown Object (????).Feb 7 2014, 6:27 PM

Alright, let's try this one on for size. n_INDEX_ACCESS is now generated, and we were finally able to drop the expr_without_variable: second definition, and go from 15 to 5 shift/reduce conflicts along the way (very close to Zend's 3 - yay!)

  • port combined_scalar_offset from zend parser
  • tweaks, old tests now pass
  • remove comments
  • whitespace

Awesome! Thanks a ton for your work on this, few are brave enough to tread into a ".y" file.