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

Expression parser #464

Merged
merged 9 commits into from
Jul 7, 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
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