-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
cpp grammar: Unable to parse pointer to array types as template argument #4149
Comments
@kaby76 Never encountered such use case in your scraping algorithm? |
The problem is that the set of test inputs is small, only 17 files. Of those, it only tests about 60% of the parser rules as measured by trcover. A proper test suite should have been supplied when the grammar was submitted. At some point when we redo this grammar, a test suite will be added, first choice likely from the GNU project. |
A practical choice. You can choose from big projects a test suite like GNU, clang, Qt, chrome etc... By the way, do you think my issue is trivially fixable? I guess it shouldn't be this difficult. |
Correct. There is no preprocessor parsing and translation currently. There are rules to ignore preprocessor directives in the grammar, but the parse can fail for a number of reasons, e.g., if a === Someone didn't refactor the
Instead, we ended up with this, which is wrong. grammars-v4/cpp/CPP14Parser.g4 Lines 706 to 714 in ff2f66f
If anything, it should look like this:
That seems to "work" but it may break other things. But even that I wouldn't do. It should be defined using Kleene operators. |
Following the specs, I was able to fix this issue.
Wonder why the grammar doesn't follow the specs in the first place. |
This is precisely what I have been complaining about for years. The proper way forward is to scrape the grammar from scratch. Then, employ known, logical, repeatable, precise transformations to obtain a functioning grammar. I had performed some work on this over here: https://github.com/kaby76/scrape-c-plus-plus-spec. We can try to use some of the transformations in the existing cpp grammar, but there's really no documentation as to why the rules are structured as they are. I now see that https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/ has a firewall preventing downloading even the drafts. Really just terrible. The only current free download of drafts is https://github.com/cplusplus/draft. Who knows how long this will be up. |
Maybe the main goal of This draft looks plausible even though not |
Why would we use a non-authoritative website source when we have authoritative drafts in PDF format at https://github.com/cplusplus, and official standard doc at https://www.iso.org/standard/79358.html and have code already to read and strip the EBNF from the official drafts and formal spec? My plan is to make a PR to fix this parsing issue. One step at a time. |
I see now what the developer did with Spec:
Step 1: Translated to mutually-left recursive Antlr4 format.
Step 2: Remove
This is perfectly fine as is (Antlr4 handles left-recursion), but can be further improved with Kleene operator. Step 3: Reorder alts.
Step 4: Group alts.
Step 5: Transform to
Each of these steps can be handled by the Trash toolkit from the scraped grammar. |
Consider:
This statement can't be parsed, notice that a pointer to function parses correctly:
Test<void(*)(void)> type;
.Thanks.
The text was updated successfully, but these errors were encountered: