RFC: Incompatible, but similar pragma handling

I can give more precise details if necessary, but it's more a general question to start.

Any recommendations on how to best handle two similar, but incompatible sets of pragma?

Example
clang -foo
#pragma bar baz - OK
#pragma bar baz blah - Not ok
#pragma foobar - OK

clang -foov2 (not backwards compatible)
#pragma bar baz - Not ok
#pragma bar baz blah - OK
#pragma foobar - OK

Unfortunately, I don't have any good suggestions. Clang has basically no
reusable pragma parsing infrastructure. Nothing is consistent, because
we're parsing all pragmas that have ever seen any significant use. Aaron
has done a really good job cleaning up attributes, and I'd love to see the
same happen to pragmas. I tried once and it didn't go well. :slight_smile:

    I can give more precise details if necessary, but it's more a
    general question to start.

    Any recommendations on how to best handle two similar, but
    incompatible sets of pragma?

Unfortunately, I don't have any good suggestions. Clang has basically no reusable pragma parsing infrastructure. Nothing is consistent, because we're parsing all pragmas that have ever seen any significant use. Aaron has done a really good job cleaning up attributes, and I'd love to see the same happen to pragmas. I tried once and it didn't go well. :slight_smile:

Cool :slight_smile: I tried rewriting the pragma parsers too once, using a templatized PEG.

It reduced implementing pragmas to a couple of lines. There are some really nice C++ templatized PEGs out there and in principle it should be possible to integrate them fully to achieve the same quality or better diagnostics as the hand-written code we have now.

We don't use parser generators for C++ but in theory there's nothing stopping us using them for the various other kinds of sub-grammars we encounter like pragmas which are trivial/regular in comparison.

Fun project for a rainy day perhaps, though contrary to the time-honoured LLVM tradition of hand-parsing.

Alp.