-
Notifications
You must be signed in to change notification settings - Fork 74
add optional marker for early exits in algorithm steps #683
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
base: main
Are you sure you want to change the base?
Changes from all commits
52e3924
f7cdda3
37ab4a8
c6ee64b
3368991
77f166c
8a0973b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -78,6 +78,28 @@ export default class Algorithm extends Builder { | |||||||||||||||||||||||||||||||||||||||||
| html = html.replace(/[ \t]+([»}])/g, ' $1'); | ||||||||||||||||||||||||||||||||||||||||||
| node.innerHTML = html; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // mark steps containing early exits (return/throw/?) with the early-exit class | ||||||||||||||||||||||||||||||||||||||||||
| const earlyExitIndicator = /\b(?:return|throw)\b|[\s(]\?\s/i; | ||||||||||||||||||||||||||||||||||||||||||
| // these are macros in ECMA-262 that expand to steps that include a return/throw/? | ||||||||||||||||||||||||||||||||||||||||||
| const earlyExitMacro = /\bIfAbrupt(?:CloseIterator|CloseAsyncIterator|RejectPromise)\(/; | ||||||||||||||||||||||||||||||||||||||||||
| const note = /^(?:NOTE|Assert): /; | ||||||||||||||||||||||||||||||||||||||||||
| const acRe = /\ba new Abstract Closure\b/i; | ||||||||||||||||||||||||||||||||||||||||||
| for (const ol of node.querySelectorAll('ol')) { | ||||||||||||||||||||||||||||||||||||||||||
| const isTopLevel = ol.parentElement === node; | ||||||||||||||||||||||||||||||||||||||||||
| const isACBody = | ||||||||||||||||||||||||||||||||||||||||||
| !isTopLevel && | ||||||||||||||||||||||||||||||||||||||||||
| ol.parentElement?.tagName === 'LI' && | ||||||||||||||||||||||||||||||||||||||||||
| acRe.test(ownTextContent(ol.parentElement)); | ||||||||||||||||||||||||||||||||||||||||||
| const items = ol.children; | ||||||||||||||||||||||||||||||||||||||||||
| for (let i = 0; i < items.length; i++) { | ||||||||||||||||||||||||||||||||||||||||||
| if (i === items.length - 1 && (isTopLevel || isACBody)) continue; | ||||||||||||||||||||||||||||||||||||||||||
| const text = ownTextContent(items[i]); | ||||||||||||||||||||||||||||||||||||||||||
| if ((earlyExitIndicator.test(text) || earlyExitMacro.test(text)) && !note.test(text)) { | ||||||||||||||||||||||||||||||||||||||||||
| items[i].classList.add('early-exit'); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+86
to
+100
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const labeledStepEntries: StepBiblioEntry[] = []; | ||||||||||||||||||||||||||||||||||||||||||
| const replaces = node.getAttribute('replaces-step'); | ||||||||||||||||||||||||||||||||||||||||||
| if (replaces) { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -153,6 +175,17 @@ export default class Algorithm extends Builder { | |||||||||||||||||||||||||||||||||||||||||
| static readonly elements = ['EMU-ALG'] as const; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // get text content of an element excluding nested <ol> children | ||||||||||||||||||||||||||||||||||||||||||
| function ownTextContent(el: Element): string { | ||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depending on whether #684 lands before this, this function may need to be pulled from the helper in utils.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #684 did land first, and I have a complaint about the |
||||||||||||||||||||||||||||||||||||||||||
| let text = ''; | ||||||||||||||||||||||||||||||||||||||||||
| for (const child of el.childNodes) { | ||||||||||||||||||||||||||||||||||||||||||
| if (child.nodeType === 3) { | ||||||||||||||||||||||||||||||||||||||||||
| text += child.textContent; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| return text; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| function getStepNumbers(item: Element) { | ||||||||||||||||||||||||||||||||||||||||||
| const { indexOf } = Array.prototype; | ||||||||||||||||||||||||||||||||||||||||||
| const counts = []; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.