Use function body rescue where possible
This commit is contained in:
parent
fc4a86483d
commit
b4c3dc8d98
3 changed files with 20 additions and 26 deletions
|
@ -97,11 +97,9 @@ defmodule RDF.IRI do
|
|||
def absolute?(%URI{scheme: nil}), do: false
|
||||
def absolute?(%URI{scheme: _}), do: true
|
||||
def absolute?(qname) when is_atom(qname) and not qname in [nil, true, false] do
|
||||
try do
|
||||
qname |> Namespace.resolve_term |> absolute?()
|
||||
rescue
|
||||
_ -> false
|
||||
end
|
||||
qname |> Namespace.resolve_term |> absolute?()
|
||||
rescue
|
||||
_ -> false
|
||||
end
|
||||
def absolute?(_), do: false
|
||||
|
||||
|
|
|
@ -55,13 +55,11 @@ defmodule RDF.Serialization do
|
|||
def format(name)
|
||||
|
||||
def format(name) when is_binary(name) do
|
||||
try do
|
||||
name
|
||||
|> String.to_existing_atom
|
||||
|> format()
|
||||
rescue
|
||||
ArgumentError -> nil
|
||||
end
|
||||
name
|
||||
|> String.to_existing_atom
|
||||
|> format()
|
||||
rescue
|
||||
ArgumentError -> nil
|
||||
end
|
||||
|
||||
def format(name) do
|
||||
|
|
|
@ -46,22 +46,20 @@ defmodule RDF.Turtle.Decoder do
|
|||
def parse(tokens), do: tokens |> :turtle_parser.parse
|
||||
|
||||
defp build_graph(ast, base) do
|
||||
try do
|
||||
{graph, _} =
|
||||
Enum.reduce ast, {RDF.Graph.new, %State{base_iri: base}}, fn
|
||||
{:triples, triples_ast}, {graph, state} ->
|
||||
with {statements, state} = triples(triples_ast, state) do
|
||||
{RDF.Graph.add(graph, statements), state}
|
||||
end
|
||||
{graph, _} =
|
||||
Enum.reduce ast, {RDF.Graph.new, %State{base_iri: base}}, fn
|
||||
{:triples, triples_ast}, {graph, state} ->
|
||||
with {statements, state} = triples(triples_ast, state) do
|
||||
{RDF.Graph.add(graph, statements), state}
|
||||
end
|
||||
|
||||
{:directive, directive_ast}, {graph, state} ->
|
||||
{graph, directive(directive_ast, state)}
|
||||
{:directive, directive_ast}, {graph, state} ->
|
||||
{graph, directive(directive_ast, state)}
|
||||
|
||||
end
|
||||
{:ok, graph}
|
||||
rescue
|
||||
error -> {:error, Exception.message(error)}
|
||||
end
|
||||
end
|
||||
{:ok, graph}
|
||||
rescue
|
||||
error -> {:error, Exception.message(error)}
|
||||
end
|
||||
|
||||
defp directive({:prefix, {:prefix_ns, _, ns}, iri}, state) do
|
||||
|
|
Loading…
Reference in a new issue