Skip to content

Highlight named funs called _, fix README and test record field types - #22

Merged
robertoaloi merged 5 commits into
mainfrom
fix/review-follow-ups
Sep 30, 2026
Merged

robertoaloi merged 5 commits into
mainfrom
fix/review-follow-ups

Conversation

@robertoaloi

Copy link
Copy Markdown
Member

Follow-ups from syncing the grammar into the ELP VS Code extension, where a review turned up a few issues.

Highlight named funs called _

A named fun can be called _, but the name patterns required at least one character after a leading underscore. With a / later on the same line, the implicit fun rule took over, ended at the / and left end outside the fun:

m() -> fun _(A) -> A / 2 end.

_ is now accepted as a name in the named fun rule and in the clause name patterns of the fun expression rules.

Test where record field types start and end

No grammar change. A typed record field is scoped meta.type.erlang from its :: to the comma or brace that ends the field. The new tests show that a comma nested in the type (in a tuple, a fun type or a binary) doesn't end the region early, and that a default value, which Erlang writes before the ::, stays an expression:

-record(typed_fields, {a :: {integer(), fun((a, b) -> c)},
                       b :: <<_:8, _:_*8>>,
                       c = fun() -> ok end :: fun(() -> ok)}).

README fixes

  • Fix a typo (ignode → ignore).
  • Fix the path of the snapshot tests (./test/snap → ./tests/snap).
  • Load the Markdown test grammar in the snapshot update command. Since Stop Markdown in doc attributes from leaking past the closing quotes #21 the snapshot tests run with it, but the documented command didn't load it, so running it as written rewrote the docstring and sigil snapshots with doc attributes scoped as generic directives.

Tests

npm test passes. The new tests for named funs called _ fail without the fix.

The snapshot tests run with the Markdown stand-in grammar since the
doc-directive fix, but the update command in the README did not load
it. Running it as documented rewrote the docstring and sigil snapshots
with doc attributes scoped as generic directives.
A named fun can be called `_`, but the name patterns required at least
one character after a leading underscore. A lone `_` name was not
recognised, so with a `/` later on the same line the implicit fun rule
took over, ended at the `/` and left `end` outside the fun:

    fun _(A) -> A / 2 end

Accept `_` as a name in the named fun rule and in the clause name
patterns of the fun expression rules.
A typed record field is scoped meta.type.erlang from its `::` to the
comma or brace that ends the field. Add tests showing that a comma
nested in the type (in a tuple, a fun type or a binary) does not end
the region early, and that a default value, which Erlang writes before
the `::`, stays an expression.
@robertoaloi
robertoaloi merged commit 49f7a9a into main Sep 30, 2026
2 checks passed
meta-codesync Bot pushed a commit to WhatsApp/erlang-language-platform that referenced this pull request Sep 30, 2026
Summary:
Sync both copies of the Erlang TextMate grammar (the ELP extension and the internal `nuclide.erlang` extension) with https://github.com/erlang-ls/grammar at `49f7a9a`. Both copies now match upstream byte for byte.

Changes since the last sync:

- erlang-ls/grammar#19: named fun expressions (`fun Name(...) -> ... end`) are highlighted correctly, and no longer scope the rest of the file as an implicit fun. Zero-arity fun expressions such as `fun() -> ok end` are keywords instead of function types. The function type rule now only applies inside types (`-type`, `-opaque`, `-spec`, `-callback`, typed record fields), via a new `meta.type.erlang` scope. Fixes pgourlain/vscode_erlang#316 and #317.
- erlang-ls/grammar#20: a fun type after a top-level range (`-type t() :: 1..10 | fun(() -> ok).`) or in a `-nominal` type no longer scopes the rest of the file as a fun expression.
- erlang-ls/grammar#21: upstreams the fix for Markdown leaking out of `-doc`/`-moduledoc` attributes (D98300495), which only lived in these copies. No behaviour change here.
- erlang-ls/grammar#22: follow-ups from the review of this diff. Named funs called `_` (`fun _(A) -> A end`) are highlighted as named funs. `README.md` typos fixed (`ignode`, `./test/snap`) and the snapshot update command loads the Markdown test grammar. Upstream also adds tests showing that a comma nested in a record field type does not end the `meta.type.erlang` region, and that a default value stays an expression.

`README.md` is synced too (test instructions and references); `LICENSE` is unchanged.

Reviewed By: jcpetruzza

Differential Revision: D122532634

fbshipit-source-id: cabfee7809fcd0e0977d700bc71b8b50db8cd02f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant