Skip to content

Commit

Permalink
Initial source code check-in
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Oct 9, 2012
0 parents commit 02e75b6
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
/ebin
/deps
erl_crash.dump
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
# EXN — Elixir Notation
40 changes: 40 additions & 0 deletions lib/exn.ex
@@ -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
20 changes: 20 additions & 0 deletions mix.exs
@@ -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
9 changes: 9 additions & 0 deletions test/exn_test.exs
@@ -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
1 change: 1 addition & 0 deletions test/test_helper.exs
@@ -0,0 +1 @@
ExUnit.start

0 comments on commit 02e75b6

Please sign in to comment.