diff --git a/lib/rdf.ex b/lib/rdf.ex index bc3862d..5e3f79f 100644 --- a/lib/rdf.ex +++ b/lib/rdf.ex @@ -70,6 +70,7 @@ defmodule RDF do def literal(lit = %Literal{}), do: lit def literal(value), do: Literal.new(value) + def literal(value, type), do: Literal.new(value, type) @doc """ Generator function for `RDF.Triple`s. @@ -96,6 +97,15 @@ defmodule RDF do iex> RDF.bnode(:foo) %RDF.BlankNode{id: :foo} """ - def bnode(id), do: BlankNode.new(:foo) + def bnode(id), do: BlankNode.new(id) + + +################################################################################ +# temporary manual RDF vocab definitions +# TODO: These should be defined as a vocabulary + + def langString do + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString") + end end diff --git a/lib/rdf/blank_node.ex b/lib/rdf/blank_node.ex index 4b2ba5b..473476f 100644 --- a/lib/rdf/blank_node.ex +++ b/lib/rdf/blank_node.ex @@ -7,6 +7,7 @@ defmodule RDF.BlankNode do @type t :: module def new, do: %RDF.BlankNode{id: make_ref} - def new(id) when is_atom(id), do: %RDF.BlankNode{id: id} + def new(id) when is_atom(id) or is_binary(id) or is_integer(id), + do: %RDF.BlankNode{id: id} end diff --git a/lib/rdf/literal.ex b/lib/rdf/literal.ex index bedd0a7..616a5fe 100644 --- a/lib/rdf/literal.ex +++ b/lib/rdf/literal.ex @@ -6,7 +6,7 @@ defmodule RDF.Literal do @type t :: module - alias RDF.XSD + alias RDF.{XSD, RDFS} defmodule InvalidLiteralError, do: defexception [:message] @@ -35,6 +35,8 @@ defmodule RDF.Literal do """ def new(value) + def new(value) when is_binary(value), + do: %RDF.Literal{value: value, datatype: XSD.string} def new(value) when is_boolean(value), do: %RDF.Literal{value: value, datatype: XSD.boolean} def new(value) when is_integer(value), @@ -43,7 +45,6 @@ defmodule RDF.Literal do do: %RDF.Literal{value: value, datatype: XSD.float} # def new(value) when is_atom(value), do: -# def new(value) when is_binary(value), do: # def new(value) when is_bitstring(value), do: # def new(value) when is_list(value), do: @@ -59,4 +60,40 @@ defmodule RDF.Literal do raise InvalidLiteralError, "#{inspect value} not convertible to a RDF.Literal" end + def new(value, language: language) when is_binary(value) do + %RDF.Literal{value: value, datatype: RDF.langString, language: language} + end + + def new(value, datatype: datatype) when is_binary(value) do + datatype_uri = RDF.uri(datatype) + cond do + datatype_uri == XSD.string -> %RDF.Literal{value: value, datatype: datatype_uri} + datatype_uri == XSD.integer -> %RDF.Literal{value: String.to_integer(value), datatype: datatype_uri} +# TODO: datatype_uri == XSD.byte -> nil # %RDF.Literal{value: String.to_integer(value), datatype: datatype_uri} +# TODO: datatype_uri == RDF.uri(RDFS.XMLLiteral) -> nil # %RDF.Literal{value: String.to_integer(value), datatype: datatype_uri} + # TODO: Should we support more values, like "1" etc.? + # TODO: Should we exclude any non-useful value? + datatype_uri == XSD.boolean -> %RDF.Literal{value: String.downcase(value) == "true", datatype: datatype_uri} + true -> %RDF.Literal{value: value, datatype: datatype_uri} + end + end + + def new(value, datatype: datatype) when is_integer(value) do + datatype_uri = RDF.uri(datatype) + cond do + datatype_uri == XSD.string -> %RDF.Literal{value: to_string(value), datatype: datatype_uri} + datatype_uri == XSD.integer -> %RDF.Literal{value: value, datatype: datatype_uri} + end + end + + def new(value, datatype: datatype) when is_boolean(value) do + datatype_uri = RDF.uri(datatype) + cond do + datatype_uri == XSD.boolean -> %RDF.Literal{value: value, datatype: datatype_uri} + # TODO: Should we exclude any non-useful value? + datatype_uri == XSD.string -> %RDF.Literal{value: to_string(value), datatype: datatype_uri} + datatype_uri == XSD.integer -> %RDF.Literal{value: (if value, do: 1, else: 0), datatype: datatype_uri} + end + end + end diff --git a/lib/rdf/ntriples/reader.ex b/lib/rdf/ntriples/reader.ex new file mode 100644 index 0000000..8c4ad50 --- /dev/null +++ b/lib/rdf/ntriples/reader.ex @@ -0,0 +1,43 @@ +defmodule RDF.NTriples.Reader do + @moduledoc """ + `RDF::NTriples` provides support for reading the N-Triples serialization + format. + + N-Triples is a line-based plain-text format for encoding an RDF graph. + It is a very restricted, explicit and well-defined subset of both + [Turtle](http://www.w3.org/TeamSubmission/turtle/) and + [Notation3](http://www.w3.org/TeamSubmission/n3/) (N3). + + The MIME content type for N-Triples files is `text/plain` and the + recommended file extension is `.nt`. + + An example of an RDF statement in N-Triples format: + + "Hex" . + """ + + use RDF.Reader + + def read_string(content, opts \\ []) do + with {:ok, tokens, _} <- tokenize(content), + {:ok, ast} <- parse(tokens) do + {:ok, build_graph(ast)} + else + {:error, {error_line, :ntriples_lexer, error_descriptor}, _error_line_again} -> + {:error, "N-Triple scanner error on line #{error_line}: #{inspect error_descriptor}"} + {:error, {error_line, :ntriples_parser, error_descriptor}} -> + {:error, "N-Triple parser error on line #{error_line}: #{inspect error_descriptor}"} + end + end + + defp tokenize(content), do: content |> to_charlist |> :ntriples_lexer.string + + defp parse(tokens), do: tokens |> :ntriples_parser.parse + + defp build_graph(ast) do + Enum.reduce ast, RDF.Graph.new, fn(triple, graph) -> + RDF.Graph.add(graph, triple) + end + end + +end diff --git a/lib/rdf/reader.ex b/lib/rdf/reader.ex new file mode 100644 index 0000000..54b7e93 --- /dev/null +++ b/lib/rdf/reader.ex @@ -0,0 +1,53 @@ +defmodule RDF.Reader do + @moduledoc false + + @callback read_file(String.t, keyword) :: keyword(RDF.Graph) + @callback read_file!(String.t, keyword) :: RDF.Graph + @callback read_string(String.t, keyword) :: keyword(RDF.Graph) + @callback read_string!(String.t, keyword) :: RDF.Graph + + defmacro __using__(_) do + quote bind_quoted: [], unquote: true do + @behaviour unquote(__MODULE__) + + def read(file_or_content, opts \\ []) do + if File.exists?(file_or_content) do + read_file(file_or_content, opts) + else + read_string(file_or_content, opts) + end + end + + def read!(file_or_content, opts \\ []) do + case read(file_or_content, opts) do + {:ok, graph} -> graph + {:error, reason} -> raise reason + end + end + + def read_file(file, opts \\ []) do + case File.read(file) do + {:ok, content} -> read_string(content, opts) + {:error, reason} -> {:error, reason} + end + end + + def read_file!(file, opts \\ []) do + case read_file(file, opts) do + {:ok, graph} -> graph + {:error, reason} -> raise reason + end + end + + def read_string!(content, opts \\ []) do + case read_string(content, opts) do + {:ok, graph} -> graph + {:error, reason} -> raise reason + end + end + + defoverridable [read: 2, read!: 2, read_file: 2, read_file!: 2, read_string!: 2] + end + end + +end diff --git a/lib/rdf/reader_parse_helper.ex b/lib/rdf/reader_parse_helper.ex new file mode 100644 index 0000000..12485b1 --- /dev/null +++ b/lib/rdf/reader_parse_helper.ex @@ -0,0 +1,25 @@ +defmodule RDF.Reader.ParseHelper do + @moduledoc false + + def to_uri({:iriref, line, value}) do + case URI.parse(value) do + %URI{scheme: nil} -> {:error, line, "#{value} is not a valid URI"} + %URI{path: nil} -> {:error, line, "#{value} is not a valid URI"} + parsed_uri -> {:ok, parsed_uri} + end + end + + def to_bnode({:blank_node_label, _line, value}), do: RDF.bnode(value) + + def to_literal({:string_literal_quote, _line, value}), + do: RDF.literal(value) + def to_literal({:string_literal_quote, _line, value}, type), + do: RDF.literal(value, [type]) + + def to_langtag({:langtag, _line, value}), do: value + + def bnode_str('_:' ++ value), do: List.to_string(value) + def langtag_str('@' ++ value), do: List.to_string(value) + def quoted_content_str(value), do: value |> List.to_string |> String.slice(1..-2) + +end diff --git a/src/ntriples_lexer.erl b/src/ntriples_lexer.erl new file mode 100644 index 0000000..716a7ab --- /dev/null +++ b/src/ntriples_lexer.erl @@ -0,0 +1,796 @@ +-file("/usr/local/Cellar/erlang/19.1/lib/erlang/lib/parsetools-2.1.3/include/leexinc.hrl", 0). +%% The source of this file is part of leex distribution, as such it +%% has the same Copyright as the other files in the leex +%% distribution. The Copyright is defined in the accompanying file +%% COPYRIGHT. However, the resultant scanner generated by leex is the +%% property of the creator of the scanner and is not covered by that +%% Copyright. + +-module(ntriples_lexer). + +-export([string/1,string/2,token/2,token/3,tokens/2,tokens/3]). +-export([format_error/1]). + +%% User code. This is placed here to allow extra attributes. +-file("src/ntriples_lexer.xrl", 31). + +quoted_content_str(TokenChars) -> 'Elixir.RDF.Reader.ParseHelper':quoted_content_str(TokenChars). +bnode_str(TokenChars) -> 'Elixir.RDF.Reader.ParseHelper':bnode_str(TokenChars). +langtag_str(TokenChars) -> 'Elixir.RDF.Reader.ParseHelper':langtag_str(TokenChars). + +-file("/usr/local/Cellar/erlang/19.1/lib/erlang/lib/parsetools-2.1.3/include/leexinc.hrl", 14). + +format_error({illegal,S}) -> ["illegal characters ",io_lib:write_string(S)]; +format_error({user,S}) -> S. + +string(String) -> string(String, 1). + +string(String, Line) -> string(String, Line, String, []). + +%% string(InChars, Line, TokenChars, Tokens) -> +%% {ok,Tokens,Line} | {error,ErrorInfo,Line}. +%% Note the line number going into yystate, L0, is line of token +%% start while line number returned is line of token end. We want line +%% of token start. + +string([], L, [], Ts) -> % No partial tokens! + {ok,yyrev(Ts),L}; +string(Ics0, L0, Tcs, Ts) -> + case yystate(yystate(), Ics0, L0, 0, reject, 0) of + {A,Alen,Ics1,L1} -> % Accepting end state + string_cont(Ics1, L1, yyaction(A, Alen, Tcs, L0), Ts); + {A,Alen,Ics1,L1,_S1} -> % Accepting transistion state + string_cont(Ics1, L1, yyaction(A, Alen, Tcs, L0), Ts); + {reject,_Alen,Tlen,_Ics1,L1,_S1} -> % After a non-accepting state + {error,{L0,?MODULE,{illegal,yypre(Tcs, Tlen+1)}},L1}; + {A,Alen,_Tlen,_Ics1,_L1,_S1} -> + string_cont(yysuf(Tcs, Alen), L0, yyaction(A, Alen, Tcs, L0), Ts) + end. + +%% string_cont(RestChars, Line, Token, Tokens) +%% Test for and remove the end token wrapper. Push back characters +%% are prepended to RestChars. + +-dialyzer({nowarn_function, string_cont/4}). + +string_cont(Rest, Line, {token,T}, Ts) -> + string(Rest, Line, Rest, [T|Ts]); +string_cont(Rest, Line, {token,T,Push}, Ts) -> + NewRest = Push ++ Rest, + string(NewRest, Line, NewRest, [T|Ts]); +string_cont(Rest, Line, {end_token,T}, Ts) -> + string(Rest, Line, Rest, [T|Ts]); +string_cont(Rest, Line, {end_token,T,Push}, Ts) -> + NewRest = Push ++ Rest, + string(NewRest, Line, NewRest, [T|Ts]); +string_cont(Rest, Line, skip_token, Ts) -> + string(Rest, Line, Rest, Ts); +string_cont(Rest, Line, {skip_token,Push}, Ts) -> + NewRest = Push ++ Rest, + string(NewRest, Line, NewRest, Ts); +string_cont(_Rest, Line, {error,S}, _Ts) -> + {error,{Line,?MODULE,{user,S}},Line}. + +%% token(Continuation, Chars) -> +%% token(Continuation, Chars, Line) -> +%% {more,Continuation} | {done,ReturnVal,RestChars}. +%% Must be careful when re-entering to append the latest characters to the +%% after characters in an accept. The continuation is: +%% {token,State,CurrLine,TokenChars,TokenLen,TokenLine,AccAction,AccLen} + +token(Cont, Chars) -> token(Cont, Chars, 1). + +token([], Chars, Line) -> + token(yystate(), Chars, Line, Chars, 0, Line, reject, 0); +token({token,State,Line,Tcs,Tlen,Tline,Action,Alen}, Chars, _) -> + token(State, Chars, Line, Tcs ++ Chars, Tlen, Tline, Action, Alen). + +%% token(State, InChars, Line, TokenChars, TokenLen, TokenLine, +%% AcceptAction, AcceptLen) -> +%% {more,Continuation} | {done,ReturnVal,RestChars}. +%% The argument order is chosen to be more efficient. + +token(S0, Ics0, L0, Tcs, Tlen0, Tline, A0, Alen0) -> + case yystate(S0, Ics0, L0, Tlen0, A0, Alen0) of + %% Accepting end state, we have a token. + {A1,Alen1,Ics1,L1} -> + token_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline)); + %% Accepting transition state, can take more chars. + {A1,Alen1,[],L1,S1} -> % Need more chars to check + {more,{token,S1,L1,Tcs,Alen1,Tline,A1,Alen1}}; + {A1,Alen1,Ics1,L1,_S1} -> % Take what we got + token_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline)); + %% After a non-accepting state, maybe reach accept state later. + {A1,Alen1,Tlen1,[],L1,S1} -> % Need more chars to check + {more,{token,S1,L1,Tcs,Tlen1,Tline,A1,Alen1}}; + {reject,_Alen1,Tlen1,eof,L1,_S1} -> % No token match + %% Check for partial token which is error. + Ret = if Tlen1 > 0 -> {error,{Tline,?MODULE, + %% Skip eof tail in Tcs. + {illegal,yypre(Tcs, Tlen1)}},L1}; + true -> {eof,L1} + end, + {done,Ret,eof}; + {reject,_Alen1,Tlen1,Ics1,L1,_S1} -> % No token match + Error = {Tline,?MODULE,{illegal,yypre(Tcs, Tlen1+1)}}, + {done,{error,Error,L1},Ics1}; + {A1,Alen1,_Tlen1,_Ics1,_L1,_S1} -> % Use last accept match + token_cont(yysuf(Tcs, Alen1), L0, yyaction(A1, Alen1, Tcs, Tline)) + end. + +%% token_cont(RestChars, Line, Token) +%% If we have a token or error then return done, else if we have a +%% skip_token then continue. + +-dialyzer({nowarn_function, token_cont/3}). + +token_cont(Rest, Line, {token,T}) -> + {done,{ok,T,Line},Rest}; +token_cont(Rest, Line, {token,T,Push}) -> + NewRest = Push ++ Rest, + {done,{ok,T,Line},NewRest}; +token_cont(Rest, Line, {end_token,T}) -> + {done,{ok,T,Line},Rest}; +token_cont(Rest, Line, {end_token,T,Push}) -> + NewRest = Push ++ Rest, + {done,{ok,T,Line},NewRest}; +token_cont(Rest, Line, skip_token) -> + token(yystate(), Rest, Line, Rest, 0, Line, reject, 0); +token_cont(Rest, Line, {skip_token,Push}) -> + NewRest = Push ++ Rest, + token(yystate(), NewRest, Line, NewRest, 0, Line, reject, 0); +token_cont(Rest, Line, {error,S}) -> + {done,{error,{Line,?MODULE,{user,S}},Line},Rest}. + +%% tokens(Continuation, Chars, Line) -> +%% {more,Continuation} | {done,ReturnVal,RestChars}. +%% Must be careful when re-entering to append the latest characters to the +%% after characters in an accept. The continuation is: +%% {tokens,State,CurrLine,TokenChars,TokenLen,TokenLine,Tokens,AccAction,AccLen} +%% {skip_tokens,State,CurrLine,TokenChars,TokenLen,TokenLine,Error,AccAction,AccLen} + +tokens(Cont, Chars) -> tokens(Cont, Chars, 1). + +tokens([], Chars, Line) -> + tokens(yystate(), Chars, Line, Chars, 0, Line, [], reject, 0); +tokens({tokens,State,Line,Tcs,Tlen,Tline,Ts,Action,Alen}, Chars, _) -> + tokens(State, Chars, Line, Tcs ++ Chars, Tlen, Tline, Ts, Action, Alen); +tokens({skip_tokens,State,Line,Tcs,Tlen,Tline,Error,Action,Alen}, Chars, _) -> + skip_tokens(State, Chars, Line, Tcs ++ Chars, Tlen, Tline, Error, Action, Alen). + +%% tokens(State, InChars, Line, TokenChars, TokenLen, TokenLine, Tokens, +%% AcceptAction, AcceptLen) -> +%% {more,Continuation} | {done,ReturnVal,RestChars}. + +tokens(S0, Ics0, L0, Tcs, Tlen0, Tline, Ts, A0, Alen0) -> + case yystate(S0, Ics0, L0, Tlen0, A0, Alen0) of + %% Accepting end state, we have a token. + {A1,Alen1,Ics1,L1} -> + tokens_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline), Ts); + %% Accepting transition state, can take more chars. + {A1,Alen1,[],L1,S1} -> % Need more chars to check + {more,{tokens,S1,L1,Tcs,Alen1,Tline,Ts,A1,Alen1}}; + {A1,Alen1,Ics1,L1,_S1} -> % Take what we got + tokens_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline), Ts); + %% After a non-accepting state, maybe reach accept state later. + {A1,Alen1,Tlen1,[],L1,S1} -> % Need more chars to check + {more,{tokens,S1,L1,Tcs,Tlen1,Tline,Ts,A1,Alen1}}; + {reject,_Alen1,Tlen1,eof,L1,_S1} -> % No token match + %% Check for partial token which is error, no need to skip here. + Ret = if Tlen1 > 0 -> {error,{Tline,?MODULE, + %% Skip eof tail in Tcs. + {illegal,yypre(Tcs, Tlen1)}},L1}; + Ts == [] -> {eof,L1}; + true -> {ok,yyrev(Ts),L1} + end, + {done,Ret,eof}; + {reject,_Alen1,Tlen1,_Ics1,L1,_S1} -> + %% Skip rest of tokens. + Error = {L1,?MODULE,{illegal,yypre(Tcs, Tlen1+1)}}, + skip_tokens(yysuf(Tcs, Tlen1+1), L1, Error); + {A1,Alen1,_Tlen1,_Ics1,_L1,_S1} -> + Token = yyaction(A1, Alen1, Tcs, Tline), + tokens_cont(yysuf(Tcs, Alen1), L0, Token, Ts) + end. + +%% tokens_cont(RestChars, Line, Token, Tokens) +%% If we have an end_token or error then return done, else if we have +%% a token then save it and continue, else if we have a skip_token +%% just continue. + +-dialyzer({nowarn_function, tokens_cont/4}). + +tokens_cont(Rest, Line, {token,T}, Ts) -> + tokens(yystate(), Rest, Line, Rest, 0, Line, [T|Ts], reject, 0); +tokens_cont(Rest, Line, {token,T,Push}, Ts) -> + NewRest = Push ++ Rest, + tokens(yystate(), NewRest, Line, NewRest, 0, Line, [T|Ts], reject, 0); +tokens_cont(Rest, Line, {end_token,T}, Ts) -> + {done,{ok,yyrev(Ts, [T]),Line},Rest}; +tokens_cont(Rest, Line, {end_token,T,Push}, Ts) -> + NewRest = Push ++ Rest, + {done,{ok,yyrev(Ts, [T]),Line},NewRest}; +tokens_cont(Rest, Line, skip_token, Ts) -> + tokens(yystate(), Rest, Line, Rest, 0, Line, Ts, reject, 0); +tokens_cont(Rest, Line, {skip_token,Push}, Ts) -> + NewRest = Push ++ Rest, + tokens(yystate(), NewRest, Line, NewRest, 0, Line, Ts, reject, 0); +tokens_cont(Rest, Line, {error,S}, _Ts) -> + skip_tokens(Rest, Line, {Line,?MODULE,{user,S}}). + +%%skip_tokens(InChars, Line, Error) -> {done,{error,Error,Line},Ics}. +%% Skip tokens until an end token, junk everything and return the error. + +skip_tokens(Ics, Line, Error) -> + skip_tokens(yystate(), Ics, Line, Ics, 0, Line, Error, reject, 0). + +%% skip_tokens(State, InChars, Line, TokenChars, TokenLen, TokenLine, Tokens, +%% AcceptAction, AcceptLen) -> +%% {more,Continuation} | {done,ReturnVal,RestChars}. + +skip_tokens(S0, Ics0, L0, Tcs, Tlen0, Tline, Error, A0, Alen0) -> + case yystate(S0, Ics0, L0, Tlen0, A0, Alen0) of + {A1,Alen1,Ics1,L1} -> % Accepting end state + skip_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline), Error); + {A1,Alen1,[],L1,S1} -> % After an accepting state + {more,{skip_tokens,S1,L1,Tcs,Alen1,Tline,Error,A1,Alen1}}; + {A1,Alen1,Ics1,L1,_S1} -> + skip_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline), Error); + {A1,Alen1,Tlen1,[],L1,S1} -> % After a non-accepting state + {more,{skip_tokens,S1,L1,Tcs,Tlen1,Tline,Error,A1,Alen1}}; + {reject,_Alen1,_Tlen1,eof,L1,_S1} -> + {done,{error,Error,L1},eof}; + {reject,_Alen1,Tlen1,_Ics1,L1,_S1} -> + skip_tokens(yysuf(Tcs, Tlen1+1), L1, Error); + {A1,Alen1,_Tlen1,_Ics1,L1,_S1} -> + Token = yyaction(A1, Alen1, Tcs, Tline), + skip_cont(yysuf(Tcs, Alen1), L1, Token, Error) + end. + +%% skip_cont(RestChars, Line, Token, Error) +%% Skip tokens until we have an end_token or error then return done +%% with the original rror. + +-dialyzer({nowarn_function, skip_cont/4}). + +skip_cont(Rest, Line, {token,_T}, Error) -> + skip_tokens(yystate(), Rest, Line, Rest, 0, Line, Error, reject, 0); +skip_cont(Rest, Line, {token,_T,Push}, Error) -> + NewRest = Push ++ Rest, + skip_tokens(yystate(), NewRest, Line, NewRest, 0, Line, Error, reject, 0); +skip_cont(Rest, Line, {end_token,_T}, Error) -> + {done,{error,Error,Line},Rest}; +skip_cont(Rest, Line, {end_token,_T,Push}, Error) -> + NewRest = Push ++ Rest, + {done,{error,Error,Line},NewRest}; +skip_cont(Rest, Line, skip_token, Error) -> + skip_tokens(yystate(), Rest, Line, Rest, 0, Line, Error, reject, 0); +skip_cont(Rest, Line, {skip_token,Push}, Error) -> + NewRest = Push ++ Rest, + skip_tokens(yystate(), NewRest, Line, NewRest, 0, Line, Error, reject, 0); +skip_cont(Rest, Line, {error,_S}, Error) -> + skip_tokens(yystate(), Rest, Line, Rest, 0, Line, Error, reject, 0). + +yyrev(List) -> lists:reverse(List). +yyrev(List, Tail) -> lists:reverse(List, Tail). +yypre(List, N) -> lists:sublist(List, N). +yysuf(List, N) -> lists:nthtail(N, List). + +%% yystate() -> InitialState. +%% yystate(State, InChars, Line, CurrTokLen, AcceptAction, AcceptLen) -> +%% {Action, AcceptLen, RestChars, Line} | +%% {Action, AcceptLen, RestChars, Line, State} | +%% {reject, AcceptLen, CurrTokLen, RestChars, Line, State} | +%% {Action, AcceptLen, CurrTokLen, RestChars, Line, State}. +%% Generated state transition functions. The non-accepting end state +%% return signal either an unrecognised character or end of current +%% input. + +-file("src/ntriples_lexer.erl", 288). +yystate() -> 26. + +yystate(36, [8255|Ics], Line, Tlen, _, _) -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [8256|Ics], Line, Tlen, _, _) -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [8204|Ics], Line, Tlen, _, _) -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [8205|Ics], Line, Tlen, _, _) -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [183|Ics], Line, Tlen, _, _) -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [95|Ics], Line, Tlen, _, _) -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [58|Ics], Line, Tlen, _, _) -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [46|Ics], Line, Tlen, _, _) -> + yystate(25, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [45|Ics], Line, Tlen, _, _) -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 48, C =< 57 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 65, C =< 90 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 97, C =< 122 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 192, C =< 214 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 216, C =< 246 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 248, C =< 767 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 768, C =< 879 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 880, C =< 893 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 895, C =< 8191 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 8304, C =< 8591 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 11264, C =< 12271 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 12289, C =< 55295 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 63744, C =< 64975 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 65008, C =< 65533 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, [C|Ics], Line, Tlen, _, _) when C >= 65536, C =< 983039 -> + yystate(36, Ics, Line, Tlen+1, 3, Tlen); +yystate(36, Ics, Line, Tlen, _, _) -> + {3,Tlen,Ics,Line,36}; +yystate(35, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 90 -> + yystate(0, Ics, Line, Tlen+1, Action, Alen); +yystate(35, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 122 -> + yystate(0, Ics, Line, Tlen+1, Action, Alen); +yystate(35, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,35}; +yystate(34, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(28, Ics, Line, Tlen+1, Action, Alen); +yystate(34, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(28, Ics, Line, Tlen+1, Action, Alen); +yystate(34, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(28, Ics, Line, Tlen+1, Action, Alen); +yystate(34, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,34}; +yystate(33, [11|Ics], Line, Tlen, _, _) -> + yystate(33, Ics, Line, Tlen+1, 8, Tlen); +yystate(33, [12|Ics], Line, Tlen, _, _) -> + yystate(33, Ics, Line, Tlen+1, 8, Tlen); +yystate(33, [C|Ics], Line, Tlen, _, _) when C >= 0, C =< 9 -> + yystate(33, Ics, Line, Tlen+1, 8, Tlen); +yystate(33, [C|Ics], Line, Tlen, _, _) when C >= 14 -> + yystate(33, Ics, Line, Tlen+1, 8, Tlen); +yystate(33, Ics, Line, Tlen, _, _) -> + {8,Tlen,Ics,Line,33}; +yystate(32, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(10, Ics, Line, Tlen+1, Action, Alen); +yystate(32, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(10, Ics, Line, Tlen+1, Action, Alen); +yystate(32, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(10, Ics, Line, Tlen+1, Action, Alen); +yystate(32, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,32}; +yystate(31, [92|Ics], Line, Tlen, Action, Alen) -> + yystate(1, Ics, Line, Tlen+1, Action, Alen); +yystate(31, [34|Ics], Line, Tlen, Action, Alen) -> + yystate(8, Ics, Line, Tlen+1, Action, Alen); +yystate(31, [11|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(31, [12|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(31, [C|Ics], Line, Tlen, Action, Alen) when C >= 0, C =< 9 -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(31, [C|Ics], Line, Tlen, Action, Alen) when C >= 14, C =< 33 -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(31, [C|Ics], Line, Tlen, Action, Alen) when C >= 35, C =< 91 -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(31, [C|Ics], Line, Tlen, Action, Alen) when C >= 93 -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(31, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,31}; +yystate(30, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(3, Ics, Line, Tlen+1, Action, Alen); +yystate(30, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(3, Ics, Line, Tlen+1, Action, Alen); +yystate(30, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(3, Ics, Line, Tlen+1, Action, Alen); +yystate(30, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,30}; +yystate(29, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(6, Ics, Line, Tlen+1, Action, Alen); +yystate(29, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(6, Ics, Line, Tlen+1, Action, Alen); +yystate(29, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(6, Ics, Line, Tlen+1, Action, Alen); +yystate(29, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,29}; +yystate(28, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(19, Ics, Line, Tlen+1, Action, Alen); +yystate(28, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(19, Ics, Line, Tlen+1, Action, Alen); +yystate(28, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(19, Ics, Line, Tlen+1, Action, Alen); +yystate(28, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,28}; +yystate(27, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(15, Ics, Line, Tlen+1, Action, Alen); +yystate(27, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(15, Ics, Line, Tlen+1, Action, Alen); +yystate(27, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(15, Ics, Line, Tlen+1, Action, Alen); +yystate(27, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,27}; +yystate(26, [95|Ics], Line, Tlen, Action, Alen) -> + yystate(7, Ics, Line, Tlen+1, Action, Alen); +yystate(26, [94|Ics], Line, Tlen, Action, Alen) -> + yystate(14, Ics, Line, Tlen+1, Action, Alen); +yystate(26, [64|Ics], Line, Tlen, Action, Alen) -> + yystate(35, Ics, Line, Tlen+1, Action, Alen); +yystate(26, [60|Ics], Line, Tlen, Action, Alen) -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(26, [46|Ics], Line, Tlen, Action, Alen) -> + yystate(22, Ics, Line, Tlen+1, Action, Alen); +yystate(26, [35|Ics], Line, Tlen, Action, Alen) -> + yystate(33, Ics, Line, Tlen+1, Action, Alen); +yystate(26, [34|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(26, [32|Ics], Line, Tlen, Action, Alen) -> + yystate(5, Ics, Line, Tlen+1, Action, Alen); +yystate(26, [13|Ics], Line, Tlen, Action, Alen) -> + yystate(20, Ics, Line, Tlen+1, Action, Alen); +yystate(26, [10|Ics], Line, Tlen, Action, Alen) -> + yystate(20, Ics, Line+1, Tlen+1, Action, Alen); +yystate(26, [9|Ics], Line, Tlen, Action, Alen) -> + yystate(5, Ics, Line, Tlen+1, Action, Alen); +yystate(26, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,26}; +yystate(25, [8255|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [8256|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [8204|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [8205|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [183|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [95|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [58|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [46|Ics], Line, Tlen, Action, Alen) -> + yystate(25, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [45|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 90 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 122 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 192, C =< 214 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 216, C =< 246 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 248, C =< 767 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 768, C =< 879 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 880, C =< 893 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 895, C =< 8191 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 8304, C =< 8591 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 11264, C =< 12271 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 12289, C =< 55295 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 63744, C =< 64975 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 65008, C =< 65533 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, [C|Ics], Line, Tlen, Action, Alen) when C >= 65536, C =< 983039 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(25, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,25}; +yystate(24, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(27, Ics, Line, Tlen+1, Action, Alen); +yystate(24, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(27, Ics, Line, Tlen+1, Action, Alen); +yystate(24, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(27, Ics, Line, Tlen+1, Action, Alen); +yystate(24, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,24}; +yystate(23, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(32, Ics, Line, Tlen+1, Action, Alen); +yystate(23, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(32, Ics, Line, Tlen+1, Action, Alen); +yystate(23, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(32, Ics, Line, Tlen+1, Action, Alen); +yystate(23, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,23}; +yystate(22, Ics, Line, Tlen, _, _) -> + {5,Tlen,Ics,Line}; +yystate(21, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(21, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(21, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(21, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,21}; +yystate(20, [13|Ics], Line, Tlen, _, _) -> + yystate(20, Ics, Line, Tlen+1, 4, Tlen); +yystate(20, [10|Ics], Line, Tlen, _, _) -> + yystate(20, Ics, Line+1, Tlen+1, 4, Tlen); +yystate(20, Ics, Line, Tlen, _, _) -> + {4,Tlen,Ics,Line,20}; +yystate(19, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(19, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(19, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(19, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,19}; +yystate(18, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(13, Ics, Line, Tlen+1, Action, Alen); +yystate(18, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 90 -> + yystate(13, Ics, Line, Tlen+1, Action, Alen); +yystate(18, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 122 -> + yystate(13, Ics, Line, Tlen+1, Action, Alen); +yystate(18, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,18}; +yystate(17, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(30, Ics, Line, Tlen+1, Action, Alen); +yystate(17, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(30, Ics, Line, Tlen+1, Action, Alen); +yystate(17, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(30, Ics, Line, Tlen+1, Action, Alen); +yystate(17, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,17}; +yystate(16, Ics, Line, Tlen, _, _) -> + {6,Tlen,Ics,Line}; +yystate(15, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(23, Ics, Line, Tlen+1, Action, Alen); +yystate(15, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(23, Ics, Line, Tlen+1, Action, Alen); +yystate(15, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(23, Ics, Line, Tlen+1, Action, Alen); +yystate(15, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,15}; +yystate(14, [94|Ics], Line, Tlen, Action, Alen) -> + yystate(16, Ics, Line, Tlen+1, Action, Alen); +yystate(14, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,14}; +yystate(13, [45|Ics], Line, Tlen, _, _) -> + yystate(18, Ics, Line, Tlen+1, 0, Tlen); +yystate(13, [C|Ics], Line, Tlen, _, _) when C >= 48, C =< 57 -> + yystate(13, Ics, Line, Tlen+1, 0, Tlen); +yystate(13, [C|Ics], Line, Tlen, _, _) when C >= 65, C =< 90 -> + yystate(13, Ics, Line, Tlen+1, 0, Tlen); +yystate(13, [C|Ics], Line, Tlen, _, _) when C >= 97, C =< 122 -> + yystate(13, Ics, Line, Tlen+1, 0, Tlen); +yystate(13, Ics, Line, Tlen, _, _) -> + {0,Tlen,Ics,Line,13}; +yystate(12, [117|Ics], Line, Tlen, Action, Alen) -> + yystate(23, Ics, Line, Tlen+1, Action, Alen); +yystate(12, [85|Ics], Line, Tlen, Action, Alen) -> + yystate(9, Ics, Line, Tlen+1, Action, Alen); +yystate(12, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,12}; +yystate(11, [8204|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [8205|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [95|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [58|Ics], Line, Tlen, Action, Alen) -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 90 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 122 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 192, C =< 214 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 216, C =< 246 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 248, C =< 767 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 880, C =< 893 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 895, C =< 8191 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 8304, C =< 8591 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 11264, C =< 12271 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 12289, C =< 55295 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 63744, C =< 64975 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 65008, C =< 65533 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, [C|Ics], Line, Tlen, Action, Alen) when C >= 65536, C =< 983039 -> + yystate(36, Ics, Line, Tlen+1, Action, Alen); +yystate(11, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,11}; +yystate(10, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(21, Ics, Line, Tlen+1, Action, Alen); +yystate(10, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(21, Ics, Line, Tlen+1, Action, Alen); +yystate(10, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(21, Ics, Line, Tlen+1, Action, Alen); +yystate(10, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,10}; +yystate(9, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(24, Ics, Line, Tlen+1, Action, Alen); +yystate(9, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(24, Ics, Line, Tlen+1, Action, Alen); +yystate(9, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(24, Ics, Line, Tlen+1, Action, Alen); +yystate(9, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,9}; +yystate(8, Ics, Line, Tlen, _, _) -> + {2,Tlen,Ics,Line}; +yystate(7, [58|Ics], Line, Tlen, Action, Alen) -> + yystate(11, Ics, Line, Tlen+1, Action, Alen); +yystate(7, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,7}; +yystate(6, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(17, Ics, Line, Tlen+1, Action, Alen); +yystate(6, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(17, Ics, Line, Tlen+1, Action, Alen); +yystate(6, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(17, Ics, Line, Tlen+1, Action, Alen); +yystate(6, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,6}; +yystate(5, [32|Ics], Line, Tlen, _, _) -> + yystate(5, Ics, Line, Tlen+1, 7, Tlen); +yystate(5, [9|Ics], Line, Tlen, _, _) -> + yystate(5, Ics, Line, Tlen+1, 7, Tlen); +yystate(5, Ics, Line, Tlen, _, _) -> + {7,Tlen,Ics,Line,5}; +yystate(4, Ics, Line, Tlen, _, _) -> + {1,Tlen,Ics,Line}; +yystate(3, [C|Ics], Line, Tlen, Action, Alen) when C >= 48, C =< 57 -> + yystate(34, Ics, Line, Tlen+1, Action, Alen); +yystate(3, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 70 -> + yystate(34, Ics, Line, Tlen+1, Action, Alen); +yystate(3, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 102 -> + yystate(34, Ics, Line, Tlen+1, Action, Alen); +yystate(3, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,3}; +yystate(2, [95|Ics], Line, Tlen, Action, Alen) -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(2, [93|Ics], Line, Tlen, Action, Alen) -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(2, [92|Ics], Line, Tlen, Action, Alen) -> + yystate(12, Ics, Line, Tlen+1, Action, Alen); +yystate(2, [62|Ics], Line, Tlen, Action, Alen) -> + yystate(4, Ics, Line, Tlen+1, Action, Alen); +yystate(2, [61|Ics], Line, Tlen, Action, Alen) -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(2, [33|Ics], Line, Tlen, Action, Alen) -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(2, [C|Ics], Line, Tlen, Action, Alen) when C >= 35, C =< 59 -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(2, [C|Ics], Line, Tlen, Action, Alen) when C >= 63, C =< 91 -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(2, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 122 -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(2, [C|Ics], Line, Tlen, Action, Alen) when C >= 126 -> + yystate(2, Ics, Line, Tlen+1, Action, Alen); +yystate(2, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,2}; +yystate(1, [117|Ics], Line, Tlen, Action, Alen) -> + yystate(3, Ics, Line, Tlen+1, Action, Alen); +yystate(1, [116|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(1, [114|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(1, [110|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(1, [102|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(1, [98|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(1, [92|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(1, [85|Ics], Line, Tlen, Action, Alen) -> + yystate(29, Ics, Line, Tlen+1, Action, Alen); +yystate(1, [39|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(1, [34|Ics], Line, Tlen, Action, Alen) -> + yystate(31, Ics, Line, Tlen+1, Action, Alen); +yystate(1, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,1}; +yystate(0, [45|Ics], Line, Tlen, _, _) -> + yystate(18, Ics, Line, Tlen+1, 0, Tlen); +yystate(0, [C|Ics], Line, Tlen, _, _) when C >= 65, C =< 90 -> + yystate(0, Ics, Line, Tlen+1, 0, Tlen); +yystate(0, [C|Ics], Line, Tlen, _, _) when C >= 97, C =< 122 -> + yystate(0, Ics, Line, Tlen+1, 0, Tlen); +yystate(0, Ics, Line, Tlen, _, _) -> + {0,Tlen,Ics,Line,0}; +yystate(S, Ics, Line, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,S}. + +%% yyaction(Action, TokenLength, TokenChars, TokenLine) -> +%% {token,Token} | {end_token, Token} | skip_token | {error,String}. +%% Generated action function. + +yyaction(0, TokenLen, YYtcs, TokenLine) -> + TokenChars = yypre(YYtcs, TokenLen), + yyaction_0(TokenChars, TokenLine); +yyaction(1, TokenLen, YYtcs, TokenLine) -> + TokenChars = yypre(YYtcs, TokenLen), + yyaction_1(TokenChars, TokenLine); +yyaction(2, TokenLen, YYtcs, TokenLine) -> + TokenChars = yypre(YYtcs, TokenLen), + yyaction_2(TokenChars, TokenLine); +yyaction(3, TokenLen, YYtcs, TokenLine) -> + TokenChars = yypre(YYtcs, TokenLen), + yyaction_3(TokenChars, TokenLine); +yyaction(4, _, _, TokenLine) -> + yyaction_4(TokenLine); +yyaction(5, _, _, TokenLine) -> + yyaction_5(TokenLine); +yyaction(6, _, _, TokenLine) -> + yyaction_6(TokenLine); +yyaction(7, _, _, _) -> + yyaction_7(); +yyaction(8, _, _, _) -> + yyaction_8(); +yyaction(_, _, _, _) -> error. + +-compile({inline,yyaction_0/2}). +-file("src/ntriples_lexer.xrl", 18). +yyaction_0(TokenChars, TokenLine) -> + { token, { langtag, TokenLine, langtag_str (TokenChars) } } . + +-compile({inline,yyaction_1/2}). +-file("src/ntriples_lexer.xrl", 19). +yyaction_1(TokenChars, TokenLine) -> + { token, { iriref, TokenLine, quoted_content_str (TokenChars) } } . + +-compile({inline,yyaction_2/2}). +-file("src/ntriples_lexer.xrl", 20). +yyaction_2(TokenChars, TokenLine) -> + { token, { string_literal_quote, TokenLine, quoted_content_str (TokenChars) } } . + +-compile({inline,yyaction_3/2}). +-file("src/ntriples_lexer.xrl", 21). +yyaction_3(TokenChars, TokenLine) -> + { token, { blank_node_label, TokenLine, bnode_str (TokenChars) } } . + +-compile({inline,yyaction_4/1}). +-file("src/ntriples_lexer.xrl", 22). +yyaction_4(TokenLine) -> + { token, { eol, TokenLine } } . + +-compile({inline,yyaction_5/1}). +-file("src/ntriples_lexer.xrl", 23). +yyaction_5(TokenLine) -> + { token, { '.', TokenLine } } . + +-compile({inline,yyaction_6/1}). +-file("src/ntriples_lexer.xrl", 24). +yyaction_6(TokenLine) -> + { token, { '^^', TokenLine } } . + +-compile({inline,yyaction_7/0}). +-file("src/ntriples_lexer.xrl", 25). +yyaction_7() -> + skip_token . + +-compile({inline,yyaction_8/0}). +-file("src/ntriples_lexer.xrl", 26). +yyaction_8() -> + skip_token . + +-file("/usr/local/Cellar/erlang/19.1/lib/erlang/lib/parsetools-2.1.3/include/leexinc.hrl", 290). diff --git a/src/ntriples_lexer.xrl b/src/ntriples_lexer.xrl new file mode 100644 index 0000000..aafdad9 --- /dev/null +++ b/src/ntriples_lexer.xrl @@ -0,0 +1,35 @@ +Definitions. + +WHITESPACE = [\s\t] +COMMENT = #[^\n\r]* +EOL = [\n\r]+ +HEX = [0-9]|[A-F]|[a-f] +UCHAR = (\\u({HEX})({HEX})({HEX})({HEX}))|(\\U({HEX})({HEX})({HEX})({HEX})({HEX})({HEX})({HEX})({HEX})) +ECHAR = \\[tbnrf"'\\] +PN_CHARS_BASE = [A-Z]|[a-z]|[\x{00C0}-\x{00D6}]|[\x{00D8}-\x{00F6}]|[\x{00F8}-\x{02FF}]|[\x{0370}-\x{037D}]|[\x{037F}-\x{1FFF}]|[\x{200C}-\x{200D}]|[\x{2070}-\x{218F}]|[\x{2C00}-\x{2FEF}]|[\x{3001}-\x{D7FF}]|[\x{F900}-\x{FDCF}]|[\x{FDF0}-\x{FFFD}]|[\x{10000}-\x{EFFFF}] +PN_CHARS_U = {PN_CHARS_BASE}|_|: +PN_CHARS = {PN_CHARS_U}|-|[0-9]|\x{00B7}|[\x{0300}-\x{036F}]|[\x{203F}-\x{2040}] +IRIREF = <([^\x00-\x20<>"{}|^`\\]|{UCHAR})*> +STRING_LITERAL_QUOTE = "([^\x22\x5C\x0A\x0D]|{ECHAR}|{UCHAR})*" +BLANK_NODE_LABEL = _:({PN_CHARS_U}|[0-9])(({PN_CHARS}|\.)*({PN_CHARS}))? +LANGTAG = @[a-zA-Z]+(-[a-zA-Z0-9]+)* + + +Rules. + +{LANGTAG} : {token, {langtag, TokenLine, langtag_str(TokenChars)}}. +{IRIREF} : {token, {iriref, TokenLine, quoted_content_str(TokenChars)}}. +{STRING_LITERAL_QUOTE} : {token, {string_literal_quote, TokenLine, quoted_content_str(TokenChars)}}. +{BLANK_NODE_LABEL} : {token, {blank_node_label, TokenLine, bnode_str(TokenChars)}}. +{EOL} : {token, {eol, TokenLine}}. +\. : {token, {'.', TokenLine}}. +\^\^ : {token, {'^^', TokenLine}}. +{WHITESPACE}+ : skip_token. +{COMMENT} : skip_token. + + +Erlang code. + +quoted_content_str(TokenChars) -> 'Elixir.RDF.Reader.ParseHelper':quoted_content_str(TokenChars). +bnode_str(TokenChars) -> 'Elixir.RDF.Reader.ParseHelper':bnode_str(TokenChars). +langtag_str(TokenChars) -> 'Elixir.RDF.Reader.ParseHelper':langtag_str(TokenChars). diff --git a/src/ntriples_parser.erl b/src/ntriples_parser.erl new file mode 100644 index 0000000..7864bc1 --- /dev/null +++ b/src/ntriples_parser.erl @@ -0,0 +1,573 @@ +-module(ntriples_parser). +-export([parse/1, parse_and_scan/1, format_error/1]). +-file("src/ntriples_parser.yrl", 37). + +to_uri(IRIREF) -> + case 'Elixir.RDF.Reader.ParseHelper':to_uri(IRIREF) of + {ok, URI} -> URI; + {error, ErrorLine, Message} -> return_error(ErrorLine, Message) + end. +to_bnode(BLANK_NODE_LABEL) -> 'Elixir.RDF.Reader.ParseHelper':to_bnode(BLANK_NODE_LABEL). +to_literal(STRING_LITERAL_QUOTE) -> 'Elixir.RDF.Reader.ParseHelper':to_literal(STRING_LITERAL_QUOTE). +to_literal(STRING_LITERAL_QUOTE, Type) -> 'Elixir.RDF.Reader.ParseHelper':to_literal(STRING_LITERAL_QUOTE, Type). +to_langtag(LANGTAG) -> 'Elixir.RDF.Reader.ParseHelper':to_langtag(LANGTAG). + +-file("/usr/local/Cellar/erlang/19.1/lib/erlang/lib/parsetools-2.1.3/include/yeccpre.hrl", 0). +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 1996-2015. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% The parser generator will insert appropriate declarations before this line.% + +-type yecc_ret() :: {'error', _} | {'ok', _}. + +-spec parse(Tokens :: list()) -> yecc_ret(). +parse(Tokens) -> + yeccpars0(Tokens, {no_func, no_line}, 0, [], []). + +-spec parse_and_scan({function() | {atom(), atom()}, [_]} + | {atom(), atom(), [_]}) -> yecc_ret(). +parse_and_scan({F, A}) -> + yeccpars0([], {{F, A}, no_line}, 0, [], []); +parse_and_scan({M, F, A}) -> + Arity = length(A), + yeccpars0([], {{fun M:F/Arity, A}, no_line}, 0, [], []). + +-spec format_error(any()) -> [char() | list()]. +format_error(Message) -> + case io_lib:deep_char_list(Message) of + true -> + Message; + _ -> + io_lib:write(Message) + end. + +%% To be used in grammar files to throw an error message to the parser +%% toplevel. Doesn't have to be exported! +-compile({nowarn_unused_function, return_error/2}). +-spec return_error(integer(), any()) -> no_return(). +return_error(Line, Message) -> + throw({error, {Line, ?MODULE, Message}}). + +-define(CODE_VERSION, "1.4"). + +yeccpars0(Tokens, Tzr, State, States, Vstack) -> + try yeccpars1(Tokens, Tzr, State, States, Vstack) + catch + error: Error -> + Stacktrace = erlang:get_stacktrace(), + try yecc_error_type(Error, Stacktrace) of + Desc -> + erlang:raise(error, {yecc_bug, ?CODE_VERSION, Desc}, + Stacktrace) + catch _:_ -> erlang:raise(error, Error, Stacktrace) + end; + %% Probably thrown from return_error/2: + throw: {error, {_Line, ?MODULE, _M}} = Error -> + Error + end. + +yecc_error_type(function_clause, [{?MODULE,F,ArityOrArgs,_} | _]) -> + case atom_to_list(F) of + "yeccgoto_" ++ SymbolL -> + {ok,[{atom,_,Symbol}],_} = erl_scan:string(SymbolL), + State = case ArityOrArgs of + [S,_,_,_,_,_,_] -> S; + _ -> state_is_unknown + end, + {Symbol, State, missing_in_goto_table} + end. + +yeccpars1([Token | Tokens], Tzr, State, States, Vstack) -> + yeccpars2(State, element(1, Token), States, Vstack, Token, Tokens, Tzr); +yeccpars1([], {{F, A},_Line}, State, States, Vstack) -> + case apply(F, A) of + {ok, Tokens, Endline} -> + yeccpars1(Tokens, {{F, A}, Endline}, State, States, Vstack); + {eof, Endline} -> + yeccpars1([], {no_func, Endline}, State, States, Vstack); + {error, Descriptor, _Endline} -> + {error, Descriptor} + end; +yeccpars1([], {no_func, no_line}, State, States, Vstack) -> + Line = 999999, + yeccpars2(State, '$end', States, Vstack, yecc_end(Line), [], + {no_func, Line}); +yeccpars1([], {no_func, Endline}, State, States, Vstack) -> + yeccpars2(State, '$end', States, Vstack, yecc_end(Endline), [], + {no_func, Endline}). + +%% yeccpars1/7 is called from generated code. +%% +%% When using the {includefile, Includefile} option, make sure that +%% yeccpars1/7 can be found by parsing the file without following +%% include directives. yecc will otherwise assume that an old +%% yeccpre.hrl is included (one which defines yeccpars1/5). +yeccpars1(State1, State, States, Vstack, Token0, [Token | Tokens], Tzr) -> + yeccpars2(State, element(1, Token), [State1 | States], + [Token0 | Vstack], Token, Tokens, Tzr); +yeccpars1(State1, State, States, Vstack, Token0, [], {{_F,_A}, _Line}=Tzr) -> + yeccpars1([], Tzr, State, [State1 | States], [Token0 | Vstack]); +yeccpars1(State1, State, States, Vstack, Token0, [], {no_func, no_line}) -> + Line = yecctoken_end_location(Token0), + yeccpars2(State, '$end', [State1 | States], [Token0 | Vstack], + yecc_end(Line), [], {no_func, Line}); +yeccpars1(State1, State, States, Vstack, Token0, [], {no_func, Line}) -> + yeccpars2(State, '$end', [State1 | States], [Token0 | Vstack], + yecc_end(Line), [], {no_func, Line}). + +%% For internal use only. +yecc_end({Line,_Column}) -> + {'$end', Line}; +yecc_end(Line) -> + {'$end', Line}. + +yecctoken_end_location(Token) -> + try erl_anno:end_location(element(2, Token)) of + undefined -> yecctoken_location(Token); + Loc -> Loc + catch _:_ -> yecctoken_location(Token) + end. + +-compile({nowarn_unused_function, yeccerror/1}). +yeccerror(Token) -> + Text = yecctoken_to_string(Token), + Location = yecctoken_location(Token), + {error, {Location, ?MODULE, ["syntax error before: ", Text]}}. + +-compile({nowarn_unused_function, yecctoken_to_string/1}). +yecctoken_to_string(Token) -> + try erl_scan:text(Token) of + undefined -> yecctoken2string(Token); + Txt -> Txt + catch _:_ -> yecctoken2string(Token) + end. + +yecctoken_location(Token) -> + try erl_scan:location(Token) + catch _:_ -> element(2, Token) + end. + +-compile({nowarn_unused_function, yecctoken2string/1}). +yecctoken2string({atom, _, A}) -> io_lib:write(A); +yecctoken2string({integer,_,N}) -> io_lib:write(N); +yecctoken2string({float,_,F}) -> io_lib:write(F); +yecctoken2string({char,_,C}) -> io_lib:write_char(C); +yecctoken2string({var,_,V}) -> io_lib:format("~s", [V]); +yecctoken2string({string,_,S}) -> io_lib:write_string(S); +yecctoken2string({reserved_symbol, _, A}) -> io_lib:write(A); +yecctoken2string({_Cat, _, Val}) -> io_lib:format("~p",[Val]); +yecctoken2string({dot, _}) -> "'.'"; +yecctoken2string({'$end', _}) -> + []; +yecctoken2string({Other, _}) when is_atom(Other) -> + io_lib:write(Other); +yecctoken2string(Other) -> + io_lib:write(Other). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +-file("src/ntriples_parser.erl", 189). + +-dialyzer({nowarn_function, yeccpars2/7}). +yeccpars2(0=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_0(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(1=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_1(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(2=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_2(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(3=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_3(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(4=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_4(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(5=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_5(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(6=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_6(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(7=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_7(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(8=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_8(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(9=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_9(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(10=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_10(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(11=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_11(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(12=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_12(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(13=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_13(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(14=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_14(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(15=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_15(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(16=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_16(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(17=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_17(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(18=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_18(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(19=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_19(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(20=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_20(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(21=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_21(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(22=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_22(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(23=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_23(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(Other, _, _, _, _, _, _) -> + erlang:error({yecc_bug,"1.4",{missing_state_in_action_table, Other}}). + +yeccpars2_0(S, blank_node_label, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 6, Ss, Stack, T, Ts, Tzr); +yeccpars2_0(S, eol, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 7, Ss, Stack, T, Ts, Tzr); +yeccpars2_0(S, iriref, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 8, Ss, Stack, T, Ts, Tzr); +yeccpars2_0(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_0_(Stack), + yeccpars2_3(3, Cat, [0 | Ss], NewStack, T, Ts, Tzr). + +yeccpars2_1(S, eol, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 7, Ss, Stack, T, Ts, Tzr); +yeccpars2_1(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_1_(Stack), + yeccgoto_nonEmptyNtriplesDoc(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_2/7}). +yeccpars2_2(S, iriref, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 12, Ss, Stack, T, Ts, Tzr); +yeccpars2_2(_, _, _, _, T, _, _) -> + yeccerror(T). + +-dialyzer({nowarn_function, yeccpars2_3/7}). +yeccpars2_3(_S, '$end', _Ss, Stack, _T, _Ts, _Tzr) -> + {ok, hd(Stack)}; +yeccpars2_3(_, _, _, _, T, _, _) -> + yeccerror(T). + +yeccpars2_4(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_4_(Stack), + yeccgoto_ntriplesDoc(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +yeccpars2_5(S, blank_node_label, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 6, Ss, Stack, T, Ts, Tzr); +yeccpars2_5(S, eol, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 10, Ss, Stack, T, Ts, Tzr); +yeccpars2_5(S, iriref, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 8, Ss, Stack, T, Ts, Tzr); +yeccpars2_5(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_5_(Stack), + yeccgoto_ntriplesDoc(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +yeccpars2_6(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_6_(Stack), + yeccgoto_subject(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +yeccpars2_7(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_7_(Stack), + yeccgoto_eols(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +yeccpars2_8(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_8_(Stack), + yeccgoto_subject(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +yeccpars2_9(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_|Nss] = Ss, + NewStack = yeccpars2_9_(Stack), + yeccgoto_ntriplesDoc(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +yeccpars2_10(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_|Nss] = Ss, + NewStack = yeccpars2_10_(Stack), + yeccgoto_eols(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_11/7}). +yeccpars2_11(S, blank_node_label, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 15, Ss, Stack, T, Ts, Tzr); +yeccpars2_11(S, iriref, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 16, Ss, Stack, T, Ts, Tzr); +yeccpars2_11(S, string_literal_quote, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 17, Ss, Stack, T, Ts, Tzr); +yeccpars2_11(_, _, _, _, T, _, _) -> + yeccerror(T). + +yeccpars2_12(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_12_(Stack), + yeccgoto_predicate(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_13/7}). +yeccpars2_13(S, '.', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 21, Ss, Stack, T, Ts, Tzr); +yeccpars2_13(_, _, _, _, T, _, _) -> + yeccerror(T). + +yeccpars2_14(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccgoto_object(hd(Ss), Cat, Ss, Stack, T, Ts, Tzr). + +yeccpars2_15(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_15_(Stack), + yeccgoto_object(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +yeccpars2_16(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_16_(Stack), + yeccgoto_object(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +yeccpars2_17(S, '^^', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 18, Ss, Stack, T, Ts, Tzr); +yeccpars2_17(S, langtag, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 19, Ss, Stack, T, Ts, Tzr); +yeccpars2_17(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_17_(Stack), + yeccgoto_literal(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_18/7}). +yeccpars2_18(S, iriref, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 20, Ss, Stack, T, Ts, Tzr); +yeccpars2_18(_, _, _, _, T, _, _) -> + yeccerror(T). + +yeccpars2_19(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_|Nss] = Ss, + NewStack = yeccpars2_19_(Stack), + yeccgoto_literal(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +yeccpars2_20(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_,_|Nss] = Ss, + NewStack = yeccpars2_20_(Stack), + yeccgoto_literal(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +yeccpars2_21(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_,_,_|Nss] = Ss, + NewStack = yeccpars2_21_(Stack), + yeccgoto_triple(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +yeccpars2_22(S, blank_node_label, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 6, Ss, Stack, T, Ts, Tzr); +yeccpars2_22(S, eol, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 10, Ss, Stack, T, Ts, Tzr); +yeccpars2_22(S, iriref, Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 8, Ss, Stack, T, Ts, Tzr); +yeccpars2_22(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_|Nss] = Ss, + NewStack = yeccpars2_22_(Stack), + yeccgoto_nonEmptyNtriplesDoc(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +yeccpars2_23(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_,_|Nss] = Ss, + NewStack = yeccpars2_23_(Stack), + yeccgoto_nonEmptyNtriplesDoc(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_eols/7}). +yeccgoto_eols(0, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_5(5, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_eols(1, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_22(22, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_literal/7}). +yeccgoto_literal(11=_S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_14(_S, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_nonEmptyNtriplesDoc/7}). +yeccgoto_nonEmptyNtriplesDoc(0=_S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_4(_S, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_nonEmptyNtriplesDoc(5=_S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_9(_S, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_nonEmptyNtriplesDoc(22=_S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_23(_S, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_ntriplesDoc/7}). +yeccgoto_ntriplesDoc(0, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_3(3, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_object/7}). +yeccgoto_object(11, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_13(13, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_predicate/7}). +yeccgoto_predicate(2, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_11(11, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_subject/7}). +yeccgoto_subject(0, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_2(2, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_subject(5, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_2(2, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_subject(22, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_2(2, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_triple/7}). +yeccgoto_triple(0, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_1(1, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_triple(5, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_1(1, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_triple(22, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_1(1, Cat, Ss, Stack, T, Ts, Tzr). + +-compile({inline,yeccpars2_0_/1}). +-file("src/ntriples_parser.yrl", 9). +yeccpars2_0_(__Stack0) -> + [begin + [ ] + end | __Stack0]. + +-compile({inline,yeccpars2_1_/1}). +-file("src/ntriples_parser.yrl", 17). +yeccpars2_1_(__Stack0) -> + [__1 | __Stack] = __Stack0, + [begin + [ __1 ] + end | __Stack]. + +-compile({inline,yeccpars2_4_/1}). +-file("src/ntriples_parser.yrl", 6). +yeccpars2_4_(__Stack0) -> + [__1 | __Stack] = __Stack0, + [begin + [ __1 ] + end | __Stack]. + +-compile({inline,yeccpars2_5_/1}). +-file("src/ntriples_parser.yrl", 8). +yeccpars2_5_(__Stack0) -> + [__1 | __Stack] = __Stack0, + [begin + [ ] + end | __Stack]. + +-compile({inline,yeccpars2_6_/1}). +-file("src/ntriples_parser.yrl", 22). +yeccpars2_6_(__Stack0) -> + [__1 | __Stack] = __Stack0, + [begin + to_bnode ( __1 ) + end | __Stack]. + +-compile({inline,yeccpars2_7_/1}). +-file("src/ntriples_parser.yrl", 0). +yeccpars2_7_(__Stack0) -> + [__1 | __Stack] = __Stack0, + [begin + '$undefined' + end | __Stack]. + +-compile({inline,yeccpars2_8_/1}). +-file("src/ntriples_parser.yrl", 21). +yeccpars2_8_(__Stack0) -> + [__1 | __Stack] = __Stack0, + [begin + to_uri ( __1 ) + end | __Stack]. + +-compile({inline,yeccpars2_9_/1}). +-file("src/ntriples_parser.yrl", 7). +yeccpars2_9_(__Stack0) -> + [__2,__1 | __Stack] = __Stack0, + [begin + [ __2 ] + end | __Stack]. + +-compile({inline,yeccpars2_10_/1}). +-file("src/ntriples_parser.yrl", 0). +yeccpars2_10_(__Stack0) -> + [__2,__1 | __Stack] = __Stack0, + [begin + '$undefined' + end | __Stack]. + +-compile({inline,yeccpars2_12_/1}). +-file("src/ntriples_parser.yrl", 23). +yeccpars2_12_(__Stack0) -> + [__1 | __Stack] = __Stack0, + [begin + to_uri ( __1 ) + end | __Stack]. + +-compile({inline,yeccpars2_15_/1}). +-file("src/ntriples_parser.yrl", 25). +yeccpars2_15_(__Stack0) -> + [__1 | __Stack] = __Stack0, + [begin + to_bnode ( __1 ) + end | __Stack]. + +-compile({inline,yeccpars2_16_/1}). +-file("src/ntriples_parser.yrl", 24). +yeccpars2_16_(__Stack0) -> + [__1 | __Stack] = __Stack0, + [begin + to_uri ( __1 ) + end | __Stack]. + +-compile({inline,yeccpars2_17_/1}). +-file("src/ntriples_parser.yrl", 30). +yeccpars2_17_(__Stack0) -> + [__1 | __Stack] = __Stack0, + [begin + to_literal ( __1 ) + end | __Stack]. + +-compile({inline,yeccpars2_19_/1}). +-file("src/ntriples_parser.yrl", 29). +yeccpars2_19_(__Stack0) -> + [__2,__1 | __Stack] = __Stack0, + [begin + to_literal ( __1 , { language , to_langtag ( __2 ) } ) + end | __Stack]. + +-compile({inline,yeccpars2_20_/1}). +-file("src/ntriples_parser.yrl", 28). +yeccpars2_20_(__Stack0) -> + [__3,__2,__1 | __Stack] = __Stack0, + [begin + to_literal ( __1 , { datatype , to_uri ( __3 ) } ) + end | __Stack]. + +-compile({inline,yeccpars2_21_/1}). +-file("src/ntriples_parser.yrl", 19). +yeccpars2_21_(__Stack0) -> + [__4,__3,__2,__1 | __Stack] = __Stack0, + [begin + { __1 , __2 , __3 } + end | __Stack]. + +-compile({inline,yeccpars2_22_/1}). +-file("src/ntriples_parser.yrl", 16). +yeccpars2_22_(__Stack0) -> + [__2,__1 | __Stack] = __Stack0, + [begin + [ __1 ] + end | __Stack]. + +-compile({inline,yeccpars2_23_/1}). +-file("src/ntriples_parser.yrl", 15). +yeccpars2_23_(__Stack0) -> + [__3,__2,__1 | __Stack] = __Stack0, + [begin + [ __1 | __3 ] + end | __Stack]. + + +-file("src/ntriples_parser.yrl", 48). diff --git a/src/ntriples_parser.yrl b/src/ntriples_parser.yrl new file mode 100644 index 0000000..6fd7c76 --- /dev/null +++ b/src/ntriples_parser.yrl @@ -0,0 +1,47 @@ +%% Grammar for N-Triples as specified in https://www.w3.org/TR/2014/REC-n-triples-20140225/ + +Nonterminals ntriplesDoc nonEmptyNtriplesDoc triple subject predicate object literal eols. +Terminals iriref blank_node_label string_literal_quote langtag '^^' '.' eol. +Rootsymbol ntriplesDoc. + +eols -> eols eol. +eols -> eol. + +ntriplesDoc -> nonEmptyNtriplesDoc : [ '$1']. +ntriplesDoc -> eols nonEmptyNtriplesDoc : [ '$2']. +ntriplesDoc -> eols : []. +ntriplesDoc -> '$empty' : []. + +%nonEmptyNtriplesDoc -> triple eol nonEmptyNtriplesDoc : [ '$1' | '$3' ]. +%nonEmptyNtriplesDoc -> triple eol : [ '$1' ]. +%nonEmptyNtriplesDoc -> triple : [ '$1' ]. + +nonEmptyNtriplesDoc -> triple eols nonEmptyNtriplesDoc : [ '$1' | '$3' ]. +nonEmptyNtriplesDoc -> triple eols : [ '$1' ]. +nonEmptyNtriplesDoc -> triple : [ '$1' ]. + +triple -> subject predicate object '.' : { '$1', '$2', '$3' }. + +subject -> iriref : to_uri('$1'). +subject -> blank_node_label : to_bnode('$1'). +predicate -> iriref : to_uri('$1'). +object -> iriref : to_uri('$1'). +object -> blank_node_label : to_bnode('$1'). +object -> literal : '$1'. + +literal -> string_literal_quote '^^' iriref : to_literal('$1', {datatype, to_uri('$3')}). +literal -> string_literal_quote langtag : to_literal('$1', {language, to_langtag('$2')}). +literal -> string_literal_quote : to_literal('$1'). + + +Erlang code. + +to_uri(IRIREF) -> + case 'Elixir.RDF.Reader.ParseHelper':to_uri(IRIREF) of + {ok, URI} -> URI; + {error, ErrorLine, Message} -> return_error(ErrorLine, Message) + end. +to_bnode(BLANK_NODE_LABEL) -> 'Elixir.RDF.Reader.ParseHelper':to_bnode(BLANK_NODE_LABEL). +to_literal(STRING_LITERAL_QUOTE) -> 'Elixir.RDF.Reader.ParseHelper':to_literal(STRING_LITERAL_QUOTE). +to_literal(STRING_LITERAL_QUOTE, Type) -> 'Elixir.RDF.Reader.ParseHelper':to_literal(STRING_LITERAL_QUOTE, Type). +to_langtag(LANGTAG) -> 'Elixir.RDF.Reader.ParseHelper':to_langtag(LANGTAG). diff --git a/test/data/N-TRIPLES-TESTS/README b/test/data/N-TRIPLES-TESTS/README new file mode 100644 index 0000000..12d8bf1 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/README @@ -0,0 +1,25 @@ +This README is for the W3C RDF Working Group's N-Triples test suite. +This test suite contains two kinds of tests: + + Positive syntax (rdft:TestNTriplesPositiveSyntax) - an input N-Triples + file with no syntax errors. + + Negative syntax (rdft:TestNTriplesNegativeSyntax) - an input N-Triples + file with at least one syntax error. + +The manifest.ttl file in this directory lists tests in the +RDF WG's N-Triples test suite. All +tests have a name (mf:name) and an input (mf:action). + +• An implementation passes a positive syntax test if it parses the + input. + +• An implementation passes a negative syntax test if it fails to parse + the input. + +The home of the test suite is . + +See http://www.w3.org/2011/rdf-wg/wiki/RDF_Test_Suites for more details. + +Eric Prud'hommeaux - 11 June 2013. +Gregg Kellogg - 26 June 2013. diff --git a/test/data/N-TRIPLES-TESTS/comment_following_triple.nt b/test/data/N-TRIPLES-TESTS/comment_following_triple.nt new file mode 100644 index 0000000..5619459 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/comment_following_triple.nt @@ -0,0 +1,5 @@ + . # comment + _:o . # comment + "o" . # comment + "o"^^ . # comment + "o"@en . # comment diff --git a/test/data/N-TRIPLES-TESTS/langtagged_string.nt b/test/data/N-TRIPLES-TESTS/langtagged_string.nt new file mode 100644 index 0000000..1bddb04 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/langtagged_string.nt @@ -0,0 +1 @@ + "chat"@en . diff --git a/test/data/N-TRIPLES-TESTS/lantag_with_subtag.nt b/test/data/N-TRIPLES-TESTS/lantag_with_subtag.nt new file mode 100644 index 0000000..629cbf4 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/lantag_with_subtag.nt @@ -0,0 +1 @@ + "Cheers"@en-UK . diff --git a/test/data/N-TRIPLES-TESTS/literal.nt b/test/data/N-TRIPLES-TESTS/literal.nt new file mode 100644 index 0000000..3aba89e --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal.nt @@ -0,0 +1 @@ + "x" . diff --git a/test/data/N-TRIPLES-TESTS/literal_all_controls.nt b/test/data/N-TRIPLES-TESTS/literal_all_controls.nt new file mode 100644 index 0000000..91c8af1 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_all_controls.nt @@ -0,0 +1 @@ + "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\t\u000B\u000C\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F" . diff --git a/test/data/N-TRIPLES-TESTS/literal_all_punctuation.nt b/test/data/N-TRIPLES-TESTS/literal_all_punctuation.nt new file mode 100644 index 0000000..c25d818 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_all_punctuation.nt @@ -0,0 +1 @@ + " !\"#$%&():;<=>?@[]^_`{|}~" . diff --git a/test/data/N-TRIPLES-TESTS/literal_ascii_boundaries.nt b/test/data/N-TRIPLES-TESTS/literal_ascii_boundaries.nt new file mode 100644 index 0000000..7a4dc71 Binary files /dev/null and b/test/data/N-TRIPLES-TESTS/literal_ascii_boundaries.nt differ diff --git a/test/data/N-TRIPLES-TESTS/literal_false.nt b/test/data/N-TRIPLES-TESTS/literal_false.nt new file mode 100644 index 0000000..5bbbae8 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_false.nt @@ -0,0 +1 @@ + "false"^^ . diff --git a/test/data/N-TRIPLES-TESTS/literal_true.nt b/test/data/N-TRIPLES-TESTS/literal_true.nt new file mode 100644 index 0000000..054b229 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_true.nt @@ -0,0 +1 @@ + "true"^^ . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_2_dquotes.nt b/test/data/N-TRIPLES-TESTS/literal_with_2_dquotes.nt new file mode 100644 index 0000000..3e69dc1 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_2_dquotes.nt @@ -0,0 +1 @@ + "x\"\"y" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_2_squotes.nt b/test/data/N-TRIPLES-TESTS/literal_with_2_squotes.nt new file mode 100644 index 0000000..8ddc52e --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_2_squotes.nt @@ -0,0 +1 @@ + "x''y" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_BACKSPACE.nt b/test/data/N-TRIPLES-TESTS/literal_with_BACKSPACE.nt new file mode 100644 index 0000000..339013d --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_BACKSPACE.nt @@ -0,0 +1 @@ + "\b" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_CARRIAGE_RETURN.nt b/test/data/N-TRIPLES-TESTS/literal_with_CARRIAGE_RETURN.nt new file mode 100644 index 0000000..91b85c8 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_CARRIAGE_RETURN.nt @@ -0,0 +1 @@ + "\r" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_CHARACTER_TABULATION.nt b/test/data/N-TRIPLES-TESTS/literal_with_CHARACTER_TABULATION.nt new file mode 100644 index 0000000..a6a9d9f --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_CHARACTER_TABULATION.nt @@ -0,0 +1 @@ + "\t" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_FORM_FEED.nt b/test/data/N-TRIPLES-TESTS/literal_with_FORM_FEED.nt new file mode 100644 index 0000000..10d2c6d --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_FORM_FEED.nt @@ -0,0 +1 @@ + "\f" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_LINE_FEED.nt b/test/data/N-TRIPLES-TESTS/literal_with_LINE_FEED.nt new file mode 100644 index 0000000..462f97a --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_LINE_FEED.nt @@ -0,0 +1 @@ + "\n" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_REVERSE_SOLIDUS.nt b/test/data/N-TRIPLES-TESTS/literal_with_REVERSE_SOLIDUS.nt new file mode 100644 index 0000000..ebc846e --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_REVERSE_SOLIDUS.nt @@ -0,0 +1 @@ + "\\" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_REVERSE_SOLIDUS2.nt b/test/data/N-TRIPLES-TESTS/literal_with_REVERSE_SOLIDUS2.nt new file mode 100644 index 0000000..586e364 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_REVERSE_SOLIDUS2.nt @@ -0,0 +1 @@ + "test-\\" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_UTF8_boundaries.nt b/test/data/N-TRIPLES-TESTS/literal_with_UTF8_boundaries.nt new file mode 100644 index 0000000..0e1616d --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_UTF8_boundaries.nt @@ -0,0 +1 @@ + "€߿ࠀ࿿က쿿퀀퟿�𐀀𿿽񀀀󿿽􀀀􏿽" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_dquote.nt b/test/data/N-TRIPLES-TESTS/literal_with_dquote.nt new file mode 100644 index 0000000..05a1fd3 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_dquote.nt @@ -0,0 +1 @@ + "x\"y" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_numeric_escape4.nt b/test/data/N-TRIPLES-TESTS/literal_with_numeric_escape4.nt new file mode 100644 index 0000000..16f0a03 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_numeric_escape4.nt @@ -0,0 +1 @@ + "\u006F" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_numeric_escape8.nt b/test/data/N-TRIPLES-TESTS/literal_with_numeric_escape8.nt new file mode 100644 index 0000000..e909a79 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_numeric_escape8.nt @@ -0,0 +1 @@ + "\U0000006F" . diff --git a/test/data/N-TRIPLES-TESTS/literal_with_squote.nt b/test/data/N-TRIPLES-TESTS/literal_with_squote.nt new file mode 100644 index 0000000..acf7f58 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/literal_with_squote.nt @@ -0,0 +1 @@ + "x'y" . diff --git a/test/data/N-TRIPLES-TESTS/manifest.ttl b/test/data/N-TRIPLES-TESTS/manifest.ttl new file mode 100644 index 0000000..f48e5a2 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/manifest.ttl @@ -0,0 +1,512 @@ +# N-Triples Syntax tests + +@prefix rdf: . +@prefix rdfs: . +@prefix mf: . +@prefix qt: . + +@prefix rdft: . + +<> rdf:type mf:Manifest ; + mf:name "N-Triples tests" ; + mf:entries + ( + <#nt-syntax-file-01> + <#nt-syntax-file-02> + <#nt-syntax-file-03> + <#nt-syntax-uri-01> + <#nt-syntax-uri-02> + <#nt-syntax-uri-03> + <#nt-syntax-uri-04> + <#nt-syntax-string-01> + <#nt-syntax-string-02> + <#nt-syntax-string-03> + <#nt-syntax-str-esc-01> + <#nt-syntax-str-esc-02> + <#nt-syntax-str-esc-03> + <#nt-syntax-bnode-01> + <#nt-syntax-bnode-02> + <#nt-syntax-bnode-03> + <#nt-syntax-datatypes-01> + <#nt-syntax-datatypes-02> + <#nt-syntax-bad-uri-01> + <#nt-syntax-bad-uri-02> + <#nt-syntax-bad-uri-03> + <#nt-syntax-bad-uri-04> + <#nt-syntax-bad-uri-05> + <#nt-syntax-bad-uri-06> + <#nt-syntax-bad-uri-07> + <#nt-syntax-bad-uri-08> + <#nt-syntax-bad-uri-09> + <#nt-syntax-bad-prefix-01> + <#nt-syntax-bad-base-01> + <#nt-syntax-bad-struct-01> + <#nt-syntax-bad-struct-02> + <#nt-syntax-bad-lang-01> + <#nt-syntax-bad-esc-01> + <#nt-syntax-bad-esc-02> + <#nt-syntax-bad-esc-03> + <#nt-syntax-bad-string-01> + <#nt-syntax-bad-string-02> + <#nt-syntax-bad-string-03> + <#nt-syntax-bad-string-04> + <#nt-syntax-bad-string-05> + <#nt-syntax-bad-string-06> + <#nt-syntax-bad-string-07> + <#nt-syntax-bad-num-01> + <#nt-syntax-bad-num-02> + <#nt-syntax-bad-num-03> + <#nt-syntax-subm-01> + <#comment_following_triple> + <#literal> + <#literal_all_controls> + <#literal_all_punctuation> + <#literal_ascii_boundaries> + <#literal_with_2_dquotes> + <#literal_with_2_squotes> + <#literal_with_BACKSPACE> + <#literal_with_CARRIAGE_RETURN> + <#literal_with_CHARACTER_TABULATION> + <#literal_with_dquote> + <#literal_with_FORM_FEED> + <#literal_with_LINE_FEED> + <#literal_with_numeric_escape4> + <#literal_with_numeric_escape8> + <#literal_with_REVERSE_SOLIDUS> + <#literal_with_REVERSE_SOLIDUS2> + <#literal_with_squote> + <#literal_with_UTF8_boundaries> + <#langtagged_string> + <#lantag_with_subtag> + <#minimal_whitespace> + ) . + +<#nt-syntax-file-01> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-file-01" ; + rdfs:comment "Empty file" ; + mf:action ; + . + +<#nt-syntax-file-02> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-file-02" ; + rdfs:comment "Only comment" ; + mf:action ; + . + +<#nt-syntax-file-03> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-file-03" ; + rdfs:comment "One comment, one empty line" ; + mf:action ; + . + +<#nt-syntax-uri-01> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-uri-01" ; + rdfs:comment "Only IRIs" ; + mf:action ; + . + +<#nt-syntax-uri-02> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-uri-02" ; + rdfs:comment "IRIs with Unicode escape" ; + mf:action ; + . + +<#nt-syntax-uri-03> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-uri-03" ; + rdfs:comment "IRIs with long Unicode escape" ; + mf:action ; + . + +<#nt-syntax-uri-04> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-uri-04" ; + rdfs:comment "Legal IRIs" ; + mf:action ; + . + +<#nt-syntax-string-01> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-string-01" ; + rdfs:comment "string literal" ; + mf:action ; + . + +<#nt-syntax-string-02> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-string-02" ; + rdfs:comment "langString literal" ; + mf:action ; + . + +<#nt-syntax-string-03> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-string-03" ; + rdfs:comment "langString literal with region" ; + mf:action ; + . + +<#nt-syntax-str-esc-01> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-str-esc-01" ; + rdfs:comment "string literal with escaped newline" ; + mf:action ; + . + +<#nt-syntax-str-esc-02> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-str-esc-02" ; + rdfs:comment "string literal with Unicode escape" ; + mf:action ; + . + +<#nt-syntax-str-esc-03> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-str-esc-03" ; + rdfs:comment "string literal with long Unicode escape" ; + mf:action ; + . + +<#nt-syntax-bnode-01> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-bnode-01" ; + rdfs:comment "bnode subject" ; + mf:action ; + . + +<#nt-syntax-bnode-02> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-bnode-02" ; + rdfs:comment "bnode object" ; + mf:action ; + . + +<#nt-syntax-bnode-03> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-bnode-03" ; + rdfs:comment "Blank node labels may start with a digit" ; + mf:action ; + . + +<#nt-syntax-datatypes-01> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-datatypes-01" ; + rdfs:comment "xsd:byte literal" ; + mf:action ; + . + +<#nt-syntax-datatypes-02> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-datatypes-02" ; + rdfs:comment "integer as xsd:string" ; + mf:action ; + . + +<#nt-syntax-bad-uri-01> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-uri-01" ; + rdfs:comment "Bad IRI : space (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-uri-02> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-uri-02" ; + rdfs:comment "Bad IRI : bad escape (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-uri-03> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-uri-03" ; + rdfs:comment "Bad IRI : bad long escape (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-uri-04> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-uri-04" ; + rdfs:comment "Bad IRI : character escapes not allowed (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-uri-05> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-uri-05" ; + rdfs:comment "Bad IRI : character escapes not allowed (2) (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-uri-06> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-uri-06" ; + rdfs:comment "Bad IRI : relative IRI not allowed in subject (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-uri-07> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-uri-07" ; + rdfs:comment "Bad IRI : relative IRI not allowed in predicate (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-uri-08> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-uri-08" ; + rdfs:comment "Bad IRI : relative IRI not allowed in object (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-uri-09> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-uri-09" ; + rdfs:comment "Bad IRI : relative IRI not allowed in datatype (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-prefix-01> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-prefix-01" ; + rdfs:comment "@prefix not allowed in n-triples (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-base-01> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-base-01" ; + rdfs:comment "@base not allowed in N-Triples (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-struct-01> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-struct-01" ; + rdfs:comment "N-Triples does not have objectList (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-struct-02> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-struct-02" ; + rdfs:comment "N-Triples does not have predicateObjectList (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-lang-01> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-lang-01" ; + rdfs:comment "langString with bad lang (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-esc-01> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-esc-01" ; + rdfs:comment "Bad string escape (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-esc-02> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-esc-02" ; + rdfs:comment "Bad string escape (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-esc-03> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-esc-03" ; + rdfs:comment "Bad string escape (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-string-01> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-string-01" ; + rdfs:comment "mismatching string literal open/close (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-string-02> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-string-02" ; + rdfs:comment "mismatching string literal open/close (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-string-03> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-string-03" ; + rdfs:comment "single quotes (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-string-04> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-string-04" ; + rdfs:comment "long single string literal (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-string-05> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-string-05" ; + rdfs:comment "long double string literal (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-string-06> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-string-06" ; + rdfs:comment "string literal with no end (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-string-07> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-string-07" ; + rdfs:comment "string literal with no start (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-num-01> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-num-01" ; + rdfs:comment "no numbers in N-Triples (integer) (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-num-02> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-num-02" ; + rdfs:comment "no numbers in N-Triples (decimal) (negative test)" ; + mf:action ; + . + +<#nt-syntax-bad-num-03> rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "nt-syntax-bad-num-03" ; + rdfs:comment "no numbers in N-Triples (float) (negative test)" ; + mf:action ; + . + +<#nt-syntax-subm-01> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "nt-syntax-subm-01" ; + rdfs:comment "Submission test from Original RDF Test Cases" ; + mf:action ; + . + +<#comment_following_triple> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "comment_following_triple" ; + rdfs:comment "Tests comments after a triple" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_ascii_boundaries> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_ascii_boundaries" ; + rdfs:comment "literal_ascii_boundaries '\\x00\\x26\\x28...'" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_UTF8_boundaries> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_UTF8_boundaries" ; + rdfs:comment "literal_with_UTF8_boundaries '\\x80\\x7ff\\x800\\xfff...'" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_all_controls> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_all_controls" ; + rdfs:comment "literal_all_controls '\\x00\\x01\\x02\\x03\\x04...'" ; + rdft:approval rdft:Approved ; + mf:action ; + . + +<#literal_all_punctuation> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_all_punctuation" ; + rdfs:comment "literal_all_punctuation '!\"#$%&()...'" ; + rdft:approval rdft:Approved ; + mf:action ; + . + +<#literal_with_squote> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_squote" ; + rdfs:comment "literal with squote \"x'y\"" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_2_squotes> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_2_squotes" ; + rdfs:comment "literal with 2 squotes \"x''y\"" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal" ; + rdfs:comment "literal \"\"\"x\"\"\"" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_dquote> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_dquote" ; + rdfs:comment 'literal with dquote "x\"y"' ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_2_dquotes> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_2_dquotes" ; + rdfs:comment "literal with 2 squotes \"\"\"a\"\"b\"\"\"" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_REVERSE_SOLIDUS2> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_REVERSE_SOLIDUS2" ; + rdfs:comment "REVERSE SOLIDUS at end of literal" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_CHARACTER_TABULATION> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_CHARACTER_TABULATION" ; + rdfs:comment "literal with CHARACTER TABULATION" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_BACKSPACE> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_BACKSPACE" ; + rdfs:comment "literal with BACKSPACE" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_LINE_FEED> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_LINE_FEED" ; + rdfs:comment "literal with LINE FEED" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_CARRIAGE_RETURN> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_CARRIAGE_RETURN" ; + rdfs:comment "literal with CARRIAGE RETURN" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_FORM_FEED> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_FORM_FEED" ; + rdfs:comment "literal with FORM FEED" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_REVERSE_SOLIDUS> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_REVERSE_SOLIDUS" ; + rdfs:comment "literal with REVERSE SOLIDUS" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_numeric_escape4> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_numeric_escape4" ; + rdfs:comment "literal with numeric escape4 \\u" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#literal_with_numeric_escape8> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "literal_with_numeric_escape8" ; + rdfs:comment "literal with numeric escape8 \\U" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#langtagged_string> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "langtagged_string" ; + rdfs:comment "langtagged string \"x\"@en" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#lantag_with_subtag> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "lantag_with_subtag" ; + rdfs:comment "lantag with subtag \"x\"@en-us" ; + rdft:approval rdft:Proposed ; + mf:action ; + . + +<#minimal_whitespace> rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "minimal_whitespace" ; + rdfs:comment "tests absense of whitespace between subject, predicate, object and end-of-statement" ; + rdft:approval rdft:Proposed ; + mf:action ; + . diff --git a/test/data/N-TRIPLES-TESTS/minimal_whitespace.nt b/test/data/N-TRIPLES-TESTS/minimal_whitespace.nt new file mode 100644 index 0000000..e9e3a80 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/minimal_whitespace.nt @@ -0,0 +1,6 @@ +. +"Alice". +_:o. +_:s. +_:s"Alice". +_:s_:bnode1. diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-base-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-base-01.nt new file mode 100644 index 0000000..dff1b3b --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-base-01.nt @@ -0,0 +1 @@ +@base . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-esc-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-esc-01.nt new file mode 100644 index 0000000..f7a88ad --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-esc-01.nt @@ -0,0 +1,2 @@ +# Bad string escape + "a\zb" . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-esc-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-esc-02.nt new file mode 100644 index 0000000..72711d4 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-esc-02.nt @@ -0,0 +1,2 @@ +# Bad string escape + "\uWXYZ" . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-esc-03.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-esc-03.nt new file mode 100644 index 0000000..3a4522f --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-esc-03.nt @@ -0,0 +1,2 @@ +# Bad string escape + "\U0000WXYZ" . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-lang-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-lang-01.nt new file mode 100644 index 0000000..a4d952c --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-lang-01.nt @@ -0,0 +1,2 @@ +# Bad lang tag + "string"@1 . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-num-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-num-01.nt new file mode 100644 index 0000000..2be6f51 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-num-01.nt @@ -0,0 +1 @@ + 1 . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-num-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-num-02.nt new file mode 100644 index 0000000..e1d5b06 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-num-02.nt @@ -0,0 +1 @@ + 1.0 . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-num-03.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-num-03.nt new file mode 100644 index 0000000..a9be82f --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-num-03.nt @@ -0,0 +1 @@ + 1.0e0 . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-prefix-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-prefix-01.nt new file mode 100644 index 0000000..89e08cc --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-prefix-01.nt @@ -0,0 +1 @@ +@prefix : . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-01.nt new file mode 100644 index 0000000..988af87 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-01.nt @@ -0,0 +1 @@ + "abc' . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-02.nt new file mode 100644 index 0000000..e1d5b06 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-02.nt @@ -0,0 +1 @@ + 1.0 . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-03.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-03.nt new file mode 100644 index 0000000..64d343d --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-03.nt @@ -0,0 +1 @@ + 1.0e1 . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-04.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-04.nt new file mode 100644 index 0000000..af4ff28 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-04.nt @@ -0,0 +1 @@ + '''abc''' . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-05.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-05.nt new file mode 100644 index 0000000..75ad4b2 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-05.nt @@ -0,0 +1 @@ + """abc""" . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-06.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-06.nt new file mode 100644 index 0000000..56dcbc6 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-06.nt @@ -0,0 +1 @@ + "abc . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-07.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-07.nt new file mode 100644 index 0000000..7f1ee80 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-string-07.nt @@ -0,0 +1 @@ + abc" . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-struct-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-struct-01.nt new file mode 100644 index 0000000..d546d56 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-struct-01.nt @@ -0,0 +1 @@ + , . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-struct-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-struct-02.nt new file mode 100644 index 0000000..1f388c6 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-struct-02.nt @@ -0,0 +1 @@ + ; , . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-01.nt new file mode 100644 index 0000000..0e69dc0 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-01.nt @@ -0,0 +1,2 @@ +# Bad IRI : space. + . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-02.nt new file mode 100644 index 0000000..36d91af --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-02.nt @@ -0,0 +1,2 @@ +# Bad IRI : bad escape + . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-03.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-03.nt new file mode 100644 index 0000000..f512345 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-03.nt @@ -0,0 +1,2 @@ +# Bad IRI : bad escape + . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-04.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-04.nt new file mode 100644 index 0000000..5cab062 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-04.nt @@ -0,0 +1,2 @@ +# Bad IRI : character escapes not allowed. + . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-05.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-05.nt new file mode 100644 index 0000000..be0a21e --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-05.nt @@ -0,0 +1,2 @@ +# Bad IRI : character escapes not allowed. + . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-06.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-06.nt new file mode 100644 index 0000000..b4e6459 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-06.nt @@ -0,0 +1,2 @@ +# No relative IRIs in N-Triples + . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-07.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-07.nt new file mode 100644 index 0000000..74534dd --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-07.nt @@ -0,0 +1,2 @@ +# No relative IRIs in N-Triples +

. diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-08.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-08.nt new file mode 100644 index 0000000..41a953d --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-08.nt @@ -0,0 +1,2 @@ +# No relative IRIs in N-Triples + . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-09.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-09.nt new file mode 100644 index 0000000..58821da --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bad-uri-09.nt @@ -0,0 +1,2 @@ +# No relative IRIs in N-Triples + "foo"^^

. diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bnode-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bnode-01.nt new file mode 100644 index 0000000..5fb0d0f --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bnode-01.nt @@ -0,0 +1 @@ +_:a . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bnode-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bnode-02.nt new file mode 100644 index 0000000..737e81b --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bnode-02.nt @@ -0,0 +1,2 @@ + _:a . +_:a . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-bnode-03.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-bnode-03.nt new file mode 100644 index 0000000..1a1f1c9 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-bnode-03.nt @@ -0,0 +1,2 @@ + _:1a . +_:1a . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-datatypes-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-datatypes-01.nt new file mode 100644 index 0000000..9126309 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-datatypes-01.nt @@ -0,0 +1 @@ + "123"^^ . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-datatypes-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-datatypes-02.nt new file mode 100644 index 0000000..d49cc27 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-datatypes-02.nt @@ -0,0 +1 @@ + "123"^^ . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-file-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-file-01.nt new file mode 100644 index 0000000..e69de29 diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-file-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-file-02.nt new file mode 100644 index 0000000..e6d327d --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-file-02.nt @@ -0,0 +1 @@ +#Empty file. diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-file-03.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-file-03.nt new file mode 100644 index 0000000..a9ca035 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-file-03.nt @@ -0,0 +1,2 @@ +#One comment, one empty line. + diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-str-esc-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-str-esc-01.nt new file mode 100644 index 0000000..3925f2e --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-str-esc-01.nt @@ -0,0 +1 @@ + "a\n" . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-str-esc-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-str-esc-02.nt new file mode 100644 index 0000000..e7d032f --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-str-esc-02.nt @@ -0,0 +1 @@ + "a\u0020b" . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-str-esc-03.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-str-esc-03.nt new file mode 100644 index 0000000..b8588c7 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-str-esc-03.nt @@ -0,0 +1 @@ + "a\U00000020b" . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-string-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-string-01.nt new file mode 100644 index 0000000..5333aef --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-string-01.nt @@ -0,0 +1 @@ + "string" . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-string-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-string-02.nt new file mode 100644 index 0000000..1ab55a3 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-string-02.nt @@ -0,0 +1 @@ + "string"@en . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-string-03.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-string-03.nt new file mode 100644 index 0000000..b34ca0f --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-string-03.nt @@ -0,0 +1 @@ + "string"@en-uk . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-subm-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-subm-01.nt new file mode 100644 index 0000000..91b4988 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-subm-01.nt @@ -0,0 +1,79 @@ +# +# Copyright World Wide Web Consortium, (Massachusetts Institute of +# Technology, Institut National de Recherche en Informatique et en +# Automatique, Keio University). +# +# All Rights Reserved. +# +# Please see the full Copyright clause at +# +# +# Test file with a variety of legal N-Triples +# +# Dave Beckett - http://purl.org/net/dajobe/ +# +# $Id: test.nt,v 1.7 2003/10/06 15:52:19 dbeckett2 Exp $ +# +##################################################################### + +# comment lines + # comment line after whitespace +# empty blank line, then one with spaces and tabs + + + . +_:anon . + _:anon . +# spaces and tabs throughout: + . + +# line ending with CR NL (ASCII 13, ASCII 10) + . + +# 2 statement lines separated by single CR (ASCII 10) + . + . + + +# All literal escapes + "simple literal" . + "backslash:\\" . + "dquote:\"" . + "newline:\n" . + "return\r" . + "tab:\t" . + +# Space is optional before final . + . + "x". + _:anon. + +# \u and \U escapes +# latin small letter e with acute symbol \u00E9 - 3 UTF-8 bytes #xC3 #A9 + "\u00E9" . +# Euro symbol \u20ac - 3 UTF-8 bytes #xE2 #x82 #xAC + "\u20AC" . +# resource18 test removed +# resource19 test removed +# resource20 test removed + +# XML Literals as Datatyped Literals + ""^^ . + " "^^ . + "x"^^ . + "\""^^ . + ""^^ . + "a "^^ . + "a c"^^ . + "a\n\nc"^^ . + "chat"^^ . +# resource28 test removed 2003-08-03 +# resource29 test removed 2003-08-03 + +# Plain literals with languages + "chat"@fr . + "chat"@en . + +# Typed Literals + "abc"^^ . +# resource33 test removed 2003-08-03 diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-uri-01.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-uri-01.nt new file mode 100644 index 0000000..02e6ba9 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-uri-01.nt @@ -0,0 +1 @@ + . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-uri-02.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-uri-02.nt new file mode 100644 index 0000000..664feea --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-uri-02.nt @@ -0,0 +1,2 @@ +# x53 is capital S + . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-uri-03.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-uri-03.nt new file mode 100644 index 0000000..b5aeb26 --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-uri-03.nt @@ -0,0 +1,2 @@ +# x53 is capital S + . diff --git a/test/data/N-TRIPLES-TESTS/nt-syntax-uri-04.nt b/test/data/N-TRIPLES-TESTS/nt-syntax-uri-04.nt new file mode 100644 index 0000000..49bacca --- /dev/null +++ b/test/data/N-TRIPLES-TESTS/nt-syntax-uri-04.nt @@ -0,0 +1,2 @@ +# IRI with all chars in it. + . diff --git a/test/unit/literal_test.exs b/test/unit/literal_test.exs index e2cdecd..5592650 100644 --- a/test/unit/literal_test.exs +++ b/test/unit/literal_test.exs @@ -6,6 +6,12 @@ defmodule RDF.LiteralTest do alias RDF.{Literal, XSD} describe "construction by type inference" do + test "creating an string literal" do + string_literal = Literal.new("foo") + assert string_literal.value == "foo" + assert string_literal.datatype == XSD.string + end + test "creating an integer by type inference" do int_literal = Literal.new(42) assert int_literal.value == 42 @@ -24,4 +30,60 @@ defmodule RDF.LiteralTest do end + describe "construction with an explicit unknown datatype" do + literal = Literal.new("custom typed value", datatype: "http://example/dt") + assert literal.value == "custom typed value" + assert literal.datatype == RDF.uri("http://example/dt") + end + + describe "construction with an explicit known (XSD) datatype" do + test "creating a boolean" do + bool_literal = Literal.new("true", datatype: XSD.boolean) + assert bool_literal.value == true + assert bool_literal.datatype == XSD.boolean + + bool_literal = Literal.new(true, datatype: XSD.boolean) + assert bool_literal.value == true + assert bool_literal.datatype == XSD.boolean + + bool_literal = Literal.new("false", datatype: XSD.boolean) + assert bool_literal.value == false + assert bool_literal.datatype == XSD.boolean + + bool_literal = Literal.new(false, datatype: XSD.boolean) + assert bool_literal.value == false + assert bool_literal.datatype == XSD.boolean + end + + test "creating an integer" do + int_literal = Literal.new(42, datatype: XSD.integer) + assert int_literal.value == 42 + assert int_literal.datatype == XSD.integer + + int_literal = Literal.new("42", datatype: XSD.integer) + assert int_literal.value == 42 + assert int_literal.datatype == XSD.integer + + int_literal = Literal.new(true, datatype: XSD.integer) + assert int_literal.value == 1 + assert int_literal.datatype == XSD.integer + int_literal = Literal.new(false, datatype: XSD.integer) + assert int_literal.value == 0 + assert int_literal.datatype == XSD.integer + end + + end + + test "creating a language-tagged string literal" do + literal = Literal.new("Eule", language: "de") + assert literal.value == "Eule" + assert literal.datatype == RDF.langString + assert literal.language == "de" + end + + @tag :skip + test "construction of a typed and language-tagged literal fails" do + end + + end diff --git a/test/unit/ntriples/reader_test.exs b/test/unit/ntriples/reader_test.exs new file mode 100644 index 0000000..361a7dd --- /dev/null +++ b/test/unit/ntriples/reader_test.exs @@ -0,0 +1,150 @@ +defmodule RDF.NTriples.ReaderTest do + use ExUnit.Case, async: false + + doctest RDF.NTriples.Reader + + alias RDF.{Graph} + + defmodule EX, do: use RDF.Vocabulary, base_uri: "http://example.org/#" + defmodule P, do: use RDF.Vocabulary, base_uri: "http://www.perceive.net/schemas/relationship/" + + @w3c_ntriples_test_suite Path.join(File.cwd!, "test/data/N-TRIPLES-TESTS") + + test "an empty string is deserialized to an empty graph" do + assert RDF.NTriples.Reader.read!("") == Graph.new + assert RDF.NTriples.Reader.read!(" \n\r\r\n ") == Graph.new + end + + test "reading comments" do + assert RDF.NTriples.Reader.read!("# just a comment") == Graph.new + + assert RDF.NTriples.Reader.read!(""" + _:1 . # a comment + """) == Graph.new({EX.S, EX.p, RDF.bnode("1")}) + + assert RDF.NTriples.Reader.read!(""" + # a comment + . + """) == Graph.new({EX.S, EX.p, EX.O}) + + assert RDF.NTriples.Reader.read!(""" + . + # a comment + """) == Graph.new({EX.S, EX.p, EX.O}) + + assert RDF.NTriples.Reader.read!(""" + # Header line 1 + # Header line 2 + . + # 1st comment + . # 2nd comment + # last comment + """) == Graph.new([ + {EX.S1, EX.p1, EX.O1}, + {EX.S1, EX.p2, EX.O2}, + ]) + end + + test "empty lines" do + assert RDF.NTriples.Reader.read!(""" + + . + """) == Graph.new({EX.spiderman, P.enemyOf, EX.green_goblin}) + + assert RDF.NTriples.Reader.read!(""" + . + + """) == Graph.new({EX.spiderman, P.enemyOf, EX.green_goblin}) + + assert RDF.NTriples.Reader.read!(""" + + . + + + . + + """) == Graph.new([ + {EX.S1, EX.p1, EX.O1}, + {EX.S1, EX.p2, EX.O2}, + ]) + end + + test "reading a single triple uris" do + assert RDF.NTriples.Reader.read!(""" + . + """) == Graph.new({EX.spiderman, P.enemyOf, EX.green_goblin}) + end + + test "reading a single triple with a blank node" do + assert RDF.NTriples.Reader.read!(""" + _:foo . + """) == Graph.new({RDF.bnode("foo"), EX.p, EX.O}) + assert RDF.NTriples.Reader.read!(""" + _:1 . + """) == Graph.new({EX.S, EX.p, RDF.bnode("1")}) + assert RDF.NTriples.Reader.read!(""" + _:foo _:bar . + """) == Graph.new({RDF.bnode("foo"), EX.p, RDF.bnode("bar")}) + end + + test "reading a single triple with an untyped string literal" do + assert RDF.NTriples.Reader.read!(""" + "Peter Parker" . + """) == Graph.new({EX.spiderman, P.realname, RDF.literal("Peter Parker")}) + end + + test "reading a single triple with a typed literal" do + assert RDF.NTriples.Reader.read!(""" + "42"^^ . + """) == Graph.new({EX.spiderman, EX.p, RDF.literal(42)}) + end + + test "reading a single triple with a language tagged literal" do + assert RDF.NTriples.Reader.read!(""" + "foo"@en . + """) == Graph.new({EX.S, EX.p, RDF.literal("foo", language: "en")}) + end + + test "reading multiple triples" do + assert RDF.NTriples.Reader.read!(""" + . + . + """) == Graph.new([ + {EX.S1, EX.p1, EX.O1}, + {EX.S1, EX.p2, EX.O2}, + ]) + assert RDF.NTriples.Reader.read!(""" + . + . + . + """) == Graph.new([ + {EX.S1, EX.p1, EX.O1}, + {EX.S1, EX.p2, EX.O2}, + {EX.S2, EX.p3, EX.O3} + ]) + end + + describe "the official W3C RDF 1.1 N-Triples Test Suite" do + # from https://www.w3.org/2013/N-TriplesTests/ + + ExUnit.Case.register_attribute __ENV__, :nt_test + + @w3c_ntriples_test_suite + |> File.ls! + |> Enum.filter(fn (file) -> Path.extname(file) == ".nt" end) + |> Enum.each(fn (file) -> + @nt_test file: Path.join(@w3c_ntriples_test_suite, file) + if file |> String.contains?("-bad-") do + test "Negative syntax test: #{file}", context do + assert {:error, _} = RDF.NTriples.Reader.read_file(context.registered.nt_test[:file]) + end + else + test "Positive syntax test: #{file}", context do + assert {:ok, %RDF.Graph{}} = RDF.NTriples.Reader.read_file(context.registered.nt_test[:file]) + end + end + end) + + end + +end