oxigraph 0.1.0.rc2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/README.md +13 -5
- data/ext/oxigraph/src/error.rs +28 -0
- data/ext/oxigraph/src/query.rs +7 -5
- data/lib/oxigraph/errors.rb +12 -3
- data/lib/oxigraph/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f336c1daaf4b5dc7fa7bd60329d9e104c602d799d51d57e4c64ec5f4a62fab5b
|
|
4
|
+
data.tar.gz: 3a33a537716ce3a1a2cce3e38e9d3cda6a92be3b58d2e8df31544a10ae764da0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 21b20d7596f8aacae74aab853d87f84ad4f309d1b769317d285ef71241354eb74590e88d7cf9df64686d92e80376c1739733b9f741af048294ed5f80774622da
|
|
7
|
+
data.tar.gz: 9d06a7022731d9d2eba579bc89f6695c61e6b61fda915b3409a0fb194f6545431d779798dd8026e268ac4b51e31bc78f7f316e64904ed2f1f5d9e4880e4fb9ec
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,8 @@ Notable changes to `oxigraph` are documented here.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.1.0] - 2026-11-17
|
|
8
|
+
|
|
7
9
|
### Added
|
|
8
10
|
|
|
9
11
|
- Added the gem scaffold: a Rust native extension that builds and loads on Ruby 3.4 and 4.0.
|
|
@@ -13,5 +15,6 @@ Notable changes to `oxigraph` are documented here.
|
|
|
13
15
|
- Added `Oxigraph::ParseError`, which carries the line and column of malformed RDF input.
|
|
14
16
|
- Added `Oxigraph::Store#query`, which runs `SELECT`, `ASK`, `CONSTRUCT`, and `DESCRIBE` queries and streams their results.
|
|
15
17
|
- Added `Oxigraph::Query.parse` and `Oxigraph::Update.parse`, which parse SPARQL without running it. A query reports its form and whether it has a `SERVICE` or a dataset clause.
|
|
16
|
-
- Added `Oxigraph::QuerySyntaxError`,
|
|
18
|
+
- Added `Oxigraph::QuerySyntaxError`, which carries the line and column of a SPARQL syntax error.
|
|
19
|
+
- Added `Oxigraph::QueryEvaluationError` and `Oxigraph::UnsupportedError`.
|
|
17
20
|
- Added precompiled gems for Linux (glibc and musl) and macOS on x86-64 and ARM64, and for Windows on x64 and ARM64. Installing on those platforms needs no Rust toolchain; other platforms compile the extension from the source gem.
|
data/README.md
CHANGED
|
@@ -6,13 +6,13 @@ This is an unofficial binding and is not affiliated with the Oxigraph project.
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Install from [RubyGems](https://rubygems.org/gems/oxigraph) with `gem install oxigraph`, or add it to your Gemfile:
|
|
10
10
|
|
|
11
11
|
```ruby
|
|
12
|
-
gem "oxigraph",
|
|
12
|
+
gem "oxigraph", "~> 0.1.0"
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Precompiled gems are available for Ruby 3.4 and 4.0 on Linux (glibc and musl), macOS, and Windows, on both x86-64 and ARM64. Installing one does not need Rust. Building the source gem needs a [Rust toolchain](https://rustup.rs) at version 1.87 or newer.
|
|
16
16
|
|
|
17
17
|
## Stores and queries
|
|
18
18
|
|
|
@@ -128,7 +128,16 @@ Oxigraph::Update.parse("DROP ALL").to_s # => "DROP ALL ;"
|
|
|
128
128
|
Oxigraph::Update.parse("nonsense") # raises Oxigraph::QuerySyntaxError
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
A query or update that does not parse raises `Oxigraph::QuerySyntaxError
|
|
131
|
+
A query or update that does not parse raises `Oxigraph::QuerySyntaxError`. Its message is the parser's own, and its wording may change. Its `line` and `column` say where the parser stopped, counted from one; both are `nil` for the few errors that have no position.
|
|
132
|
+
|
|
133
|
+
The parser reports a prefix that nothing declared as an ordinary syntax error. It stops after the name, sometimes on a later line, and its message does not always mention the prefix:
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
Oxigraph::Query.parse("SELECT * WHERE { ex:a ?p ?o }")
|
|
137
|
+
# raises Oxigraph::QuerySyntaxError: error at 1:26: expected OPTIONAL
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
A query that fails while it runs raises `Oxigraph::QueryEvaluationError`.
|
|
132
141
|
|
|
133
142
|
## Terms
|
|
134
143
|
|
|
@@ -168,7 +177,6 @@ triple.to_s # => "<http://example.com/a> <http://example.com/p> \"chat\"@fr"
|
|
|
168
177
|
- JSON-LD that refers to a remote context fails to load, because the gem never fetches anything.
|
|
169
178
|
- Stores live in memory only. The gem is built without RocksDB, so there is no on-disk store.
|
|
170
179
|
- The gem is built without an HTTP client, so it never opens a network connection.
|
|
171
|
-
- There are no precompiled gems, so every install compiles the Rust extension.
|
|
172
180
|
- Only Ruby 3.4 and 4.0 are tested.
|
|
173
181
|
|
|
174
182
|
## Contributing
|
data/ext/oxigraph/src/error.rs
CHANGED
|
@@ -2,6 +2,7 @@ use std::fmt::Display;
|
|
|
2
2
|
|
|
3
3
|
use magnus::{kwargs, prelude::*, Error, ExceptionClass, RModule, Ruby};
|
|
4
4
|
use oxigraph::io::RdfSyntaxError;
|
|
5
|
+
use spargebra::SparqlSyntaxError;
|
|
5
6
|
|
|
6
7
|
/// Builds an `Oxigraph::Error`, the base class that `lib/oxigraph/errors.rb`
|
|
7
8
|
/// defines.
|
|
@@ -34,6 +35,33 @@ pub fn parse_error(ruby: &Ruby, cause: &RdfSyntaxError) -> Error {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/// Builds an `Oxigraph::QuerySyntaxError` that carries where a query or update
|
|
39
|
+
/// went wrong. Upstream keeps the position private and begins its message with
|
|
40
|
+
/// it, so it is read back from there. An error upstream reports without a
|
|
41
|
+
/// position leaves both nil.
|
|
42
|
+
pub fn query_syntax_error(ruby: &Ruby, cause: &SparqlSyntaxError) -> Error {
|
|
43
|
+
let message = cause.to_string();
|
|
44
|
+
let start = position_in(&message);
|
|
45
|
+
let position = kwargs!(
|
|
46
|
+
"line" => start.map(|(line, _)| line),
|
|
47
|
+
"column" => start.map(|(_, column)| column)
|
|
48
|
+
);
|
|
49
|
+
let exception = error_class(ruby, "QuerySyntaxError")
|
|
50
|
+
.and_then(|class| class.new_instance((message, position)));
|
|
51
|
+
match exception {
|
|
52
|
+
Ok(exception) => exception.into(),
|
|
53
|
+
Err(failure) => failure,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Reads the line and column from a message such as
|
|
58
|
+
/// `error at 3:9: expected ...`, both already counted from one.
|
|
59
|
+
fn position_in(message: &str) -> Option<(usize, usize)> {
|
|
60
|
+
let (position, _) = message.strip_prefix("error at ")?.split_once(": ")?;
|
|
61
|
+
let (line, column) = position.split_once(':')?;
|
|
62
|
+
Some((line.parse().ok()?, column.parse().ok()?))
|
|
63
|
+
}
|
|
64
|
+
|
|
37
65
|
pub fn argument_error(ruby: &Ruby, cause: impl Display) -> Error {
|
|
38
66
|
Error::new(ruby.exception_arg_error(), cause.to_string())
|
|
39
67
|
}
|
data/ext/oxigraph/src/query.rs
CHANGED
|
@@ -11,7 +11,7 @@ use oxigraph::store::Store;
|
|
|
11
11
|
use spargebra::algebra::{AggregateExpression, Expression, GraphPattern, OrderExpression};
|
|
12
12
|
use spargebra::SparqlParser;
|
|
13
13
|
|
|
14
|
-
use crate::error::{argument_error, error, named_error};
|
|
14
|
+
use crate::error::{argument_error, error, named_error, query_syntax_error};
|
|
15
15
|
use crate::model::{frozen, term_to_value, triple_to_value};
|
|
16
16
|
|
|
17
17
|
/// A parsed SPARQL query, exposed to Ruby as `Oxigraph::Query`.
|
|
@@ -25,13 +25,14 @@ pub struct Query {
|
|
|
25
25
|
impl Query {
|
|
26
26
|
fn parse(ruby: &Ruby, arguments: &[Value]) -> Result<Obj<Self>, Error> {
|
|
27
27
|
let (text, parser) = text_and_parser(ruby, arguments)?;
|
|
28
|
-
|
|
28
|
+
let query = Self::from_text(ruby, parser, &text)?;
|
|
29
|
+
Ok(frozen(ruby, query))
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
fn from_text(ruby: &Ruby, parser: SparqlParser, text: &str) -> Result<Self, Error> {
|
|
32
33
|
let inner = parser
|
|
33
34
|
.parse_query(text)
|
|
34
|
-
.map_err(|cause|
|
|
35
|
+
.map_err(|cause| query_syntax_error(ruby, &cause))?;
|
|
35
36
|
let service = pattern_has_service(pattern_of(&inner));
|
|
36
37
|
Ok(Self { inner, service })
|
|
37
38
|
}
|
|
@@ -79,7 +80,7 @@ impl Update {
|
|
|
79
80
|
let (text, parser) = text_and_parser(ruby, arguments)?;
|
|
80
81
|
let inner = parser
|
|
81
82
|
.parse_update(&text)
|
|
82
|
-
.map_err(|cause|
|
|
83
|
+
.map_err(|cause| query_syntax_error(ruby, &cause))?;
|
|
83
84
|
Ok(frozen(ruby, Self { inner }))
|
|
84
85
|
}
|
|
85
86
|
|
|
@@ -95,7 +96,8 @@ impl Update {
|
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
/// Reads the arguments that `Query.parse` and `Update.parse` share: the text,
|
|
98
|
-
/// then `base_iri:` and `prefixes:`.
|
|
99
|
+
/// then `base_iri:` and `prefixes:`. Returns the text and a parser that knows
|
|
100
|
+
/// the base IRI and the prefixes.
|
|
99
101
|
fn text_and_parser(ruby: &Ruby, arguments: &[Value]) -> Result<(String, SparqlParser), Error> {
|
|
100
102
|
let arguments = scan_args::scan_args::<(String,), (), (), (), RHash, ()>(arguments)?;
|
|
101
103
|
let keywords = scan_args::get_kwargs::<
|
data/lib/oxigraph/errors.rb
CHANGED
|
@@ -16,9 +16,18 @@ module Oxigraph
|
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
# Raised when a SPARQL query or update does not parse.
|
|
20
|
-
# where
|
|
21
|
-
|
|
19
|
+
# Raised when a SPARQL query or update does not parse. Its line and column
|
|
20
|
+
# say where, counted from one; both are nil for an error that has no
|
|
21
|
+
# position.
|
|
22
|
+
class QuerySyntaxError < Error
|
|
23
|
+
attr_reader :line, :column
|
|
24
|
+
|
|
25
|
+
def initialize(message = nil, line: nil, column: nil)
|
|
26
|
+
super(message)
|
|
27
|
+
@line = line
|
|
28
|
+
@column = column
|
|
29
|
+
end
|
|
30
|
+
end
|
|
22
31
|
|
|
23
32
|
# Raised when a query fails while it runs.
|
|
24
33
|
class QueryEvaluationError < Error; end
|
data/lib/oxigraph/version.rb
CHANGED