-
Notifications
You must be signed in to change notification settings - Fork 631
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
Adding support for recursive blocs and associativity in ARGUMENT EXTEND #12743
Adding support for recursive blocs and associativity in ARGUMENT EXTEND #12743
Conversation
I don't understand how associativity is used for nonterminals without levels, so not sure about that part. Supporting recursive definitions in ARGUMENT EXTEND could be useful. On the other hand, it's odd that we have 2 different ways to specify productions that have different formats and feature sets. The original Camlp5 method already supports recursive productions without any additional feature such as Excluding GRAMMAR EXTEND, the EXTENDs seem fairly verbose. Each only describes a single nonterminal. Aside from the semantic info they provide, they don't have all the features of the Campl5 style productions (e.g. inline subproductions). I think we'd be better off if we moved the semantic information elsewhere--either as annotations in the Camlp5 format or in some new file, perhaps with a build-time check that all the necessary semantic info is present. Also, BTW, IIUC We might consider backporting some of the EXTEND production syntax to the Camlp5 format to make it less cluttered, such as not requiring |
The |
@jfehrle: there are several questions in your comment.
Do you mean it as a general move of
That's right. Then, it is a matter of convention of which syntax we may prefer. If the question is why recursive entries rather than levels, it is because I found it easier (no need to invent a notation for levels). But I'd be ok to provide instead levels, we just need a notation for that. Somehow with |
Why not, but that may be a lot of things to do. As a bit of history, here is how tactic extensions were done before the In a v file:
In an ml file:
In current Coq, with
And if you want to override the default value for what was called |
The
You mean in this case backporting the Camlp5 to the By the way, with camlp5 in gramlib, I wonder whether it would be worth to change |
Perhaps we can chat about this on a phone call as well. We could add this additional feature to ARGUMENT EXTEND. I have no objection. OTOH we have 2 ways to represent productions (GRAMMAR EXTEND and ARGUMENT EXTEND) that look a bit different and have different capabilities. The WITH is adding something that's already supported in GRAMMAR EXTEND. If we can get to a single mechanism that serves all our requirements that will be simpler for us use, think about and maintain, and this PR might not be needed. I'm not planning to make such a change anytime soon but I thought it was worth mentioning. |
@jfehrle: we could talk on next Thursday evening 8pm Paris time? |
@herbelin To talk about possible improvements to parsing? I don't have anything new to say yet about this particular PR. For parsing improvements, it may make more sense to wait a little longer so I have specific ideas that I've vetted somewhat. But I could do 8PM Paris time in any case. On August 20th, right? |
I meant to talk about this PR (providing recursivity vs levels, and if levels, with which syntax). But this can be a larger discussion too. Yes, on August 20th. |
@ppedrot: I'd like to have your opinion about this PR. Indeed, this PR is introducing new syntax, namely support for recursive grammars, which is an alternative way to using levels. I could also support levels, e.g. with a user syntax of the following form:
Q1: Do you have an opinion on providing levels vs recursion vs both of them? Also, we talked with @jfehrle about the diversity of Coq-level user syntaxes for syntax extensions (the Q2: Do you see a way to unify this? For instance, I don't mind renouncing to the |
@herbelin On second thoughts I am not sure I see the interest of adding that much complexity to the So, essentially, my opinion on this PR depends on the following question: what is gained here compared to an explicit parsing rule performed through |
The question is about not having too many APIs and syntaxes to do the same thing. It is also a way to explicitly say that declaring an argument is not only a parsing rule, but also a printing rule, an interning rule, an interpretation rule, a substitution rule. Or are you saying that we could keep the |
In that respect, this PR is making things worse then?
There is more you can define around generic arguments, e.g. you can extend constr quotations with arbitrary stuff and the like. The set of features registered on a generic argument is open. To me, |
Not if we consider that camlp5 is not supposed to be used by plugin developers.
I don't get what is your proposal. Is it to keep things as they are? In particular, I have a concrete question which is blocking me to continue working on notations: the |
In the end the Tacentries API generates tokens using the campl5 production type, so at best it's a pious lie.
The current situation is not satisfactory, but I think that adding layers of complexity to reimplement the very same thing as the base API except for the use of a half-baked, quirky syntax that is constrained by some unfortunate historical design choices is not the way to go.
I agree this is a real problem[1], but judging from the parsing rules of that argument, it's definitely leaning on the side of full-blown DSLs. It'd be indeed more robust to write it via a [1] Given the guarantees enforced by the campl5 engine and its overall implementation, I technically believe that most of the Coq syntax works by accident. In a streak of cognitive dissonance, I both dream and fear of the day we switch to a parser engine that gives you more invariants. |
Honestly, in term of time, it would be faster to me to have this PR merged (which is not a big deal), but I can also backtrack and study how to move
Not that I know.
I recognize here your taste for "pedagogical exaggeration"! As far as I'm concerned, I'd be curious to know if other parser would be helpful for us (though this does not go in the direction of replacing ARGUMENT EXTEND with PARSING EXTEND). I'm otherwise also ok to progressively adapt camlp5 to our needs, as I know it better and better. |
"works" meaning "parses correctly", right?
We should think about ways to evolve what we have; switching to another parser engine is likely to create havoc both for developers and users. I've been thinking about writing some code to analyze the grammar and (for example) identify productions that are disambiguated only by their order. We may well be able to make the parser somewhat more powerful so it's less tricky to update the grammar without breaking anything. Not quite sure what you mean by "invariants" here. |
@ppedrot: unless we take the decision to renounce to |
…gression). case of failure due to an empty entry was not treated as in: Declare Custom Entry ent. Notation "ent:( x )" := x (x custom ent). Notation "a ; b" := (pair a b) (in custom ent at level 50). Check ent:(_ ; _).
"Fail" was not checking that the error was a Not_found in the test file.
We keep module_expr_atom to be able to use parentheses as in ~~~coq Module M := F (X). ~~~ However `Module M := (X Y)` seems not so nice and is dropped.
TO DO: - adapt to VERNAC ARGUMENT EXTEND - organize the code around nicer invariants
61c9da5
to
c1bcef1
Compare
Looks like the rebase picked up extra incorrect commits. |
The "needs: rebase" label was set more than 30 days ago. If the PR is not rebased in 30 days, it will be automatically closed. |
This PR was not rebased after 30 days despite the warning, it is now closed. |
Trying #17832 as an approach based on GRAMMAR EXTEND. |
Kind: feature
We add support for recursive blocs and associativity of
ARGUMENT EXTEND
. Example:The commit on
WITH
needs polishing, but I prefer first to get feedback on the principle. When polish, it would be direct to extend it toVERNAC ARGUMENT EXTEND
.In practice, all
ARGUMENT EXTEND
are naturally with a right associativity. So fixing right associativity to be the default may be considered. In particular, I updated the grammars by necessity. Maybe some rules not covered by an effective example still need an explicitRIGHT
associativity. (This is one reason defaulting toRIGHT
associativity might be safer for compatibility.)It is possible that recursive blocks helps the ssr plugin to avoid some
GRAMMAR EXTEND
but I prefer to let a specialist see (even if such change could also be added directly to the PR).The change in
doc_grammar.ml
should be checked.This PR is preparing the removal of an "optimization" of camlp5 which allows to support a right associativity even if not asked for.
WITH
commit and extend it toVERNAC ARGUMENT EXTEND