Page MenuHomePhabricator

Improve parsing of namespaces
AbandonedPublic

Authored by joshuaspence on Nov 18 2015, 1:34 AM.
Tags
None
Referenced Files
F18761261: D14506.id35093.diff
Oct 6 2025, 1:18 PM
F18749867: D14506.id.diff
Oct 4 2025, 5:23 AM
F18749010: D14506.diff
Oct 4 2025, 1:57 AM
F18705169: D14506.id.diff
Sep 28 2025, 10:24 AM
F18697342: D14506.diff
Sep 27 2025, 9:33 AM
F18523976: D14506.diff
Sep 6 2025, 11:30 AM
F18183404: D14506.diff
Aug 16 2025, 11:27 AM
F18168825: D14506.id35093.diff
Aug 15 2025, 4:22 PM
Subscribers

Details

Summary

D14498 wasn't quite correct. Specifically, it incorrectly parsed the following code:

<?php

namespace A;

class A {}
class B {}
Test Plan
xhpast-before.png (404×191 px, 13 KB)
xhpast-after.png (432×204 px, 14 KB)
BeforeAfter }

Diff Detail

Repository
rPHU libphutil
Branch
master
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 8903
Build 10427: Run Core Tests
Build 10426: arc lint + arc unit

Event Timeline

joshuaspence retitled this revision from to Improve parsing of namespaces.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
support/xhpast/parser.y
57

I have no idea if this is okay.

support/xhpast/parser.y
57

The resolution does seem okay, but it's probably better to rewrite the grammar in a way that it's not ambiguous.

This would also make something like this parse badly:

namespace A;

class T { }

namespace B;

class T { }

Here, the second namespace statement would be a child of the first (according to the grammar), even though they're both top-level.

Hmm yeah, you are correct. I am wondering if maybe I should just revert D19948... It would still be possible to implement some sort of getNamespace() method (I think), but it would be significantly harder.