Skip to content

Conversation

jonatanklosko
Copy link
Member

Closes #77.

### Ref 8. Empty anonymous function

As opposed to the Elixir parser, we successfully parse anonymous functions with
no stab clauses, so this is valid:

```
x = fn

end
```

This code may appear if an editor extension automatically inserts `end` after
`fn`. We want it to parse as anonymous function node, so that functionality such
as indentation works as expected.

If we require at least one stab clause, the above would be parsed with an error,
where `fn` and `end` are both identifiers. That is not useful. Note that both
`fn` and `end` are reserved keywords, so there is no case where they would
actually be identifiers, hence no ambiguity.

Ideally, this would parse it as an anonymous function node with an error, however
that does not seem straightforward to achieve.

@jonatanklosko jonatanklosko merged commit 12be92d into main Dec 9, 2024
1 check passed
@jonatanklosko jonatanklosko deleted the jk-fn-empty branch December 9, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Handling empty anonymous functions
2 participants