/
sigils.ex
61 lines (44 loc) · 1.32 KB
/
sigils.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
defmodule RDF.Sigils do
@moduledoc """
Sigils for the most common types of RDF nodes.
"""
@doc ~S"""
Handles the sigil `~I` for IRIs.
Note: The given IRI string is precompiled into an `RDF.IRI` struct.
## Examples
iex> import RDF.Sigils
iex> ~I<http://example.com>
RDF.iri("http://example.com")
"""
defmacro sigil_I({:<<>>, _, [iri]}, []) when is_binary(iri) do
Macro.escape(RDF.iri!(iri))
end
@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
@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.XSD.String.new(value))
end
defmacro sigil_L({:<<>>, _, [value]}, language) when is_binary(value) do
Macro.escape(RDF.LangString.new(value, language: to_string(language)))
end
end