joelspadin / tree-sitter-devicetree

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

Some fixes for /delete-node/ and /delete-property/ directives #18

Open igor-prusov opened 1 month ago

igor-prusov commented 1 month ago

Linux kernel has files that don't have whitespaces after /delete-node/ and /delete-property/ directives. Also there are /delete-node/ definitions on document's top level. This means that DTC accepts such files.

Examples:

sdm845-cheza-r2.dts

&src_pp3300_l22a {
    /delete-property/regulator-boot-on;
    /delete-property/regulator-always-on;
};

aspeed-ast2600-evb-a1.dts

/ {
    model = "AST2600 A1 EVB";
    compatible = "aspeed,ast2600-evb-a1", "aspeed,ast2600-evb", "aspeed,ast2600";

    /delete-node/regulator-vcc-sdhci0;
    /delete-node/regulator-vcc-sdhci1;
    /delete-node/regulator-vccq-sdhci0;
    /delete-node/regulator-vccq-sdhci1;
};

/delete-node/ &sdc;

This PR allowes to accept all those derectives as valid. I've used lexical precedence to make tree-sitter prioritize keyword token over an identifier, though I am not entirely sure why it currently gets reduced to identifier with an error recovery over delete_node.

Fixes #14