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
33 changes: 29 additions & 4 deletions bin/annotate-specification-links
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def line_number_of(path: Path, case: dict[str, Any]) -> int:
1,
)

def extract_kind_and_spec(key: str) -> (str, str):
"""
Extracts specification number and kind from the defined key
"""
can_have_spec = ["rfc", "iso"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: we could infer that from URITemplate.variable_names by checking if a template has a spec variable (but the ISO template must be configured in that case)

if not any(key.startswith(el) for el in can_have_spec):
return key, ""
number = re.search(r"\d+", key)
spec = "" if number is None else number.group(0)
kind = key.removesuffix(spec)
return kind, spec


def main():
# Clear annotations which may have been emitted by a previous run.
Expand All @@ -82,20 +94,33 @@ def main():
line=error.lineno,
col=error.pos + 1,
title=str(error),
message=f"cannot load {path}"
)
sys.stdout.write(error)
continue

for test_case in contents:
specifications = test_case.get("specification")
if specifications is not None:
for each in specifications:
quote = each.pop("quote", "")
(kind, section), = each.items()
(key, section), = each.items()

number = re.search(r"\d+", kind)
spec = "" if number is None else number.group(0)
(kind, spec) = extract_kind_and_spec(key)

url_template = version_urls[kind]
if url_template is None:
error = annotation(
level="error",
path=path,
line=line_number_of(path, test_case),
title=f"unsupported template '{kind}'",
message=f"cannot find a URL template for '{kind}'"
)
sys.stdout.write(error)
continue

url = version_urls[kind].expand(
url = url_template.expand(
spec=spec,
section=section,
)
Expand Down
2 changes: 1 addition & 1 deletion bin/specification_urls.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"external": {
"ecma262": "https://262.ecma-international.org/{section}",
"perl5": "https://perldoc.perl.org/perlre#{section}",
"rfc": "https://www.rfc-editor.org/rfc/{spec}.txt#{section}",
"rfc": "https://www.rfc-editor.org/rfc/rfc{spec}.txt#{section}",
"iso": "https://www.iso.org/obp/ui"
}
}