HomePhabricator

Improve parsing of namespaces

Tags
None
Referenced Files
F973992: xhpast-after.png
Nov 17 2015, 8:19 PM
F973991: xhpast-before.png
Nov 17 2015, 8:19 PM
Subscribers
None

Description

Improve parsing of namespaces

Summary:
Currently PHP namespaces are parsed in two different ways, depending on the syntax used. For example, consider the following example:

<?php

namespace A;

class B {}

namespace A\B\C {
 class D {}
}

namespace {
  class A {}
}

This is currently parsed by XHPAST as follows (see https://secure.phabricator.com/xhpast/view/915/):

xhpast-before.png (799×297 px, 28 KB)

This generally makes it difficult to determine the namespace in which a class is declared (unless the namespace is defined using the namespace { ... } syntax, which is somewhat rare). Instead, always parse namespaces as if they were of the namespace { ... } form.

Test Plan:
Added unit tests. Also inspected the AST after this change:

xhpast-after.png (708×243 px, 25 KB)

Reviewers: jim_reed, Blessed Reviewers, epriestley

Reviewed By: Blessed Reviewers, epriestley

Subscribers: JolanYacht, Korvin

Differential Revision: https://secure.phabricator.com/D14498

Details

Provenance
joshuaspenceAuthored on
joshuaspencePushed on Nov 17 2015, 8:19 PM
Reviewer
Blessed Reviewers
Differential Revision
D14498: Improve parsing of namespaces
Parents
rPHUe9ed72483a14: Apply phutil XHPAST linter standard
Branches
Unknown
Tags
Unknown
Build Status
Buildable 8893
Build 10411: Run Core Tests