-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1237 from bettio/increase-elixir-support
Increase Elixir support Increases Elixir support by adding support to Enumerable and Collectable protocols, and to a number of Exceptions. Fixes #1174 These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
- Loading branch information
Showing
41 changed files
with
3,535 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# This file is part of elixir-lang. | ||
# | ||
# Copyright 2012-2018 Elixir Contributors | ||
# https://github.com/elixir-lang/elixir/tree/v1.7.4/lib/elixir/lib/exception.ex | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
defmodule ArgumentError do | ||
# This avoids crashing the compiler at build time | ||
@compile {:autoload, false} | ||
|
||
defexception message: "argument error" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# This file is part of elixir-lang. | ||
# | ||
# Copyright 2012-2018 Elixir Contributors | ||
# https://github.com/elixir-lang/elixir/tree/v1.7.4/lib/elixir/lib/exception.ex | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
defmodule ArithmeticError do | ||
# This avoids crashing the compiler at build time | ||
@compile {:autoload, false} | ||
|
||
defexception message: "bad argument in arithmetic expression" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# This file is part of elixir-lang. | ||
# | ||
# Copyright 2012-2018 Elixir Contributors | ||
# https://github.com/elixir-lang/elixir/tree/v1.7.4/lib/elixir/lib/exception.ex | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
defmodule BadArityError do | ||
# This avoids crashing the compiler at build time | ||
@compile {:autoload, false} | ||
|
||
defexception [:function, :args] | ||
|
||
@impl true | ||
def message(exception) do | ||
fun = exception.function | ||
args = exception.args | ||
insp = Enum.map_join(args, ", ", &inspect/1) | ||
# TODO: enable as soon as :erlang.fun_info and Function.info are implemented | ||
# {:arity, arity} = Function.info(fun, :arity) | ||
# "#{inspect(fun)} with arity #{arity} called with #{count(length(args), insp)}" | ||
"#{inspect(fun)} called with #{count(length(args), insp)}" | ||
end | ||
|
||
defp count(0, _insp), do: "no arguments" | ||
defp count(1, insp), do: "1 argument (#{insp})" | ||
defp count(x, insp), do: "#{x} arguments (#{insp})" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# This file is part of elixir-lang. | ||
# | ||
# Copyright 2012-2018 Elixir Contributors | ||
# https://github.com/elixir-lang/elixir/tree/v1.7.4/lib/elixir/lib/exception.ex | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
defmodule BadBooleanError do | ||
# This avoids crashing the compiler at build time | ||
@compile {:autoload, false} | ||
|
||
defexception [:term, :operator] | ||
|
||
@impl true | ||
def message(exception) do | ||
"expected a boolean on left-side of \"#{exception.operator}\", got: #{inspect(exception.term)}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# This file is part of elixir-lang. | ||
# | ||
# Copyright 2012-2018 Elixir Contributors | ||
# https://github.com/elixir-lang/elixir/tree/v1.7.4/lib/elixir/lib/exception.ex | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
defmodule BadFunctionError do | ||
# This avoids crashing the compiler at build time | ||
@compile {:autoload, false} | ||
|
||
defexception [:term] | ||
|
||
@impl true | ||
def message(exception) do | ||
"expected a function, got: #{inspect(exception.term)}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# This file is part of elixir-lang. | ||
# | ||
# Copyright 2012-2018 Elixir Contributors | ||
# https://github.com/elixir-lang/elixir/tree/v1.7.4/lib/elixir/lib/exception.ex | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
defmodule BadMapError do | ||
# This avoids crashing the compiler at build time | ||
@compile {:autoload, false} | ||
|
||
defexception [:term] | ||
|
||
@impl true | ||
def message(exception) do | ||
"expected a map, got: #{inspect(exception.term)}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# This file is part of elixir-lang. | ||
# | ||
# Copyright 2012-2018 Elixir Contributors | ||
# https://github.com/elixir-lang/elixir/tree/v1.7.4/lib/elixir/lib/exception.ex | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
defmodule BadStructError do | ||
# This avoids crashing the compiler at build time | ||
@compile {:autoload, false} | ||
|
||
defexception [:struct, :term] | ||
|
||
@impl true | ||
def message(exception) do | ||
"expected a struct named #{inspect(exception.struct)}, got: #{inspect(exception.term)}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# This file is part of elixir-lang. | ||
# | ||
# Copyright 2012-2018 Elixir Contributors | ||
# https://github.com/elixir-lang/elixir/tree/v1.7.4/lib/elixir/lib/exception.ex | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
defmodule CaseClauseError do | ||
# This avoids crashing the compiler at build time | ||
@compile {:autoload, false} | ||
|
||
defexception [:term] | ||
|
||
@impl true | ||
def message(exception) do | ||
"no case clause matching: #{inspect(exception.term)}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# This file is part of elixir-lang. | ||
# | ||
# Copyright 2012-2018 Elixir Contributors | ||
# https://github.com/elixir-lang/elixir/commits/v1.7.4/lib/elixir/lib/collectable.ex | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
defimpl Collectable, for: List do | ||
def into(original) do | ||
fun = fn | ||
list, {:cont, x} -> [x | list] | ||
list, :done -> original ++ :lists.reverse(list) | ||
_, :halt -> :ok | ||
end | ||
|
||
{[], fun} | ||
end | ||
end |
Oops, something went wrong.