Places in Elixir code that set Macro.Env context to match

29 views
Skip to first unread message

Luke Imhoff

unread,
May 22, 2016, 10:40:34 PM5/22/16
to elixir-lang-core
I'm trying to track down where in the Elixir and Erlang code in elixir-lang/elixir that Macro.Env context is set to :match.  I have a feeling I am slow approaching an equivalent implementation with my `ResolveState#put(DECLARING_SCOPE, true)` in Intellij Elixir (https://github.com/KronicDeth/intellij-elixir/blob/8347836a86ced50dedccd044014a9029538c1208/src/org/elixir_lang/psi/scope/Variable.java#L236, https://github.com/KronicDeth/intellij-elixir/blob/8347836a86ced50dedccd044014a9029538c1208/src/org/elixir_lang/psi/scope/Variable.java#L400, https://github.com/KronicDeth/intellij-elixir/blob/8347836a86ced50dedccd044014a9029538c1208/src/org/elixir_lang/psi/scope/Variable.java#L410, https://github.com/KronicDeth/intellij-elixir/blob/8347836a86ced50dedccd044014a9029538c1208/src/org/elixir_lang/psi/impl/ElixirPsiImplUtil.java#L1372), but if I had the real rules in Elixir's own code I could double check I'm not missing a use case for Macro.Env context :match.  Currently, I've just been by checking variable resolution for every variable in elixir-lang/elixir/lib/elixir by hand and adding DECLARING_SCOPE rules when it helps not have to check up the AST (PSI for IntellIJ) to determine if something really can be a variable declaration or can only be a usage.

José Valim

unread,
May 23, 2016, 5:19:05 AM5/23/16
to elixir-l...@googlegroups.com
Luke,

The only expressions that can change the scope are special forms. Therefore, the solution is to look at the special forms and see where in them a variable can be set. We have:

* left side of =
* left side of <- in with and for
* left side of -> in case:do, receive:do, try:catch:else, with:else
* left side of -> in fn

And the function definitions (which can happen in any regular macro).



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Mon, May 23, 2016 at 4:40 AM, Luke Imhoff <kroni...@gmail.com> wrote:
I'm trying to track down where in the Elixir and Erlang code in elixir-lang/elixir that Macro.Env context is set to :match.  I have a feeling I am slow approaching an equivalent implementation with my `ResolveState#put(DECLARING_SCOPE, true)` in Intellij Elixir (https://github.com/KronicDeth/intellij-elixir/blob/8347836a86ced50dedccd044014a9029538c1208/src/org/elixir_lang/psi/scope/Variable.java#L236, https://github.com/KronicDeth/intellij-elixir/blob/8347836a86ced50dedccd044014a9029538c1208/src/org/elixir_lang/psi/scope/Variable.java#L400, https://github.com/KronicDeth/intellij-elixir/blob/8347836a86ced50dedccd044014a9029538c1208/src/org/elixir_lang/psi/scope/Variable.java#L410, https://github.com/KronicDeth/intellij-elixir/blob/8347836a86ced50dedccd044014a9029538c1208/src/org/elixir_lang/psi/impl/ElixirPsiImplUtil.java#L1372), but if I had the real rules in Elixir's own code I could double check I'm not missing a use case for Macro.Env context :match.  Currently, I've just been by checking variable resolution for every variable in elixir-lang/elixir/lib/elixir by hand and adding DECLARING_SCOPE rules when it helps not have to check up the AST (PSI for IntellIJ) to determine if something really can be a variable declaration or can only be a usage.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/5e67cdda-df8c-4161-8549-842b2979e500%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages