Skip to content
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
4 changes: 3 additions & 1 deletion scripts/lib/api-addresses.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export function addressOf(url) {
if (host === 'ocaml.org' && /^\/manual\/[^/]+\/api\//.test(u.pathname)) {
const path = dotted(stem)
const member = /^(?:TYPE|VAL)([a-z_][\w']*)$/.exec(fragment)
return { path: member ? [...path, member[1]] : path, exact: true, fragment: member ? 'member' : none, type: stem }
const constructor = /^TYPEELT[a-z_][\w']*\.([A-Z][\w']*)$/.exec(fragment)
const name = member?.[1] ?? constructor?.[1]
return { path: name ? [...path, name] : path, exact: true, fragment: name ? 'member' : none, type: stem }
}

if (host === 'doc.rust-lang.org' || host === 'docs.rs') {
Expand Down
41 changes: 34 additions & 7 deletions scripts/lib/api-identities.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,7 @@ function documenter(url, page, fragment) {
return { via: 'documenter', declared, kind: declared === 'type' ? 'type' : bucket(declared === 'constant' ? 'constant' : declared), path: name.split('.'), title: page.title }
}

function ocamldoc(_url, page, fragment) {
const heading = page.headings.find((entry) => entry.level === 1)?.text ?? ''
const module = /^Module ([A-Z][\w']*(?:\.[A-Z][\w']*)*)$/.exec(heading)
if (!module) return undefined
const base = { via: 'ocamldoc', declared: 'module', kind: 'module', path: dotted(module[1]), title: page.title }
if (!fragment) return base
function ocamldocMember(page, fragment) {
const member = /^(TYPE|VAL)([a-z_][\w']*)$/.exec(fragment)
const anchor = page.anchors.find((entry) => entry.id === fragment)
if (!member || !anchor) return undefined
Expand All @@ -298,7 +293,39 @@ function ocamldoc(_url, page, fragment) {
? /^type\s+(?:(?:[+-]?'[\w']+|\([^)]*\))\s+)?([a-z_][\w']*)(?![\w'])/
: /^val\s+([a-z_][\w']*)(?![\w'])/).exec(declaration)
if (named?.[1] !== member[2]) return undefined
return { ...base, declared: isType ? 'type' : 'val', kind: isType ? 'type' : 'member', path: [...base.path, member[2]] }
return { declared: isType ? 'type' : 'val', kind: isType ? 'type' : 'member', name: member[2] }
}

function ocamldoc(_url, page, fragment) {
const heading = page.headings.find((entry) => entry.level === 1)?.text ?? ''
const module = /^Module ([A-Z][\w']*(?:\.[A-Z][\w']*)*)$/.exec(heading)
if (!module) return undefined
const base = { via: 'ocamldoc', declared: 'module', kind: 'module', path: dotted(module[1]), title: page.title }
if (!fragment) return base
const anchor = page.anchors.find((entry) => entry.id === fragment)
if (!anchor) return undefined
const constructor = /^TYPEELT([a-z_][\w']*)\.([A-Z][\w']*)$/.exec(fragment)
if (constructor) {
const end = page.html.indexOf('</span>', anchor.at)
const declaration = end < 0 ? '' : page.html.slice(anchor.at, end)
if (!ocamldocMember(page, `TYPE${constructor[1]}`)) return undefined
// Consume complete tags so quoted attribute values cannot supply markup.
const tags = declaration.matchAll(/<!--[\s\S]*?-->|<\/?[A-Za-z][\w:-]*(?=\s|\/?>)(?:"[^"]*"|'[^']*'|[^"'<>])*>/g)
const constructorSpan = [...tags].some(([tag]) => {
if (!/^<span(?=\s|>)/.test(tag)) return false
const text = tag.slice(5, -1).trimEnd()
const attributes = [...text.matchAll(/\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy)]
const last = attributes.at(-1)
if ((last ? last.index + last[0].length : 0) !== text.length) return false
const field = attributes.find(([, name]) => name === 'class')
return (field?.[2] ?? field?.[3] ?? field?.[4]) === 'constructor'
})
if (!constructorSpan || strip(declaration) !== constructor[2]) return undefined
return { ...base, declared: 'constructor', kind: 'member', path: [...base.path, constructor[2]] }
}
const member = ocamldocMember(page, fragment)
if (!member) return undefined
return { ...base, declared: member.declared, kind: member.kind, path: [...base.path, member.name] }
}

function mdn(url, page) {
Expand Down
2 changes: 1 addition & 1 deletion site/src/data/api-destination-evidence.json
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@
{"url":"https://ocaml.org/manual/5.5/api/Iarray.html","host":"ocaml.org","status":200,"via":"html","title":"OCaml library : Iarray","identity":{"via":"ocamldoc","declared":"module","kind":"module","path":["Iarray"]},"ok":true,"terminal":[{"key":"ocaml:Iarray","symbol":"Iarray","at":"identity"}],"checkedAt":"2026-11-08","names":["ocaml:Iarray"],"sources":["builtin","prose"]},
{"url":"https://ocaml.org/manual/5.5/api/Iarray.html#TYPEt","host":"ocaml.org","status":200,"via":"html","title":"OCaml library : Iarray","identity":{"via":"ocamldoc","declared":"type","kind":"type","path":["Iarray","t"]},"fragment":"found","ok":true,"terminal":[{"key":"ocaml:Iarray.t","symbol":"t","at":"identity"}],"checkedAt":"2026-11-08","names":["ocaml:Iarray.t"],"sources":["builtin","type"]},
{"url":"https://ocaml.org/manual/5.5/api/List.html","host":"ocaml.org","status":200,"via":"html","title":"OCaml library : List","identity":{"via":"ocamldoc","declared":"module","kind":"module","path":["List"]},"ok":true,"terminal":[{"key":"ocaml:List","symbol":"List","at":"identity"}],"checkedAt":"2026-11-08","names":["ocaml:List"],"sources":["builtin","prose"]},
{"url":"https://ocaml.org/manual/5.5/api/Option.html#TYPEELTt.None","host":"ocaml.org","status":200,"via":"html","title":"OCaml library : Option","identity":{"via":"page","declared":"page","kind":"other","path":[]},"heading":"#TYPEELTt.None","fragment":"found","ok":true,"terminal":[{"key":"authored:`None`","symbol":"`None`","at":"review"}],"checkedAt":"2026-11-09","names":["site/src/content/docs/_staged/ocaml/guides/bootstrap/index.md","site/src/data/port-guides/ocaml.json"],"sources":["authored"]},
{"url":"https://ocaml.org/manual/5.5/api/Option.html#TYPEELTt.None","host":"ocaml.org","status":200,"via":"html","title":"OCaml library : Option","identity":{"via":"ocamldoc","declared":"constructor","kind":"member","path":["Option","None"]},"heading":"Option.None","fragment":"found","ok":true,"terminal":[{"key":"authored:`None`","symbol":"`None`","at":"identity"}],"checkedAt":"2026-11-09","names":["site/src/content/docs/_staged/ocaml/guides/bootstrap/index.md","site/src/data/port-guides/ocaml.json"],"sources":["authored"]},
{"url":"https://ocaml.org/manual/5.5/api/Seq.html","host":"ocaml.org","status":200,"via":"html","title":"OCaml library : Seq","identity":{"via":"ocamldoc","declared":"module","kind":"module","path":["Seq"]},"ok":true,"terminal":[{"key":"ocaml:Seq","symbol":"Seq","at":"identity"}],"checkedAt":"2026-11-08","names":["ocaml:Seq"],"sources":["builtin","prose"]},
{"url":"https://ocaml.org/manual/5.5/api/Seq.html#TYPEt","host":"ocaml.org","status":200,"via":"html","title":"OCaml library : Seq","identity":{"via":"ocamldoc","declared":"type","kind":"type","path":["Seq","t"]},"fragment":"found","ok":true,"terminal":[{"key":"ocaml:Seq.t","symbol":"t","at":"identity"}],"checkedAt":"2026-11-08","names":["ocaml:Seq.t"],"sources":["builtin","type"]},
{"url":"https://ocaml.org/manual/5.5/api/Seq.html#VALfilter","host":"ocaml.org","status":200,"via":"html","title":"OCaml library : Seq","identity":{"via":"ocamldoc","declared":"val","kind":"member","path":["Seq","filter"]},"fragment":"found","ok":true,"terminal":[{"key":"ocaml:Seq.filter","symbol":"filter","at":"identity"}],"checkedAt":"2026-11-08","names":["ocaml:Seq.filter"],"sources":["builtin","prose"]},
Expand Down
5 changes: 0 additions & 5 deletions site/src/data/api-link-review.json
Original file line number Diff line number Diff line change
Expand Up @@ -980,11 +980,6 @@
"url": "https://ocaml.org/docs/libraries-dune",
"heading": "Libraries With Dune"
},
{
"label": "`None`",
"url": "https://ocaml.org/manual/5.5/api/Option.html#TYPEELTt.None",
"heading": "#TYPEELTt.None"
},
{
"label": "OCaml expressions",
"url": "https://ocaml.org/manual/5.5/expr.html#s:value-expr",
Expand Down
26 changes: 26 additions & 0 deletions site/test/api-destination-evidence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,32 @@ describe('what the verifier reads from a page', () => {
}
})

it('checks OCaml variant constructors against their type and declared name', () => {
const html = '<title>OCaml library : Option</title><h1>Module <a>Option</a></h1>'
+ '<pre><span id="TYPEt">type \'a t</span> = \'a option = </pre><table class="typetable">'
+ '<tr><td><code><span id="TYPEELTt.None"><span class="constructor">None</span></span></code></td></tr>'
+ '<tr><td><code><span id="TYPEELTt.Some"><span class="constructor">Some</span></span> of \'a</code></td></tr></table>'
for (const name of ['None', 'Some']) {
const url = `https://ocaml.org/manual/5.5/api/Option.html#TYPEELTt.${name}`
expect(addressOf(url)).toMatchObject({ path: ['Option', name], exact: true, fragment: 'member' })
const identity = pageIdentity(url, readPage(html))
expect(identity).toMatchObject({ via: 'ocamldoc', declared: 'constructor', kind: 'member', path: ['Option', name] })
expect(judge(sourceIdentity({ port: 'ocaml', name: `Option.${name}`, source: 'builtin' }), identity)).toBeUndefined()
expect(judge(sourceIdentity({ port: 'ocaml', name: `Other.${name}`, source: 'builtin' }), identity)).toMatchObject({ failure: 'owner' })
for (const forged of [html.replace('type \'a t', 'type \'a other'),
html.replace(`class="constructor">${name}`, 'class="constructor">Invented'),
html.replace(`class="constructor">${name}`, `class="type">${name}`),
html.replace(`class="constructor">${name}`, `data-class="constructor">${name}`),
html.replace(`class="constructor">${name}`, `data-note.text=" class='constructor' ">${name}`),
html.replace(`class="constructor">${name}`, `title=" class='constructor'">${name}`),
html.replace(`class="constructor">${name}`, `title="<span class='constructor' ">${name}`),
html.replace(`<span class="constructor">${name}</span>`, `<b title="<span class='constructor' ">${name}</b>`),
html.replace(`class="constructor">${name}`, `><!-- <span class='constructor' -->${name}`)]) {
expect(pageIdentity(url, readPage(forged))).toMatchObject({ kind: 'other' })
}
}
})

it('matches complete OCaml identifiers including apostrophes in value and type declarations', () => {
const actual = []
const expected = []
Expand Down
Loading