Skip to content

Conversation

williamthome
Copy link
Contributor

@williamthome williamthome commented Jan 24, 2025

Closes #3.

Currently, only "top level" forms of a module are allowed at the beginning of the source_file rule, but this makes this tree-sitter not usable, for example, in Markdown code blocks.

Allowing any fragment of an expression makes this tree-sitter usable for other languages to inject Erlang code, for example, a new language in the Phoenix (Elixir) style, that embeeds Erlang code in HTML.


Notes:

  1. The tree generated for fragmented code is (source_file (...exprs)). Maybe the tree as is today as (source_file (...forms)) should be for a file/module structure and (fragment (...exprs)) should be for fragmented parts of code
  2. The term "fragment" is what comes to my mind, but could be any other
  3. I'm not sure about the conflicts order introduced by this PR

Before this PR

tree-sitter-erlang-before

After this PR

tree-sitter-erlang-after

@facebook-github-bot
Copy link
Contributor

Hi @williamthome!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@williamthome williamthome force-pushed the feat/allow-exprs-in-source-file-rule branch from 40e22c7 to 080a5cd Compare January 27, 2025 09:40
@williamthome williamthome force-pushed the feat/allow-exprs-in-source-file-rule branch from 080a5cd to 3086281 Compare January 27, 2025 09:43
@facebook-github-bot
Copy link
Contributor

@alanz has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@alanz
Copy link
Member

alanz commented Feb 4, 2025

Thanks for this. It causes a few problems in ELP if we try to use it, for parsing escripts

And the fundamental problem is the shebang causes it to go into error mode, and the prior version recovered gracefully.

I think the solution may be to add an additional form time that parses the shebang.

I am happy to give that a go.

@alanz
Copy link
Member

alanz commented Feb 4, 2025

FYI, to check it, in the ELP repo change the tree-sitter-erlang dep to point at this directory (checked out), then run cargo xtask codegen once the tree-sitter-erlang tests pass.

then cargo test --workspace.

facebook-github-bot pushed a commit to WhatsApp/erlang-language-platform that referenced this pull request Feb 7, 2025
Summary:
Closes WhatsApp/tree-sitter-erlang#3.

Currently, only "top level" forms of a module are allowed at the beginning of the source_file rule, but this makes this tree-sitter not usable, for example, in Markdown code blocks.

Allowing any fragment of an expression makes this tree-sitter usable for other languages to inject Erlang code, for example, a new language in the Phoenix (Elixir) style, that embeeds Erlang code in HTML.

 ---

Notes:

1. The tree generated for fragmented code is `(source_file (...exprs))`. Maybe the tree as is today as `(source_file (...forms))` should be for a file/module structure and `(fragment (...exprs))` should be for fragmented parts of code
2. The term "fragment" is what comes to my mind, but could be any other
3. I'm not sure about the conflicts order introduced by this PR

 ---

## Before this PR

![tree-sitter-erlang-before](https://github.com/user-attachments/assets/b922e440-8ca0-432e-845d-82ad6c532299)

## After this PR

![tree-sitter-erlang-after](https://github.com/user-attachments/assets/0a835a76-1a90-4d7c-b171-9e46c9c47301)

X-link: WhatsApp/tree-sitter-erlang#9

Reviewed By: michalmuskala

Differential Revision: D69120163

Pulled By: alanz

fbshipit-source-id: 73f02ac6b61dbd0bec100d2dcfaa52b7694304cb
@facebook-github-bot
Copy link
Contributor

@alanz merged this pull request in bafd09b.

@williamthome williamthome deleted the feat/allow-exprs-in-source-file-rule branch February 10, 2025 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support parsing rebar.config files
3 participants