Skip to content

Commit ba16c25

Browse files
authored
Expression parser (#464)
1 parent 38caee9 commit ba16c25

14 files changed

+1631
-275
lines changed

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"command-line-args": "^5.2.0",
4848
"command-line-usage": "^6.1.1",
4949
"dedent-js": "^1.0.1",
50-
"ecmarkdown": "^7.0.0",
50+
"ecmarkdown": "^7.1.0",
5151
"eslint-formatter-codeframe": "^7.32.1",
5252
"fast-glob": "^3.2.7",
5353
"grammarkdown": "^3.2.0",

src/Algorithm.ts

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export default class Algorithm extends Builder {
4949

5050
// @ts-ignore
5151
node.ecmarkdownTree = emdTree;
52+
// @ts-ignore
53+
node.originalHtml = innerHTML;
5254

5355
if (spec.opts.lintSpec && spec.locate(node) != null && !node.hasAttribute('example')) {
5456
const clause = clauseStack[clauseStack.length - 1];

src/Biblio.ts

+20
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ export default class Biblio {
109109
return this.lookup(ns, env => env._byAoid[aoid]);
110110
}
111111

112+
getOpNames(ns: string): Set<string> {
113+
const out = new Set<string>();
114+
let current = this._nsToEnvRec[ns];
115+
while (current) {
116+
const entries = current._byType['op'] || [];
117+
for (const entry of entries) {
118+
out.add(entry.aoid);
119+
}
120+
current = current._parent;
121+
}
122+
return out;
123+
}
124+
112125
getDefinedWords(ns: string): Record<string, AlgorithmBiblioEntry | TermBiblioEntry> {
113126
const result = Object.create(null);
114127

@@ -316,9 +329,16 @@ export type Signature = {
316329
optionalParameters: Parameter[];
317330
return: null | Type;
318331
};
332+
export type AlgorithmType =
333+
| 'abstract operation'
334+
| 'host-defined abstract operation'
335+
| 'implementation-defined abstract operation'
336+
| 'syntax-directed operation'
337+
| 'numeric method';
319338
export interface AlgorithmBiblioEntry extends BiblioEntryBase {
320339
type: 'op';
321340
aoid: string;
341+
kind?: AlgorithmType;
322342
signature: null | Signature;
323343
effects: string[];
324344
/*@internal*/ _node?: Element;

src/Clause.ts

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type Note from './Note';
22
import type Example from './Example';
33
import type Spec from './Spec';
4-
import type { PartialBiblioEntry, Signature, Type } from './Biblio';
4+
import type { AlgorithmType, PartialBiblioEntry, Signature, Type } from './Biblio';
55
import type { Context } from './Context';
66

77
import { ParseError, TypeParser } from './type-parser';
@@ -15,6 +15,15 @@ import {
1515
} from './header-parser';
1616
import { offsetToLineAndColumn } from './utils';
1717

18+
const aoidTypes = [
19+
'abstract operation',
20+
'sdo',
21+
'syntax-directed operation',
22+
'host-defined abstract operation',
23+
'implementation-defined abstract operation',
24+
'numeric method',
25+
];
26+
1827
export function extractStructuredHeader(header: Element): Element | null {
1928
const dl = header.nextElementSibling;
2029
if (dl == null || dl.tagName !== 'DL' || !dl.classList.contains('header')) {
@@ -211,18 +220,7 @@ export default class Clause extends Builder {
211220
node: this.node,
212221
attr: 'aoid',
213222
});
214-
} else if (
215-
name != null &&
216-
type != null &&
217-
[
218-
'abstract operation',
219-
'sdo',
220-
'syntax-directed operation',
221-
'host-defined abstract operation',
222-
'implementation-defined abstract operation',
223-
'numeric method',
224-
].includes(type)
225-
) {
223+
} else if (name != null && type != null && aoidTypes.includes(type)) {
226224
this.node.setAttribute('aoid', name);
227225
this.aoid = name;
228226
}
@@ -350,10 +348,19 @@ export default class Clause extends Builder {
350348
});
351349
} else {
352350
const signature = clause.signature;
351+
let kind: AlgorithmType | undefined =
352+
clause.type != null && aoidTypes.includes(clause.type)
353+
? (clause.type as AlgorithmType)
354+
: undefined;
355+
// @ts-ignore
356+
if (kind === 'sdo') {
357+
kind = 'syntax-directed operation';
358+
}
353359
const op: PartialBiblioEntry = {
354360
type: 'op',
355361
aoid: clause.aoid,
356362
refId: clause.id,
363+
kind,
357364
signature,
358365
effects: clause.effects,
359366
_node: clause.node,

0 commit comments

Comments
 (0)