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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c81c123e08cd03068ed0207dfc1e35d9f7434bac83027ff53e7864f770a248df
4
- data.tar.gz: 2242e741137d11286ce93f08548a13ece23020b15efed7076cf1ea5af6491077
3
+ metadata.gz: f336c1daaf4b5dc7fa7bd60329d9e104c602d799d51d57e4c64ec5f4a62fab5b
4
+ data.tar.gz: 3a33a537716ce3a1a2cce3e38e9d3cda6a92be3b58d2e8df31544a10ae764da0
5
5
  SHA512:
6
- metadata.gz: 9e80c131dc6636ae109bbf6f766da62c79e0d9d2a7c92ff6f7f3231ac2dc404322fb53bc675aae4044417d58f402e848826dbfc67714df8032fbf512f6a2b40c
7
- data.tar.gz: 98b6fed72816febdc41ceeec9fe70ce6a7c2b234d111195d425f5b51ad5a931f392a45c075103f2255a9faf00daa1c370b85a3b7eaa0f84f93f398ddc2e33f6a
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`, `Oxigraph::QueryEvaluationError`, and `Oxigraph::UnsupportedError`.
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
- The gem is not published to RubyGems yet. Build it from source by pointing Bundler at a commit of this repository:
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", git: "https://github.com/nertzy/oxigraph-ruby", ref: "<commit SHA>"
12
+ gem "oxigraph", "~> 0.1.0"
13
13
  ```
14
14
 
15
- Building needs Ruby 3.4 or newer and a [Rust toolchain](https://rustup.rs) at version 1.87 or newer.
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`, whose message gives the line and column. A query that fails while it runs raises `Oxigraph::QueryEvaluationError`.
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
@@ -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
  }
@@ -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
- Ok(frozen(ruby, Self::from_text(ruby, parser, &text)?))
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| named_error(ruby, "QuerySyntaxError", 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| named_error(ruby, "QuerySyntaxError", 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::<
@@ -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. The message says
20
- # where.
21
- class QuerySyntaxError < Error; end
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oxigraph
4
- VERSION = "0.1.0.rc2"
4
+ VERSION = "0.1.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxigraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Hutchins