joelspadin / tree-sitter-devicetree

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

`/delete-node/` reported as error #14

Closed ensc closed 1 month ago

ensc commented 9 months ago

syntax description rejects a lot of /delete-node/ + /delete-property/ case. E.g. in

/ {
    /delete-node/ foo;
    /delete-property/ bar;
};

/ {
    /delete-node/ foo@0;
};

/ {
    /delete-node/foo;
};

/ {
    /delete-property/bar;
};

/delete-node/ &bar;

only the first block works. Rest is reported as

(document
 (node name: (identifier) {
  (delete_node /delete-node/ name: (identifier) ;)
  (delete_property /delete-property/ name: (identifier) ;)
  } ;)
 (node name: (identifier) {
  (delete_node /delete-node/ name: (identifier)
   name: (ERROR @ (identifier))
   ;)
  } ;)
 (node name: (identifier) {
  (ERROR (identifier) ;)
  } ;)
 (node name: (identifier) {
  (ERROR (identifier) ;)
  } ;)
 (ERROR (identifier)
  (reference & label: (identifier))
  ;))
axelkar commented 8 months ago

The 3rd & 4th blocks are invalid. AFAIK, directives with arguments are supposed to have whitespace.

The spec is not specific, but reading dtc's source code or the elinux.org wiki can help

axelkar commented 8 months ago

Oh and to the following TODO, yes they are. https://github.com/joelspadin/tree-sitter-devicetree/blob/2087a5b965db2a9efabab958a27fd8ddf43038a2/grammar.js#L180

https://elinux.org/Device_Tree_Mysteries#Signed_Property_Values Apparently dtc allows negative integers?

ensc commented 8 months ago

The 3rd & 4th blocks are invalid. AFAIK, directives with arguments are supposed to have whitespace.

They are accepted by dtc and I am using them for years...

Whitespaces are simply ignored; e.g.

    a = <23>;
    b=<42>;
    c  =  <666>;

is completely valid. Why should they matter for /delete-.../?

axelkar commented 8 months ago

They are accepted by dtc and I am using them for years...

Thanks for telling me! I looked at the parser spec but I don't have enough knowledge of tree-sitter to fix it. No idea how it requires whitespace in seq.