@kurrawongai/codemirror-lang-sparql12 0.2.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.
- package/LICENSE +21 -0
- package/NOTICE +25 -0
- package/README.md +40 -0
- package/dist/complete.d.ts +51 -0
- package/dist/highlight.d.ts +13 -0
- package/dist/index.cjs +968 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +953 -0
- package/dist/index.js.map +1 -0
- package/dist/keywords.d.ts +6 -0
- package/package.json +57 -0
- package/src/complete.ts +202 -0
- package/src/grammar.d.ts +13 -0
- package/src/highlight.ts +83 -0
- package/src/index.ts +98 -0
- package/src/keywords.ts +39 -0
- package/src/sparql.grammar +486 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 codemirror-lang-rdf contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
codemirror-lang-rdf
|
|
2
|
+
Copyright (c) 2026 codemirror-lang-rdf contributors
|
|
3
|
+
|
|
4
|
+
This product includes work derived from:
|
|
5
|
+
|
|
6
|
+
codemirror-lang-turtle and codemirror-lang-sparql
|
|
7
|
+
Copyright (c) aatauil
|
|
8
|
+
MIT licensed — https://github.com/aatauil
|
|
9
|
+
|
|
10
|
+
The Turtle and SPARQL grammars here are rewrites for the RDF 1.2 and
|
|
11
|
+
SPARQL 1.2 specifications of the approach those packages take.
|
|
12
|
+
|
|
13
|
+
The vendored conformance corpora under packages/*/test/corpus are:
|
|
14
|
+
|
|
15
|
+
Copyright (c) W3C
|
|
16
|
+
Distributed under the W3C Test Suite License and the W3C 3-clause BSD
|
|
17
|
+
License. Each corpus directory carries a SOURCE file naming the upstream
|
|
18
|
+
repository and the pinned commit.
|
|
19
|
+
|
|
20
|
+
https://github.com/w3c/rdf-tests
|
|
21
|
+
https://github.com/w3c/data-shapes
|
|
22
|
+
|
|
23
|
+
The attribution above lived in LICENSE until GitHub reported the repository's
|
|
24
|
+
licence as NOASSERTION: licence detection needs that file to match the MIT text
|
|
25
|
+
closely, and an interpolated paragraph is enough to defeat it.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @kurrawongai/codemirror-lang-sparql12
|
|
2
|
+
|
|
3
|
+
SPARQL 1.2 query and update support for CodeMirror 6, with highlighting,
|
|
4
|
+
folding, indentation, and keyword, prefix, and variable completion.
|
|
5
|
+
|
|
6
|
+
## Get started
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install codemirror @kurrawongai/codemirror-lang-sparql12
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
In your application's browser entry module:
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
import { basicSetup, EditorView } from 'codemirror';
|
|
16
|
+
import { sparql } from '@kurrawongai/codemirror-lang-sparql12';
|
|
17
|
+
|
|
18
|
+
new EditorView({
|
|
19
|
+
parent: document.body,
|
|
20
|
+
doc: 'SELECT ?s ?p ?o WHERE { ?s ?p ?o }',
|
|
21
|
+
extensions: [basicSetup, sparql()],
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The parser supports editing incomplete queries. It accepts some invalid
|
|
26
|
+
syntax and does not check query semantics. Use a separate validator before
|
|
27
|
+
executing a query when validation is required.
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
- [Usage and completion](https://github.com/kurrawong/codemirror-lang-rdf/blob/main/docs/usage.md)
|
|
32
|
+
- [API reference](https://github.com/kurrawong/codemirror-lang-rdf/blob/main/docs/api.md#sparql)
|
|
33
|
+
- [Highlight tags](https://github.com/kurrawong/codemirror-lang-rdf/blob/main/docs/highlight-tags.md)
|
|
34
|
+
- [Conformance and corpus revision](https://github.com/kurrawong/codemirror-lang-rdf/blob/main/docs/conformance.md)
|
|
35
|
+
|
|
36
|
+
## Licence
|
|
37
|
+
|
|
38
|
+
MIT. The grammar builds on the approach used by
|
|
39
|
+
[aatauil/codemirror-lang-sparql](https://github.com/aatauil/codemirror-lang-sparql)
|
|
40
|
+
(MIT). Vendored W3C tests use the W3C Test Suite License and W3C 3-clause BSD License.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { CompletionContext, CompletionResult } from '@codemirror/autocomplete';
|
|
2
|
+
import type { EditorState } from '@codemirror/state';
|
|
3
|
+
/** A prefix label (without the colon) mapped to the IRI it expands to. */
|
|
4
|
+
export type PrefixMap = Record<string, string>;
|
|
5
|
+
/** Where the editor may look for prefixes beyond the document's own declarations. */
|
|
6
|
+
export type PrefixSource = PrefixMap | ((state: EditorState) => PrefixMap);
|
|
7
|
+
export interface CompletionOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Prefixes to offer even when the document has not declared them — an
|
|
10
|
+
* application's prefix manager, typically. Document declarations win on
|
|
11
|
+
* conflict, because what the document says is what the document means.
|
|
12
|
+
*/
|
|
13
|
+
prefixSource?: PrefixSource;
|
|
14
|
+
}
|
|
15
|
+
export declare const sparqlKeywords: readonly string[];
|
|
16
|
+
export declare const sparqlFunctions: readonly string[];
|
|
17
|
+
export declare const srlKeywords: readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* The prefixes declared by the document itself, read from the syntax tree.
|
|
20
|
+
*
|
|
21
|
+
* Works the same for a query, an update and an SRL rule set, because all three
|
|
22
|
+
* share the `PrefixDecl` production.
|
|
23
|
+
*/
|
|
24
|
+
export declare function documentPrefixes(state: EditorState): PrefixMap;
|
|
25
|
+
/**
|
|
26
|
+
* Every variable the document already mentions, with its sigil.
|
|
27
|
+
*
|
|
28
|
+
* Offering these is the completion that earns its keep most often: a query
|
|
29
|
+
* names the same variable in a pattern, a filter and a projection, and typing
|
|
30
|
+
* it identically three times is where the typos are.
|
|
31
|
+
*/
|
|
32
|
+
export declare function documentVariables(state: EditorState): string[];
|
|
33
|
+
/** Every prefix the editor knows about: the external source, overlaid by the document's. */
|
|
34
|
+
export declare function knownPrefixes(state: EditorState, options?: CompletionOptions): PrefixMap;
|
|
35
|
+
export interface CompletionSourceOptions extends CompletionOptions {
|
|
36
|
+
/** Which keyword set to offer. SRL adds its own and drops the update ones. */
|
|
37
|
+
dialect?: 'sparql' | 'srl';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Completion for SPARQL and SRL.
|
|
41
|
+
*
|
|
42
|
+
* Deliberately context-light on *keywords*: it offers the whole set wherever a
|
|
43
|
+
* word is being typed rather than working out whether the cursor is in a
|
|
44
|
+
* pattern or a projection. In an error-tolerant tree a half-typed clause
|
|
45
|
+
* rarely has a reliable position to read, and a wrong context is worse than a
|
|
46
|
+
* slightly long list — CodeMirror filters by what has been typed anyway.
|
|
47
|
+
*
|
|
48
|
+
* Prefixes and variables are the opposite: they come from the document, so
|
|
49
|
+
* they are always exactly right.
|
|
50
|
+
*/
|
|
51
|
+
export declare function sparqlCompletionSource(options?: CompletionSourceOptions): (context: CompletionContext) => CompletionResult | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NodePropSource } from '@lezer/common';
|
|
2
|
+
/**
|
|
3
|
+
* The shared highlight-tag table, SPARQL and SRL half.
|
|
4
|
+
*
|
|
5
|
+
* `docs/highlight-tags.md` is the canonical table; the repository-root test
|
|
6
|
+
* asserts this and the Turtle grammar agree on every shared construct, so an
|
|
7
|
+
* application can keep one `HighlightStyle` for all six languages.
|
|
8
|
+
*
|
|
9
|
+
* The keyword rule is built from `KEYWORD_NODE_NAMES` rather than written out.
|
|
10
|
+
* A hand-written list of 125 node names would go stale the first time a
|
|
11
|
+
* keyword was added, and silently: the new keyword would simply be uncoloured.
|
|
12
|
+
*/
|
|
13
|
+
export declare const sparqlHighlighting: NodePropSource;
|