fortran-lang / fprettify

auto-formatter for modern fortran source code
https://pypi.python.org/pypi/fprettify
Other
368 stars 73 forks source link

Disable whitespace disrupting CUDA chevrons #162

Open JamieJQuinn opened 6 months ago

JamieJQuinn commented 6 months ago

Previously, fprettify did not understand CUDA fortran's triple-chevron syntax for calling kernel functions, e.g.

call example_kernel<<<1, 1>>>(args)

As a result, each symbol in the chevrons <<< would have whitespace added, resulting in the incorrect syntax:

call example_kernel <  <  < 1, 1 >  >  > (args)

This problem only occurs when adding whitespace around relational operators is enabled.

This commit adds an escape hatch to the function that handles whitespace around operators add_whitespace_context which disables the whitespace handling for any line that matches the REGEX "<<<.*>>>":

CUDA_CHEVRONS_RE = re.compile(r"<<<.*>>>", RE_FLAGS)

...

if not ( ... or CUDA_CHEVRONS_RE.search(line) ):

This change should not break any Fortran syntax, however any relational operator that appears in a line that also features a triple-chevron will not be formatted, e.g.

call example_kernel<<<1, 1>>>(3< 4, var1 ==var2)

This fixes #124.