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

Error on concatenation of two strings with a backslash #457

Open
mbraakhekke opened this issue Dec 18, 2024 · 4 comments
Open

Error on concatenation of two strings with a backslash #457

mbraakhekke opened this issue Dec 18, 2024 · 4 comments

Comments

@mbraakhekke
Copy link

The following minimal program results in a NoMatchError for line 2:

program simple
    character(len=10) :: foo = '\' // 'b'
end program simple

I believe this is correct Fortran--at least it compiles fine on Intel.

I'm still investigating myself. It's doesn't seem to be a problem with the regex pattern for the concat-op. I think it has something to do with the fact that backslashes in strings get automatically escaped to \\ in Python.

Interestingly, if I take out the line from the program block, i.e. just:

character(len=10) :: foo = '\' // 'b'

it works fine.

@arporter
Copy link
Member

Thanks for reporting this @mbraakhekke. Do you get the expected parse tree for the line in isolation? (I ask because you have to be careful as, unless you tell the reader you have free-format code, it will see the first c and match a fixed-format comment.)

@mbraakhekke
Copy link
Author

Thanks for reporting this @mbraakhekke. Do you get the expected parse tree for the line in isolation? (I ask because you have to be careful as, unless you tell the reader you have free-format code, it will see the first c and match a fixed-format comment.)

You're right: the line gets interpreted as a comment. How do I tell the reader the file is free-format?

@arporter
Copy link
Member

It's slightly non-intuitive. You need to call set_format() on the reader object (https://fparser.readthedocs.io/en/latest/_static/html/classfparser_1_1common_1_1readfortran_1_1FortranReaderBase.html#ad9e18ea6d859fd5459381d4f1437311d) and pass it an appropriate sourceinfo.FortranFormat object:

from fparser.common.sourceinfo import FortranFormat

reader = ...
reader.set_format(FortranFormat(is_free=True, is_strict=False))
...

@mbraakhekke
Copy link
Author

OK thanks. Now the parsing also fails with a FortranSyntaxError. I'll keep digging. Possibly, I can submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants