Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 02e75b6
Showing
6 changed files
with
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/ebin | ||
/deps | ||
erl_crash.dump |
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 @@ | ||
# EXN — Elixir Notation |
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,40 @@ | ||
defmodule Exn do | ||
def decode(string) when is_binary(string) do | ||
values = | ||
case Code.string_to_ast!(string) do | ||
{:__block__,_, [item]} -> item | ||
{:__block__,_, items} -> items | ||
item -> item | ||
end | ||
unless Macro.term?(values) do | ||
{:error, :term_expected} | ||
else | ||
values | ||
end | ||
end | ||
|
||
def encode(terms) when is_list(terms) do | ||
if keywords?(terms) do | ||
"[" <> | ||
Enum.join( | ||
lc {key, value} inlist terms do | ||
"#{key}: " <> encode(value) | ||
end, ", ") | ||
<> "]" | ||
else | ||
inspect terms | ||
end | ||
end | ||
def encode(term), do: inspect(term) | ||
|
||
defp keywords?(terms) do | ||
Enum.all?(terms, | ||
function do | ||
{key, _value} -> | ||
is_atom(key) | ||
_ -> | ||
false | ||
end) and | ||
List.sort(terms) == terms | ||
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,20 @@ | ||
defmodule Exn.Mixfile do | ||
use Mix.Project | ||
|
||
def project do | ||
[ app: :exn, | ||
version: "0.0.1", | ||
deps: deps ] | ||
end | ||
|
||
# Configuration for the OTP application | ||
def application do | ||
[] | ||
end | ||
|
||
# Returns the list of dependencies in the format: | ||
# { :foobar, "0.1", git: "https://github.com/elixir-lang/foobar.git" } | ||
defp deps do | ||
[] | ||
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,9 @@ | ||
Code.require_file "../test_helper.exs", __FILE__ | ||
|
||
defmodule ExnTest do | ||
use ExUnit.Case | ||
|
||
test "the truth" do | ||
assert true | ||
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 @@ | ||
ExUnit.start |