frozenlib / parse-display

Procedural macro to implement Display and FromStr using common settings.
Apache License 2.0
182 stars 14 forks source link

Newline in struct member prevents valid parse #27

Closed TheThirdOne closed 1 year ago

TheThirdOne commented 1 year ago

Code like

    #[derive(FromStr)]
    #[display("{0}")]
    struct Test(String);

or

    #[derive(FromStr)]
    #[display("{a},{b}")]
    struct Test {
        a : String,
        b : String,
    }

Results in a parse error if the member contains a newline. This appears to be because the following does not use the setting to allow multiline regex. https://github.com/frozenlib/parse-display/blob/afcf129838df0c9aac9f2821fd39fafd12c30f46/parse-display-derive/src/regex_utils.rs#L6

Is this intentional? This is not the behavior I expected.

frozenlib commented 1 year ago

Thanks for the report.

This was not the intended behavior and has been fixed at 0cca5012de9f3f51f913ce4101733dba3993dfa1.

However, if we change the regex_syntax::Parser setting, there will be a difference between the default behavior of regex crate and the behavior of #[from_str(regex = "...")], which is confusing, so we are only changing the behavior of the part that does not use #[from_str(regex = "...")].

If there is enough demand, I would like to add the ability to set the regex options by specifying them as #[from_str(regex_flags = "s")].

TheThirdOne commented 1 year ago

I agree that changing the default regex is a better decision than changing regex parsing in general. This is fixed for me.