If I quote the following:

Code.string_to_quoted """
  if foo do
    "true"
  else
    "false"
  end
"""

I get the following AST:

{:if, [line: 1], [{:foo, [line: 1], nil}, [do: "true", else: "false"]]}

Which makes sense to me as the last node is a list. However, `when` seems 
to follow different rules and I'm not following exactly how Elixir parses 
it from the AST:

Code.strig_to_quoted """
  def foo(bar) when bar == 1 do
    "baz"
  end
"""

{:def, [line: 1],
 [{:when, [line: 1],
   [{:foo, [line: 1], [{:bar, [line: 1], nil}]},
    {:==, [line: 1], [{:bar, [line: 1], nil}, 1]}]}, [do: "baz"]]}

`when` is not in that last list, but is now the first element in the values 
for `:def`

Can someone point me to examples of how Elixir is parsing `when` within the 
source? I dug around in Kernel which brought me to elixir_def but got stuck 
there.

Use case: I am experimenting with writing some macro functions that could 
take guard clauses.

-- 
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-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/b3e81eb9-8cd9-4bfa-b6a1-f43216d7136f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to