diff --git a/bin/annotate-specification-links b/bin/annotate-specification-links index eebc7e34..963768b4 100755 --- a/bin/annotate-specification-links +++ b/bin/annotate-specification-links @@ -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"] + 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. @@ -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, ) diff --git a/bin/specification_urls.json b/bin/specification_urls.json index 9b985e97..9af1a12d 100644 --- a/bin/specification_urls.json +++ b/bin/specification_urls.json @@ -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" } }