Skip to content

Commit

Permalink
Expression parser (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot authored Jul 7, 2022
1 parent 38caee9 commit ba16c25
Show file tree
Hide file tree
Showing 14 changed files with 1,631 additions and 275 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"command-line-args": "^5.2.0",
"command-line-usage": "^6.1.1",
"dedent-js": "^1.0.1",
"ecmarkdown": "^7.0.0",
"ecmarkdown": "^7.1.0",
"eslint-formatter-codeframe": "^7.32.1",
"fast-glob": "^3.2.7",
"grammarkdown": "^3.2.0",
Expand Down
2 changes: 2 additions & 0 deletions src/Algorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export default class Algorithm extends Builder {

// @ts-ignore
node.ecmarkdownTree = emdTree;
// @ts-ignore
node.originalHtml = innerHTML;

if (spec.opts.lintSpec && spec.locate(node) != null && !node.hasAttribute('example')) {
const clause = clauseStack[clauseStack.length - 1];
Expand Down
20 changes: 20 additions & 0 deletions src/Biblio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ export default class Biblio {
return this.lookup(ns, env => env._byAoid[aoid]);
}

getOpNames(ns: string): Set<string> {
const out = new Set<string>();
let current = this._nsToEnvRec[ns];
while (current) {
const entries = current._byType['op'] || [];
for (const entry of entries) {
out.add(entry.aoid);
}
current = current._parent;
}
return out;
}

getDefinedWords(ns: string): Record<string, AlgorithmBiblioEntry | TermBiblioEntry> {
const result = Object.create(null);

Expand Down Expand Up @@ -316,9 +329,16 @@ export type Signature = {
optionalParameters: Parameter[];
return: null | Type;
};
export type AlgorithmType =
| 'abstract operation'
| 'host-defined abstract operation'
| 'implementation-defined abstract operation'
| 'syntax-directed operation'
| 'numeric method';
export interface AlgorithmBiblioEntry extends BiblioEntryBase {
type: 'op';
aoid: string;
kind?: AlgorithmType;
signature: null | Signature;
effects: string[];
/*@internal*/ _node?: Element;
Expand Down
33 changes: 20 additions & 13 deletions src/Clause.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type Note from './Note';
import type Example from './Example';
import type Spec from './Spec';
import type { PartialBiblioEntry, Signature, Type } from './Biblio';
import type { AlgorithmType, PartialBiblioEntry, Signature, Type } from './Biblio';
import type { Context } from './Context';

import { ParseError, TypeParser } from './type-parser';
Expand All @@ -15,6 +15,15 @@ import {
} from './header-parser';
import { offsetToLineAndColumn } from './utils';

const aoidTypes = [
'abstract operation',
'sdo',
'syntax-directed operation',
'host-defined abstract operation',
'implementation-defined abstract operation',
'numeric method',
];

export function extractStructuredHeader(header: Element): Element | null {
const dl = header.nextElementSibling;
if (dl == null || dl.tagName !== 'DL' || !dl.classList.contains('header')) {
Expand Down Expand Up @@ -211,18 +220,7 @@ export default class Clause extends Builder {
node: this.node,
attr: 'aoid',
});
} else if (
name != null &&
type != null &&
[
'abstract operation',
'sdo',
'syntax-directed operation',
'host-defined abstract operation',
'implementation-defined abstract operation',
'numeric method',
].includes(type)
) {
} else if (name != null && type != null && aoidTypes.includes(type)) {
this.node.setAttribute('aoid', name);
this.aoid = name;
}
Expand Down Expand Up @@ -350,10 +348,19 @@ export default class Clause extends Builder {
});
} else {
const signature = clause.signature;
let kind: AlgorithmType | undefined =
clause.type != null && aoidTypes.includes(clause.type)
? (clause.type as AlgorithmType)
: undefined;
// @ts-ignore
if (kind === 'sdo') {
kind = 'syntax-directed operation';
}
const op: PartialBiblioEntry = {
type: 'op',
aoid: clause.aoid,
refId: clause.id,
kind,
signature,
effects: clause.effects,
_node: clause.node,
Expand Down
Loading

0 comments on commit ba16c25

Please sign in to comment.