-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64e7d73
commit 1c8da8d
Showing
18 changed files
with
330 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright © 2024–now Jitse De Smet | ||
Comunica Association and Ghent University – imec, Belgium | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
best not unpack the context entry since its contents are reset between parsing runs. | ||
You should thus only have the context object itself withing your closure. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# TRAQULA parser engine for SPARQL 1.1 + Adjust | ||
|
||
TRAQULA Sparql 1.1 Adjust is a SPARQL 1.1 query parser that also parses the [builtin function ADJUST](https://github.com/w3c/sparql-dev/blob/main/SEP/SEP-0002/sep-0002.md) for TypeScript. | ||
Simple grammar extension of [TRAQULA engine-sparql-1-1](https://github.com/comunica/traqula/tree/main/engines/engine-sparql-1-1) | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @traqula/engine-sparql-1-1 | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
yarn add @traqula/engine-sparql-1-1 | ||
``` | ||
|
||
## Import | ||
|
||
Either through ESM import: | ||
|
||
```javascript | ||
import { Sparql11AdjustParser } from '@traqula/engine-sparql-1-1-adjust'; | ||
``` | ||
|
||
_or_ CJS require: | ||
|
||
```javascript | ||
const Sparql11AdjustParser = require('@traqula/engine-sparql-1-1-adjust').Sparql11AdjustParser; | ||
``` | ||
|
||
## Usage | ||
|
||
This package contains a `Sparql11AdjustParser` that is able to parse SPARQL 1.1 queries including the [builtin function ADJUST](https://github.com/w3c/sparql-dev/blob/main/SEP/SEP-0002/sep-0002.md): | ||
|
||
```typescript | ||
const parser = new Sparql11Parser(); | ||
const abstractSyntaxTree = parser.parse(` | ||
SELECT ?s ?p (ADJUST(?o, "-PT10H"^^<http://www.w3.org/2001/XMLSchema#dayTimeDuration>) as ?adjusted) WHERE { | ||
?s ?p ?o | ||
} | ||
`); | ||
``` | ||
|
||
This parser is a simple grammar extension to the [engine-sparql-1-1](https://github.com/comunica/traqula/tree/main/engines/engine-sparql-1-1). | ||
As such, most, if not all, documentation of that parser holds for this one too. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
"files": [ | ||
"lib/**/*.d.ts", | ||
"lib/**/*.js", | ||
"lib/**/*.cjs", | ||
"lib/**/*.js.map" | ||
], | ||
"engines": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# TRAQULA parser engine for SPARQL 1.1 | ||
|
||
TRAQULA Sparql 1.1 is a SPARQL 1.1 query parser for TypeScript. | ||
|
||
|
||
## Installation | ||
|
||
```bash | ||
npm install @traqula/engine-sparql-1-1 | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
yarn add @traqula/engine-sparql-1-1 | ||
``` | ||
|
||
## Import | ||
|
||
Either through ESM import: | ||
|
||
```javascript | ||
import { Sparql11Parser } from '@traqula/engine-sparql-1-1'; | ||
``` | ||
|
||
_or_ CJS require: | ||
|
||
```javascript | ||
const Sparql11Parser = require('@traqula/engine-sparql-1-1').Sparql11Parser; | ||
``` | ||
|
||
## Usage | ||
|
||
This package contains a `Sparql11Parser` that is able to parse SPARQL 1.1 queries: | ||
|
||
```typescript | ||
const parser = new Sparql11Parser(); | ||
const abstractSyntaxTree = parser.parse('SELECT * { ?s ?p ?o }'); | ||
``` | ||
|
||
The package also contains multiple parserBuilders. | ||
These builders can be used either to consume to a parser, | ||
or to usage as a starting point for your own grammar. | ||
|
||
### Consuming parserBuilder to parser | ||
|
||
At the core of TRAQULA, parser are constructed of multiple parser rules that have been consumed by the builder. | ||
This consumption returns a parser that can parse strings starting from any grammar rule. | ||
|
||
The `sparql11ParserBuilder` for example contains both the rules `queryOrUpdate` and `path` (among many others). | ||
The consumption of `sparql11ParserBuilder` will thus return an object that has function `queryOrUpdate` and `path`. | ||
Calling those function with a string will cause that string to be parsed using the appropriate rule as a starting rule. | ||
|
||
```typescript | ||
const parser: { | ||
queryOrUpdate: (input: string) => SparqlQuery; | ||
path: (input: string) => PropertyPath | IriTerm; | ||
} = sparql11ParserBuilder.consumeToParser({ | ||
tokenVocabulary: l.sparql11Tokens.build(), | ||
}, { | ||
parseMode: new Set([ gram.canParseVars, gram.canCreateBlankNodes ]), | ||
dataFactory: new DataFactory(), | ||
}); | ||
``` | ||
|
||
### Constructing a new grammar from an existing one | ||
|
||
The builders can also be used to construct new parsers. | ||
As an example the `triplesBlockParserBuilder` is created by merging the `objectListBuilder` with some new rules. | ||
|
||
## Configuration | ||
|
||
Optionally, the following parameters can be set in the `Sparql11Parser` constructor: | ||
|
||
* `dataFactory`: A custom [RDFJS DataFactory](http://rdf.js.org/#datafactory-interface) to construct terms and triples. _(Default: `require('@rdfjs/data-model')`)_ | ||
* `baseIRI`: An initial default base IRI. _(Default: none)_ | ||
* `prefixes`: An initial map of prefixes | ||
* `skipValidation`: Can be used to disable the validation that used variables in a select clause are in scope. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"files": [ | ||
"lib/**/*.d.ts", | ||
"lib/**/*.js", | ||
"lib/**/*.cjs", | ||
"lib/**/*.js.map" | ||
], | ||
"engines": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# TRAQULA parser engine for SPARQL 1.2 | ||
|
||
TRAQULA Sparql 1.2 is a SPARQL 1.2 query parser for TypeScript. | ||
It is a grammar extension of [TRAQULA engine-sparql-1-1](https://github.com/comunica/traqula/tree/main/engines/engine-sparql-1-1) | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @traqula/engine-sparql-1-1 | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
yarn add @traqula/engine-sparql-1-1 | ||
``` | ||
|
||
## Import | ||
|
||
Either through ESM import: | ||
|
||
```javascript | ||
import { Sparql12Parser } from '@traqula/engine-sparql-1-2'; | ||
``` | ||
|
||
_or_ CJS require: | ||
|
||
```javascript | ||
const Sparql12Parser = require('@traqula/engine-sparql-1-2').Sparql12Parser; | ||
``` | ||
|
||
## Usage | ||
|
||
This package contains a `Sparql12Parser` that is able to parse SPARQL 1.2 queries: | ||
|
||
```typescript | ||
const parser = new Sparql12Parser(); | ||
const abstractSyntaxTree = parser.parse('SELECT * { ?s ?p ?o }'); | ||
``` | ||
|
||
This parser is a simple grammar extension to the [engine-sparql-1-1](https://github.com/comunica/traqula/tree/main/engines/engine-sparql-1-1). | ||
As such, most, if not all, documentation of that parser holds for this one too. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"files": [ | ||
"lib/**/*.d.ts", | ||
"lib/**/*.js", | ||
"lib/**/*.cjs", | ||
"lib/**/*.js.map" | ||
], | ||
"engines": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.