Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cylc_lang: permit preprocessing in intercycle offsets #86

Merged
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
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
Copy link
Member Author

Choose a reason for hiding this comment

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

This gets run through the lexer when the cylc-sphinx-extensions docs are built. Before this change, this code would have caused a build error.

Try yourself with make html.

"""

.. 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
Loading