rdf-ex/lib/rdf/sigils.ex

64 lines
1.3 KiB
Elixir
Raw Normal View History

2017-04-10 00:38:30 +00:00
defmodule RDF.Sigils do
@moduledoc """
Sigils for the most common types of RDF nodes.
"""
2017-04-10 00:38:30 +00:00
@doc ~S"""
Handles the sigil `~I` for IRIs.
2017-04-10 01:06:20 +00:00
Note: The given IRI string is precompiled into an IRI struct.
2017-04-10 00:38:30 +00:00
## Examples
iex> import RDF.Sigils
iex> ~I<http://example.com>
RDF.uri("http://example.com")
"""
2017-04-18 01:27:28 +00:00
defmacro sigil_I({:<<>>, _, [iri]}, []) when is_binary(iri) do
Macro.escape(RDF.uri(iri))
end
2017-04-10 00:38:30 +00:00
2017-05-19 15:19:06 +00:00
@doc ~S"""
Handles the sigil `~B` for blank nodes.
## Examples
iex> import RDF.Sigils
iex> ~B<foo>
RDF.bnode("foo")
"""
defmacro sigil_B({:<<>>, _, [bnode]}, []) when is_binary(bnode) do
Macro.escape(RDF.BlankNode.new(bnode))
end
2017-04-18 01:27:28 +00:00
@doc ~S"""
Handles the sigil `~L` for plain Literals.
The sigil modifier can be used to specify a language tag.
Note: Languages with subtags are not supported.
## Examples
iex> import RDF.Sigils
iex> ~L"foo"
RDF.literal("foo")
iex> ~L"foo"en
RDF.literal("foo", language: "en")
"""
defmacro sigil_L(value, language)
defmacro sigil_L({:<<>>, _, [value]}, []) when is_binary(value) do
Macro.escape(RDF.String.new(value))
2017-04-18 01:27:28 +00:00
end
defmacro sigil_L({:<<>>, _, [value]}, language) when is_binary(value) do
Macro.escape(RDF.LangString.new(value, %{language: to_string(language)}))
2017-04-18 01:27:28 +00:00
end
2017-04-10 00:38:30 +00:00
end