Skip to content

Conversation

KrystalDelusion
Copy link
Member

@KrystalDelusion KrystalDelusion commented Sep 24, 2025

What are the reasons/motivation for this change?

https://yosyshq.discourse.group/t/quoted-strings-in-pass-arguments/83

Explain how this is achieved.

  • Use std::quoted() from <iomanip> to quote/unquote pass arguments. In order to maintain handling of (unquoted) comments and semicolons this occurs when adding the token to the arg list, rather than in the tokenization itself. Passes no longer receive tokenized-but-raw arguments and are instead pre-unquoted. Should resolve Support quoted strings as arguments to passes #4511.
  • Add support for single quoted strings. These have no escape character and are treated verbatim. This is useful for minimizing the number of backslashes in (for example) logger -expect regexps (e.g. "\\\"" -> '\"').
  • In order to maintain reproducibility with echo on, arguments which require quoting will automatically quote (arguments which were quoted but didn't need to be will not be quoted in the echo). Single quotes are used by default, unless the arg contains a single quote and then it will use std::quoted() (which uses double quotes and can escape with backslash).
  • Resolve issues with passes such as setattr which rely on arguments having quotation marks for disambiguation.

If applicable, please suggest to reviewers how they can test the change.

PR includes tests (though I don't think they're currently being picked up by CI) for checking behavior of arg parsing in tests/scripts. Many of which utilize a plugin that gets compiled during testing and provides the test_args pass, which is basically just log but each argument is separated by a newline.

i.e. they should be part of the quote instead of starting a comment
Use `std::quoted()` from `<iomanip>` to quote/unquote pass arguments.
In order to maintain handling of (unquoted) comments and semicolons this occurs when adding the token to the arg list, rather than in the tokenization itself.
Passes no longer receive tokenized-but-raw arguments and are instead pre-unquoted.
This will cause problems for some passes (e.g. `setparam`) which rely on arguments having quotation marks for disambiguation.
In order to maintain reproducibility with `echo on`, arguments which require quoting will automatically quote (arguments which were quoted but didn't need to be will not be quoted in the echo).
Add other special characters to `needs_quote()` check.
Fix `"\" ` being treated as a complete quoted string because of the space after the `"` even though it's escaped.
Single quoted strings have no escape character and are treated verbatim.
This is useful for minimizing the number of backslashes in (for example) `logger -expect` regexps (e.g. `"\\\""` -> `'\"'`).
`Yosys::quote()` will use single quotes by default, unless the string contains a single quote and then it will use `std::quoted()`.

Fix strange behaviour arrising from always using `std::quoted(result)`.  Because of the way the function interacts with streams, if there is only one quotation mark then the result would end at the first whitespace.
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

Successfully merging this pull request may close these issues.

Support quoted strings as arguments to passes
1 participant