Skip to content

dust_dds_gen: Cannot have trailing whitespace or comments after #endif #492

@Notgnoshi

Description

@Notgnoshi

In C/C++, I habitually leave trailing comments on #endifs, namespaces, and nested classes.

It's not strictly necessary to do so in IDL, because it'd be quite strange to have nested preprocessor statements, but I thought I'd report that dust_dds_gen can't parse the following:

#ifndef FOO
#define FOO

// ...

#endif // FOO

This fails with:

thread 'main' (1723130) panicked at build.rs:7:52:
called `Result::unwrap()` on an `Err` value: "  --> 6:1\n   |\n6 | #endif // FOO\n   | ^---\n   |\n   = expected line"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I had hoped this might be an easy fix by adding

block_comment = @{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" }
line_comment = @{ "//" ~ (!NEWLINE ~ ANY)* }
COMMENT = _{ block_comment | line_comment }

to the Pest grammar, but I think the issue arises from

ifdef_directive   =  { "#ifdef" ~ identifier ~ NEWLINE ~ line* ~ "#endif" }

requiring the line ends with strictly #endif\n (I get the same kind of failure if I add any trailing whitespace to the #endif).

But I don't think

ifdef_directive   =  { "#ifdef" ~ identifier ~ NEWLINE ~ line* ~ "#endif" ~ ANY }

is correct either, because then that'd accept

#endif GARBAGE HERE

So maybe

ifdef_directive   =  { "#ifdef" ~ identifier ~ NEWLINE ~ line* ~ "#endif" ~ WHITESPACE* ~ COMMENT? }

Or maybe it's the definition of line that doesn't leave room for trailing whitespace or comments?

I consider this a very low priority issue, but I thought I'd report it anyways.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions