semantic icon indicating copy to clipboard operation
semantic copied to clipboard

Leaf nodes in precise AST sometimes have unnecessary contents

Open patrickt opened this issue 5 years ago • 0 comments

Ported from https://github.com/tree-sitter/haskell-tree-sitter/issues/136.

In Python, true and false are matched by rules of the same name. The TH generates leaf datatypes for these containing Text, like so:

newtype True = True { bytes :: Text }

However, as there’s no way for the grammar to ever produce a parse tree for which bytes is something other than "true", this is superfluous and could be elided for improved performance and a closer match to the language’s semantics. Otherwise put, all values of True should really be the same, but the Text field means that the datatype doesn’t enforce that.

patrickt avatar Feb 13 '20 16:02 patrickt