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

unspecified parsing error for escaped quotes #49

Closed
allenb-epilog opened this issue Jan 2, 2025 · 3 comments
Closed

unspecified parsing error for escaped quotes #49

allenb-epilog opened this issue Jan 2, 2025 · 3 comments

Comments

@allenb-epilog
Copy link

allenb-epilog commented Jan 2, 2025

Hello,

Using the latest gersemi release 0.17.1 installed via pip I get an unspecified parsing error on cmake source files with escaped quotes in a very specific configuration. A minimum reproduction can be made placing the following in a CMakeLists.txt file and running the formatter/checker on it:

set(MY_VAR
-DCMAKE_INSTALL_PREFIX="\"${INSTALL_PREFIX}\""
)

I can work around this for my specific case by moving the "middle" quote to the beginning of the line like so:

set(MY_VAR
"-DCMAKE_INSTALL_PREFIX=\"${INSTALL_PREFIX}\""
)
@BlankSpruce
Copy link
Owner

This will be rather difficult to fix because I never implemented proper parsing of so called "unquoted legacy" part of unquoted strings because I thought it won't manifest in practice. I was right for about 5 years now. :)

CMake documentation recommends the approach you present in workaround:

We do not recommend using legacy unquoted arguments in new code. Instead use a Quoted Argument or a Bracket Argument to represent the content.

I'll try my best but it might be that rare case where I acknowledge the bug without further action.

As a side note I've run cmake -P /tmp/foo.cmake with CMake 3.31.2 and the following content of /tmp/foo.cmake:

set(INSTALL_PREFIX "install prefix")

set(MY_VAR1
-DCMAKE_INSTALL_PREFIX="\"${INSTALL_PREFIX}\""
)

set(MY_VAR2
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}"
)

set(MY_VAR3
"-DCMAKE_INSTALL_PREFIX=\"${INSTALL_PREFIX}\""
)

message(STATUS "My var 1: ${MY_VAR1}")
message(STATUS "My var 2: ${MY_VAR2}")
message(STATUS "My var 3: ${MY_VAR3}")

and it looks like the problematic code (MY_VAR1) produces different output than workaround (MY_VAR3)

$ cmake -P /tmp/foo.cmake
-- My var 1: -DCMAKE_INSTALL_PREFIX=""install prefix""
-- My var 2: -DCMAKE_INSTALL_PREFIX="install prefix"
-- My var 3: -DCMAKE_INSTALL_PREFIX="install prefix"

@allenb-epilog
Copy link
Author

I have no issue closing this as my case ended up not needing the additional quotes. Thank you for taking the time to look into the issue!

@BlankSpruce
Copy link
Owner

I'll weigh it myself whether it's worth fixing that since a lot could change across these 5 years and it might be not as difficult as I anticipate now. Thanks for the report.

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