joelspadin / tree-sitter-devicetree

Tree-sitter grammar for Devicetree files
MIT License
28 stars 6 forks source link

Fix property node's "value" field #5

Open nickcoutsos opened 2 years ago

nickcoutsos commented 2 years ago

I've noticed that the value field in a property node gives = instead of the property's value node. This change just restructures that part of the rule so that the entire value field is optional, and the portion used in the field starts after the = token.

I was a little unsure about this approach since it makes it sound like the presence of the field is optional but this is consistent with the tests.

nickcoutsos commented 2 years ago

While looking into fixing an issue with my handling of unit_address nodes I noticed that there's a similar issue with the node's address field returning @. If this fix is alright I'd be happy to make a followup PR to update fields that have optional matches.

nickcoutsos commented 1 year ago

It seems the underlying issue here is that the value field was being applied to the = (non-named child) as well, and node.childForFieldName() only returns the first. For my use case I need to use a cursor to access each instance of the field so I can just restrict that to named children anyway, but I think the above fix is otherwise valid.