From 6e8e4030885ee4e623c2f4bc00309e89d9816f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=BCtt?= Date: Fri, 14 Feb 2025 11:21:17 +0100 Subject: [PATCH] Docs: Add warning for bad usage strings --- docs/generate_input_reference.py | 5 +++++ src/input/input_keyword_types.F | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/docs/generate_input_reference.py b/docs/generate_input_reference.py index 768f547f84..174abb25fb 100755 --- a/docs/generate_input_reference.py +++ b/docs/generate_input_reference.py @@ -311,6 +311,11 @@ def render_keyword( location = get_text(keyword.find("LOCATION")) lone_keyword_value = get_text(keyword.find("LONE_KEYWORD_VALUE")) + # Check that the usage string starts with one of the keyword names. + if keyword.tag == "KEYWORD" and usage: + if not any(usage.upper().startswith(n) for n in keyword_names): + print(f"Warning: Keyword {keyword_xref} has bad usage: {location}") + # Find keyword data type. data_type_element = keyword.find("DATA_TYPE") assert data_type_element is not None diff --git a/src/input/input_keyword_types.F b/src/input/input_keyword_types.F index 446b3a2969..d0797da933 100644 --- a/src/input/input_keyword_types.F +++ b/src/input/input_keyword_types.F @@ -191,6 +191,7 @@ CONTAINS CHARACTER(len=*), INTENT(in), OPTIONAL :: deprecation_notice LOGICAL, INTENT(in), OPTIONAL :: removed + CHARACTER(LEN=default_string_length) :: tmp_string INTEGER :: i, n LOGICAL :: check @@ -221,6 +222,19 @@ CONTAINS IF (PRESENT(usage)) THEN CPASSERT(LEN_TRIM(usage) <= LEN(keyword%usage)) keyword%usage = usage + ! Check that the usage string starts with one of the keyword names. + IF (keyword%names(1) /= "_SECTION_PARAMETERS_" .AND. keyword%names(1) /= "_DEFAULT_KEYWORD_") THEN + tmp_string = usage + CALL uppercase(tmp_string) + check = .FALSE. + DO i = 1, SIZE(keyword%names) + check = check .OR. (INDEX(tmp_string, TRIM(keyword%names(i))) == 1) + END DO + !TODO: Arm this check once all the existing usage strings have been fixed. + !IF (.NOT. check) THEN + ! CPABORT("Usage string must start with one of the keyword name.") + !END IF + END IF ELSE keyword%usage = "" END IF