-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed YAML parser to native Elixir
- Loading branch information
1 parent
d703b91
commit 4485d39
Showing
7 changed files
with
51 additions
and
13 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,37 @@ | ||
defmodule YamlExt do | ||
def decode_file(file_path) do | ||
case :yamerl_constr.file(file_path, detailed_constr: true) do | ||
[{ _, document }] -> decode(document) | ||
_ -> %{} | ||
end | ||
end | ||
|
||
defp decode(document) do | ||
case _to_map(document) do | ||
"" -> %{} | ||
decoded -> decoded | ||
end | ||
end | ||
|
||
defp _to_map({ :yamerl_seq, :yamerl_node_seq, _tag, _loc, seq, _n }), | ||
do: Enum.map(seq, &_to_map(&1)) | ||
|
||
defp _to_map({ :yamerl_map, :yamerl_node_map, _tag, _loc, map_tuples }), | ||
do: _tuples_to_map(map_tuples, %{}) | ||
|
||
defp _to_map({ _yamler_element, _yamler_node_element, _tag, _loc, elem }), | ||
do: to_string(elem) | ||
|
||
defp _to_map({ _yamler_element, _yamler_node_element, _tag, _loc }), | ||
do: "" | ||
|
||
defp _tuples_to_map([], map), | ||
do: map | ||
|
||
defp _tuples_to_map([{ key, val } | rest], map) do | ||
case key do | ||
{ :yamerl_str, :yamerl_node_str, _tag, _log, name } -> | ||
_tuples_to_map(rest, Dict.put_new(map, to_string(name), _to_map(val))) | ||
end | ||
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 |
---|---|---|
@@ -1 +1 @@ | ||
%{"yomel": {:hex, :yomel, "0.2.2"}} | ||
%{"yamerl": {:git, "git://github.com/yakaz/yamerl.git", "ae810a808817d9482b4628ae3e20d746e3729fe0", []}} |
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