Page MenuHomePhabricator

Fix a minor XHPAST bug
ClosedPublic

Authored by joshuaspence on Jan 5 2015, 12:25 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 22, 8:41 AM
Unknown Object (File)
Tue, Nov 19, 5:58 AM
Unknown Object (File)
Mon, Nov 18, 11:25 AM
Unknown Object (File)
Mon, Nov 4, 11:53 PM
Unknown Object (File)
Thu, Oct 31, 1:11 AM
Unknown Object (File)
Oct 16 2024, 4:01 PM
Unknown Object (File)
Oct 15 2024, 5:07 AM
Unknown Object (File)
Oct 9 2024, 2:05 PM

Details

Summary

Currently, there is a minor bug with XHPAST when parsing class methods with no modifiers. See D10687 for some more information.

Test Plan

Specifically, consider the following:

class Foo {
  public function bar() {}
  function baz() {}
}

Previously when parsing this code with xhpast we get a node of type n_METHOD_DECLARATION: "public function bar() {}" and a node of type n_METHOD_DECLARATION: "baz() {}". After this change, xhpast correctly parses this as a node of type n_METHOD_DECLARATION: "public function bar() {}" and a node of type n_METHOD_DECLARATION: "function baz() {}".

Diff Detail

Repository
rPHU libphutil
Branch
master
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 3579
Build 3587: [Placeholder Plan] Wait for 30 Seconds

Event Timeline

joshuaspence retitled this revision from to Fix a minor XHPAST bug.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.
epriestley edited edge metadata.

I think there's a cleaner fix inline?

support/xhpast/parser.y
1176

I think you want:

NLMORE($$, $2);

...here, instead. As written, this change will expand the range of $1 (which is n_METHOD_MODIFIER_LIST) to include the keyword "function", but I think this is not desirable: the word "function" does not seem like it should be part of the "method modifier list" to me.

If you use NLMORE($$, $2) instead, you'll expand the range of $$ (the n_METHOD_DECLARATION) leftward, if $2 is defined and has a leftmost extent that is left-more than the left side of $$.

Basically, you'll move the beginning of the n_METHOD_DECLARATION backward to include function if it does not already.

This revision now requires changes to proceed.Jan 5 2015, 7:13 PM

Overall, you'll get the same n_METHOD_DECLARATION as this patch, but without expanding the n_METHOD_MODIFIER_LIST as a side effect.

support/xhpast/parser.y
1176

Sure, that seems reasonable. I think I based this on the fact that n_CLASS_ATTRIBUTES includes class.

I'm going to have to update the test cases as well, is this okay?

epriestley edited edge metadata.
This revision is now accepted and ready to land.Jan 6 2015, 2:43 PM
This revision was automatically updated to reflect the committed changes.

Since this landed, calling getDocblockToken() on a n_METHOD_DECLARATION does not return docblock token anymore.

Ah -- the order of the NLMORE() is important here, because appendChild() does not extend the tokens to the left. By calling NMLORE() first, appendChild() does not change the token range if $1 exists. I'll fix appendChild().