From 94052731d0f955ad8c9ec9fb9392470f48187d3f Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Tue, 17 Sep 2024 15:11:45 +0100 Subject: [PATCH] cylc_lang: permit preprocessing in intercycle offsets --- cylc/sphinx_ext/cylc_lang/__init__.py | 8 ++++++++ cylc/sphinx_ext/cylc_lang/lexers.py | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/cylc/sphinx_ext/cylc_lang/__init__.py b/cylc/sphinx_ext/cylc_lang/__init__.py index 3aa78b9..82ef51d 100644 --- a/cylc/sphinx_ext/cylc_lang/__init__.py +++ b/cylc/sphinx_ext/cylc_lang/__init__.py @@ -30,12 +30,20 @@ .. code-block:: cylc + # Jinja2 + + {% set final_cycle_point = final_cycle_point | default('') %} + {% set duration = duration | default('P1Y') %} + [scheduling] initial cycle point = 2000 + final cycle point = {{ final_cycle_point }} [[graph]] P1Y = """ @wall_clock => foo? => bar (foo? & bar) => pub + + foo[-{{ duration }}+P1D] => foo """ .. note:: diff --git a/cylc/sphinx_ext/cylc_lang/lexers.py b/cylc/sphinx_ext/cylc_lang/lexers.py index cefb44c..7836263 100644 --- a/cylc/sphinx_ext/cylc_lang/lexers.py +++ b/cylc/sphinx_ext/cylc_lang/lexers.py @@ -200,9 +200,35 @@ class CylcLexer(RegexLexer): include('integer-duration'), # matches a subset of iso8601 include('iso8601-duration'), (r'[\^\$]', INTERCYCLE_OFFSET_TOKEN), + ( + # anything that contains Jinja2 syntax + r'(?=[^\]]*{{)', + INTERCYCLE_OFFSET_TOKEN, + 'preproc-intercycle-offset', + ), + ( + # anything that contains EmPy syntax + r'(?=[^\]]*@)', + INTERCYCLE_OFFSET_TOKEN, + 'preproc-intercycle-offset', + ), (r'\]', Text, '#pop') ], + # Task inter-cycle offset with preprocessing: foo[-{{duration}}+P1D] + # Note: This is done in its own section so that we don't bypass the + # validation that has been implemented for explicit offsets + 'preproc-intercycle-offset': [ + # permit pre-processing + include('preproc'), + # interpret all other text as part of the offset + # (we can't perform validation when preprocessing is involved) + (r'[^\]]', INTERCYCLE_OFFSET_TOKEN), + # the first "]" (outside of preprocessing) marks the end of the + # offset + (r'(?=\])', Text, '#pop') + ], + # generic Cylc cycle point: 2000 'cycle-point': [ # validating the cycle point as a regex [effectively] requires