rdf-ex/lib/rdf/sigils.ex
Marcel Otto 2b9aa62d69 core: yet another approach for RDF.Literal
- we now only the store the lexical form when it's non-canonical
- Literal validation and canonicalization
- a general RDF.Datatype.Test.Case
- also tested datatype implementations for booleans, integers, string and langStrings
- use literal sigils in Inspect implementation of Literals when possible
2017-04-23 23:41:29 +02:00

45 lines
1,007 B
Elixir

defmodule RDF.Sigils do
@doc ~S"""
Handles the sigil `~I` for IRIs.
Note: The given IRI string is precompiled into an IRI struct.
## Examples
iex> import RDF.Sigils
iex> ~I<http://example.com>
RDF.uri("http://example.com")
"""
defmacro sigil_I({:<<>>, _, [iri]}, []) when is_binary(iri) do
Macro.escape(RDF.uri(iri))
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.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