Skip to content

Commit

Permalink
add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jitsedesmet committed Jan 10, 2025
1 parent c52eebd commit 178a5fd
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 58 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 18.x
- 20.x
- 22.x
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v4
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn test

spec:
runs-on: ubuntu-latest
strategy:
matrix:
spec:
- spec:base
- spec:query
- spec:update
- spec:all
- spec:earl
node-version:
- 22.x
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v4
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn ${{ matrix.spec }}
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
"test": "yarn build && vitest test --run",
"bench": "yarn build && vitest bench --run",
"spec:base": "rdf-test-suite out/parser.cjs http://w3c.github.io/rdf-tests/sparql/sparql11/manifest-all.ttl -c .rdf-test-suite-cache/",
"spec:query": "npm run spec:base -- -s http://www.w3.org/TR/sparql11-query/",
"spec:update": "npm run spec:base -- -s http://www.w3.org/TR/sparql11-update/",
"spec:star": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-star/tests/sparql/syntax/manifest.jsonld -i '{ \"sparqlStar\": true }' -c .rdf-test-suite-cache/",
"spec:earl:query": "npm run spec:query --silent -- -o earl -p spec/earl-meta.json > spec/earl-query.ttl",
"spec:earl:update": "npm run spec:update --silent -- -o earl -p spec/earl-meta.json > spec/earl-update.ttl",
"spec:earl:star": "npm run spec:star --silent -- -o earl -p spec/earl-meta.json > spec/earl-star.ttl",
"spec:all": "npm run spec:base && npm run spec:query && npm run spec:update && npm run spec:star",
"spec:earl": "npm run spec:earl:query && npm run spec:earl:update && npm run spec:earl:star"
"spec:query": "yarn spec:base -- -s http://www.w3.org/TR/sparql11-query/",
"spec:update": "yarn spec:base -- -s http://www.w3.org/TR/sparql11-update/",
"spec:earl:query": "yarn spec:query --silent -- -o earl -p spec/earl-meta.json > spec/earl-query.ttl",
"spec:earl:update": "yarn spec:update --silent -- -o earl -p spec/earl-meta.json > spec/earl-update.ttl",
"spec:all": "yarn spec:base && yarn spec:query && yarn spec:update",
"spec:earl": "yarn spec:earl:query && yarn spec:earl:update"
},
"dependencies": {
"chevrotain": "^11.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/builder/parserBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class Builder<Names extends string, RuleDefs extends RuleDefMap<Names>> {
parser.input = lexResult.tokens;
const result = parser[rule.name](...args);
if (parser.errors.length > 0) {
console.log(lexResult.tokens);
// Console.log(lexResult.tokens);
throw new Error(`Parse error on line ${parser.errors.map(x => x.token.startLine).join(', ')}
${parser.errors.map(x => `${x.token.startLine}: ${x.message}`).join('\n')}`);
}
Expand Down
29 changes: 24 additions & 5 deletions src/grammar/sparql11/queryUnit/queryUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ export const selectQuery: RuleDef<'selectQuery', Omit<SelectQuery, HandledByBase

ACTION(() => {
if (selectVal.variables.length === 1 && selectVal.variables[0] instanceof Wildcard) {
if (modifier.group !== undefined) {
throw new Error('GROUP BY not allowed with wildcard');
}
return;
}
const variables = <Variable[]> selectVal.variables;
Expand Down Expand Up @@ -262,19 +265,35 @@ export const selectClause: RuleDef<'selectClause', ISelectClause> = <const> {
return [ new Wildcard() ];
} },
{ ALT: () => {
const usedVars: VariableTerm[] = [];
const result: Variable[] = [];
AT_LEAST_ONE(() => OR3([
{ ALT: () => result.push(SUBRULE1(var_)) },
{ ALT: () => {
const raw = SUBRULE1(var_);
ACTION(() => {
if (usedVars.some(v => v.equals(raw))) {
throw new Error(`Variable ${raw.value} used more than once in SELECT clause`);
}
usedVars.push(raw);
result.push(raw);
});
} },
{ ALT: () => {
CONSUME(l.symbols.LParen);
const expr = SUBRULE(expression);
CONSUME(l.as);
const variable = SUBRULE2(var_);
CONSUME(l.symbols.RParen);
result.push({
expression: expr,
variable,
} satisfies VariableExpression);
ACTION(() => {
if (usedVars.some(v => v.equals(variable))) {
throw new Error(`Variable ${variable.value} used more than once in SELECT clause`);
}
usedVars.push(variable);
result.push({
expression: expr,
variable,
} satisfies VariableExpression);
});
} },
]));
return result;
Expand Down
Empty file.
2 changes: 0 additions & 2 deletions src/parser/sparql11/Sparql11Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ const queryOrUpdate: RuleDef<'queryOrUpdate', Query | Update | Pick<Update, 'bas
{ ALT: () => SUBRULE(describeQuery) },
{ ALT: () => SUBRULE(askQuery) },
]);
// TODO: tackle variable scope of select: you can only fail on note 12 after parsing the whole query.
// As such, you can use the context entry skipValidation. (So you can test partial queries)
const values = SUBRULE(valuesClause);
return ACTION(() => (<Query>{
...prologueValues,
Expand Down
4 changes: 2 additions & 2 deletions test/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ describe('a SPARQL parser', () => {

describe('confirms to SPARQL tests', () => {
testPositiveQueriesInDir('./test/statics/sparql', [
[ 'SPARQL 1.1 parser', new Sparql11Parser({ baseIRI: 'http://example.org/', prefixes: { ex: 'http://example.org/' }}) ],
// [ 'SPARQL 1.2 parser', new Sparql12Parser({ prefixes: { ex: 'http://example.org/' }}) ],
[ 'SPARQL 1.1 parser', new Sparql11Parser({ prefixes: { ex: 'http://example.org/' }}) ],
[ 'SPARQL 1.2 parser', new Sparql12Parser({ prefixes: { ex: 'http://example.org/' }}) ],
]);
});

Expand Down
31 changes: 0 additions & 31 deletions test/statics/sparql/_bind-fail.json

This file was deleted.

9 changes: 0 additions & 9 deletions test/statics/sparql/_bind-fail.sparql

This file was deleted.

0 comments on commit 178a5fd

Please sign in to comment.