Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce support for Mod.{A, B, C} on imports, alias, require and use #3666

Merged
merged 4 commits into from
Sep 25, 2015

Conversation

lexmag
Copy link
Member

@lexmag lexmag commented Sep 3, 2015

Closes #3646.

  • adjust elixir_parser to emit new AST
  • multi alias
defmodule MultiAlias1 do
  alias List.{Chars}
end

multiline:

defmodule MultiAlias2 do
  alias Mix.{
    CLI,
    Shell.IO
  }
end

just random place:

[List.{Chars}, 1]
** (UndefinedFunctionError) undefined function: List.{}/1
    (elixir) List.{}(Chars)

invalid identifier:

defmodule MultiAlias1 do
  alias List.{Chars, 42}
end
** (SyntaxError) iex:2: syntax error before: '}'
  • multi import
  • multi require
  • multi use

There are a couple of open questions:

  • do we need to support trailing comma, e.g.: macro List.{Chars,}
  • do we need to support blank import (alias, etc.), e.g.: macro List.{}

@josevalim, I would like any feedback on it.

@@ -405,8 +406,16 @@ dot_op -> '.' eol : '$1'.
dot_identifier -> identifier : '$1'.
dot_identifier -> matched_expr dot_op identifier : build_dot('$2', '$1', '$3').

dot_alias -> aliases : {'__aliases__', meta_from_token('$1', 0), ?exprs('$1')}.
dot_alias -> matched_expr dot_op aliases : build_dot_alias('$2', '$1', '$3').
dot_plain_alias -> aliases : {'__aliases__', meta_from_token('$1', 0), ?exprs('$1')}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to change the parser, I have found this old commit, we just need to bring it back:

b4b9ecc

Except I wouldn't bring [], although we can bring both {} and <<>>. The reason we shouldn't bring [] it is because we don't have :[] in AST anyway.

@lexmag lexmag force-pushed the import-many-friends branch 19 times, most recently from ce1f700 to aff2bb3 Compare September 6, 2015 20:15
expand_multi_alias_call(Kind, Meta, Base, Refs, E);
true ->
compile_error(Meta, ?m(E, file),
"options is not supported by multi-alias")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do support options... we don't support :as.

@lexmag lexmag force-pushed the import-many-friends branch 5 times, most recently from ff058a6 to b24e029 Compare September 6, 2015 23:38
@lexmag lexmag force-pushed the import-many-friends branch 3 times, most recently from bbc0af9 to 9efc109 Compare September 7, 2015 00:35
@lexmag lexmag changed the title [WIP] Introduce support for Mod.{A, B, C} on imports, alias, require and use Introduce support for Mod.{A, B, C} on imports, alias, require and use Sep 7, 2015
@lexmag
Copy link
Member Author

lexmag commented Sep 7, 2015

Updated.

raise ArgumentError, "invalid arguments for use, expected an atom or alias as argument"
end

case module do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try moving the case to a separate function that returns a list. Then you can just do: Enum.map parse_aliases(module, __CALLER__), fun with unquote_splicing at the end.

@lexmag lexmag force-pushed the import-many-friends branch 2 times, most recently from c6e2cce to 1df23e7 Compare September 7, 2015 11:26
@josevalim
Copy link
Member

Beautiful. It will be in 1.2. :)

@josevalim josevalim added this to the v1.2.0 milestone Sep 7, 2015
@lexmag lexmag force-pushed the import-many-friends branch from 1df23e7 to 8c57c91 Compare September 25, 2015 09:54
josevalim added a commit that referenced this pull request Sep 25, 2015
Introduce support for Mod.{A, B, C} on imports, alias, require and use
@josevalim josevalim merged commit 0e5804f into elixir-lang:master Sep 25, 2015
@lexmag lexmag deleted the import-many-friends branch September 25, 2015 11:40
@knewter
Copy link

knewter commented Sep 25, 2015

o/ \o

@paulcsmith
Copy link

This is going to be awesome!

@mschae
Copy link

mschae commented Sep 25, 2015

Awesome! This is great news, thanks so much!

Also do you guys (@knewter @paulcsmith and @lexmag) share the same photographer? ;)

@paulcsmith
Copy link

@mschae Haha I hadn't noticed that! Maybe we do!

@knewter
Copy link

knewter commented Sep 25, 2015

Ha, mine came from a headshot at OSCon 2014...anticipating responses :) /cc @paulcsmith @lexmag

@paulcsmith
Copy link

@knewter Got mine when I joined the company I'm working for :)

@lexmag
Copy link
Member Author

lexmag commented Sep 25, 2015

Hehe, homemade for visa application about 2 years ago.

KronicDeth added a commit to KronicDeth/intellij-elixir that referenced this pull request Jul 29, 2016
Includes the ability to quote multiple aliases, but no references yet.
Ports elixir-lang/elixir#3666.
KronicDeth added a commit to KronicDeth/intellij-elixir that referenced this pull request Jul 29, 2016
Includes the ability to quote multiple aliases, but no references yet.
Ports elixir-lang/elixir#3666.
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.

6 participants