Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suppress error for productions defined in biblio #432

Merged
merged 2 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,12 @@ ${this.opts.multipage ? `<li><span>Navigate to/from multipage</span><code>m</cod
}
const name = production.getAttribute('name')!;
if (!productions.has(name)) {
if (this.biblio.byProductionName(name) != null) {
// in an ideal world we'd keep the full grammar in the biblio so we could check for a matching RHS, not just a matching LHS
// but, we're not in that world
// https://github.com/tc39/ecmarkup/issues/431
continue;
}
this.warn({
type: 'node',
node: grammar,
Expand Down
109 changes: 108 additions & 1 deletion test/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let assert = require('assert');
let emu = require('../lib/ecmarkup');

let { lintLocationMarker: M, positioned, assertError } = require('./utils.js');
let { lintLocationMarker: M, positioned, assertError, assertErrorFree } = require('./utils.js');

describe('errors', () => {
it('no contributors', async () => {
Expand Down Expand Up @@ -932,4 +932,111 @@ ${M} </pre>
{ asImport: 'only' }
);
});

describe('SDO defined over unknown production', () => {
it('unknown production', async () => {
await assertError(
positioned`
<emu-clause id="sec-example" type="sdo">
<h1>Static Semantics: Example</h1>
<dl class='header'></dl>
${M}<emu-grammar>
Foo : \`a\`
</emu-grammar>
<emu-alg>
1. Return *true*.
</emu-alg>
</emu-clause>
`,
{
ruleId: 'grammar-shape',
nodeType: 'emu-grammar',
message: 'could not find definition corresponding to production Foo',
}
);
});

it('unknown rhs', async () => {
await assertError(
positioned`
<emu-grammar type="definition">
Foo : \`b\`
</emu-grammar>

<emu-clause id="sec-example" type="sdo">
<h1>Static Semantics: Example</h1>
<dl class='header'></dl>
${M}<emu-grammar>
Foo : \`a\`
</emu-grammar>
<emu-alg>
1. Return *true*.
</emu-alg>
</emu-clause>
`,
{
ruleId: 'grammar-shape',
nodeType: 'emu-grammar',
message: 'could not find definition for rhs a',
}
);
});

it('negative', async () => {
await assertErrorFree(`
<emu-grammar type="definition">
Foo : \`a\`
</emu-grammar>

<emu-clause id="sec-example" type="sdo">
<h1>Static Semantics: Example</h1>
<dl class='header'></dl>
<emu-grammar>
Foo : \`a\`
</emu-grammar>
<emu-alg>
1. Return *true*.
</emu-alg>
</emu-clause>
`);
});

it('negative: external biblio', async () => {
let upstream = await emu.build(
'root.html',
() => `
<emu-grammar type="definition">
Foo : \`a\`
</emu-grammar>
`,
{
copyright: false,
location: 'https://example.com/spec/',
warn: e => {
console.error('Error:', e);
throw new Error(e.message);
},
}
);
let upstreamBiblio = upstream.exportBiblio();

await assertErrorFree(
`
<emu-clause id="sec-example" type="sdo">
<h1>Static Semantics: Example</h1>
<dl class='header'></dl>
<emu-grammar>
Foo : \`a\`
</emu-grammar>
<emu-alg>
1. Return *true*.
</emu-alg>
</emu-clause>
`,
{
extraBiblios: [upstreamBiblio],
}
);
});
});
});