2017-04-10 00:38:30 +00:00
|
|
|
defmodule RDF.Sigils do
|
2017-06-16 16:45:52 +00:00
|
|
|
@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-08-20 20:35:14 +00:00
|
|
|
Note: The given IRI string is precompiled into an `RDF.IRI` struct.
|
2017-04-10 01:06:20 +00:00
|
|
|
|
2017-04-10 00:38:30 +00:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> import RDF.Sigils
|
|
|
|
iex> ~I<http://example.com>
|
2017-08-20 20:35:14 +00:00
|
|
|
RDF.iri("http://example.com")
|
2017-04-10 00:38:30 +00:00
|
|
|
|
|
|
|
"""
|
2017-04-18 01:27:28 +00:00
|
|
|
defmacro sigil_I({:<<>>, _, [iri]}, []) when is_binary(iri) do
|
2017-08-20 20:35:14 +00:00
|
|
|
Macro.escape(RDF.iri!(iri))
|
2017-04-18 01:27:28 +00:00
|
|
|
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
|
2017-04-23 21:41:29 +00:00
|
|
|
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
|
2017-04-23 21:41:29 +00:00
|
|
|
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
|