Skip to content

Commit

Permalink
Merge pull request #86 from oliver-sanders/preproc-intercycle-offsets
Browse files Browse the repository at this point in the history
cylc_lang: permit preprocessing in intercycle offsets
  • Loading branch information
oliver-sanders authored Sep 26, 2024
2 parents 23c8296 + 9405273 commit b64f9db
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cylc/sphinx_ext/cylc_lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
26 changes: 26 additions & 0 deletions cylc/sphinx_ext/cylc_lang/lexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b64f9db

Please sign in to comment.