An Erlang grammar for tree-sitter.
See the docs for design and development information.
Above: an excerpt from rabbitmq/khepri using this grammar in the Helix editor.
From the docs on macros:
It is good programming practice, but not mandatory, to ensure that a macro definition is a valid Erlang syntactic form.
This grammar attempts to parse within define
attributes with best-effort
but some macro definitions and their resulting macros may produce (ERROR)
nodes.
It's pretty complete despite the above caveat. It has a 99.58% pass rate against the .erl/.hrl files in the OTP codebase1. Try it out on the online playground.
This project is licensed under the Apache-2.0 license. Any files under
the queries/
directory are licensed under the BSD 0-clause license.
Footnotes
-
The remaining files that exhibit errors are either not truly Erlang or use preprocessor directives with blatantly invalid syntax. This can be measured with
tree-sitter parse --quiet --stat path/to/otp/**.{erl,hrl}
. ↩