(node: cheerio.Cheerio<cheerio.Element>, $: cheerio.CheerioAPI)
| 24 | } |
| 25 | |
| 26 | const extract = (node: cheerio.Cheerio<cheerio.Element>, $: cheerio.CheerioAPI) => { |
| 27 | const anchorElement = node.find('div.titlepage > div > div > h3.title > a[name*="jvms-6.5"]').first(); |
| 28 | const nameElement = anchorElement.parent().find('span.emphasis > em'); |
| 29 | const anchor = anchorElement.attr('name')!; |
| 30 | const name = nameElement.text(); |
| 31 | |
| 32 | const [ |
| 33 | operationSection, |
| 34 | formatSection, |
| 35 | _formsSection, |
| 36 | operandStackSection, |
| 37 | descriptionSection, |
| 38 | ] = node.find('div.section').toArray().map(it => $(it)); |
| 39 | |
| 40 | const operation = operationSection.find('p.norm').first().text(); |
| 41 | const format = formatSection.find('div.literallayout > p > span.emphasis > em').toArray().map(it => $(it).text()); |
| 42 | const description = descriptionSection.find('p.norm-dynamic').first(); |
| 43 | // rewrite links to oracle.com |
| 44 | $(description).find('* > a[href*="jvms-"]').toArray().forEach((el) => { |
| 45 | $(el).attr('href', `https://docs.oracle.com/javase/specs/jvms/se18/html/${$(el).attr('href')}`); |
| 46 | }); |
| 47 | |
| 48 | const [stackBefore, stackAfter] = operandStackSection.find('p.norm') |
| 49 | .toArray() |
| 50 | .map(it => $(it)); |
| 51 | |
| 52 | const result: InstructionInfo[] = []; |
| 53 | const hasVariadicMapping = Object.keys(VARIADIC_MAPPINGS).some((pat) => name.endsWith(pat)); |
| 54 | if (hasVariadicMapping) { |
| 55 | for (const [pattern, mappings] of Object.entries(VARIADIC_MAPPINGS)) { |
| 56 | if (name.endsWith(pattern)) { |
| 57 | for (const mapping of mappings) { |
| 58 | result.push({ |
| 59 | name: name.replace(pattern, mapping).replaceAll('<', '[').replaceAll('>', ']'), |
| 60 | anchor, |
| 61 | description: description.html()!, |
| 62 | tooltip: operation, |
| 63 | stack: [stackBefore?.html(), stackAfter?.html()], |
| 64 | format: format.map(x => x.replaceAll('<', '[').replaceAll('>', ']')), |
| 65 | }); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } else { |
| 70 | result.push({ |
| 71 | name, |
| 72 | anchor, |
| 73 | description: description.html()!, |
| 74 | tooltip: operation, |
| 75 | stack: [stackBefore?.html(), stackAfter?.html()], |
| 76 | format, |
| 77 | }); |
| 78 | } |
| 79 | return result; |
| 80 | }; |
| 81 | |
| 82 | const main = async () => { |
| 83 | const file = await fs.readFile(JVMS_SPECIFICATION, 'utf-8'); |
no test coverage detected