Add crate name to grmtools section entries - #664
Conversation
| let mut map = HashMap::new(); | ||
| let grmtools = [ | ||
| "yacckind", | ||
| "lexerkind", |
There was a problem hiding this comment.
grmtools as the notion of a "tool name" is kind of awkward.
I was wondering if it might be better to have lrpar.yacckind and lrlex.lexerkind
instead of grmtools.* for all the crates?
Not sure if it is better to have uniformity across the crates, or indication of who uses it.
There was a problem hiding this comment.
Rather than "tool name", maybe I'll try leaning into "crate name", in which case lrpar/lrlex make sense.
Anyhow, I'm going to try that since it's the most consistent naming scheme i've thought of.
Not too worried if we end up wanting to go back to grmtools.* it's not hard to change.
|
I guess I should mention this just adds default "tool names" to the existing entries. |
| static RE_DIGITS: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^[0-9]+").unwrap()); | ||
| static RE_STRING: LazyLock<Regex> = LazyLock::new(|| Regex::new(r#"^\"(\\.|[^"\\])*\""#).unwrap()); | ||
|
|
||
| static DEFAULT_TOOLNAME: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| { |
There was a problem hiding this comment.
would target name be better than tool name?
| .parse() | ||
| .map_err(|mut errs| errs.drain(..).map(|e| e.into()).collect::<Vec<_>>())?; | ||
| if let Some(HeaderValue(_, yk_val)) = header.get("grmtools.yacckind") { | ||
| if let Some(HeaderValue(_, yk_val)) = header.get("lrpar.yacckind") { |
There was a problem hiding this comment.
So, about the time I got done I remembered that YaccKind is actually defined in cfgrammar So i'm not sure if that isn't going to be more confusing than it is helpful?
There was a problem hiding this comment.
If we want to use the crate names then we could just call this cfgrammar.yacckind?
There was a problem hiding this comment.
Fair enough, I'm not super fond of having multiple prefixes for parser related things, but it does reflect the fact that the consumer of the field is cfgrammar.
There was a problem hiding this comment.
I agree that it does expose a bit more internalness to the user than I would ideally like, but it has the virtue of consistency. Still, this is one of those things that we might change our minds on once we've sat with it for a while!
| | `lrlex.lexerkind` | [LexerKind](lexcompatibility.md#lexerkinds) | ✗ | | ||
| | `lrlex.posix_escapes`[^†] | bool | ✗ | | ||
| | `lrlex.allow_wholeline_comments`[^‡] | bool | ✗ | | ||
| | `regex.case_insensitive` | bool | ✗ | |
There was a problem hiding this comment.
The regex prefix hadn't occurred to me. I think I like it!
|
First thoughts: this looks like it works? You've raised a really good question in the sense of "what's the right prefix?" I hadn't thought about crate names, but so far this looks like it is probably better than |
|
Yeah, as far as working it at least passes |
|
Running through the |
|
So I think this one is ready in the sense that I can probably proceed to the next step of relaxing the unused key checks for unrecognized crate names, to allow user defined keys. I'm happy to let this one simmer while we think about it though. |
|
What are your initial thoughts on the design? |
|
Overall I'm pretty happy with how it has turned out, I like that the regex fields now all point to the regex crate explicitly. If we keep the current behavior where the library figures out unprefixed items perhaps people can just continue using What I mean is: with the unused key check, we can keep checking that keys prefixed with I guess what I'm thinking is we really don't seem forced to deprecate Edit: Besides that I also like that the crate names gives us a way to avoid conflicting keys like you've mentioned. Edit2: I guess to summarize overall I like it, and I wonder whether the downside of separating the key prefix for |
|
Yes, for backwards compatibility we should definitely allow Summary: I think we should move ahead with this approach. |
|
Actually it's not even a problem if someone makes a Edit: I mean, it would be confusing, but there is not actually any conflict, we can differentiate the two syntactically. |
|
I went ahead and unmarked as draft then. |
True! In terms of the code, I'm already happy with this. Could/should we merge (subject to squashing)? |
This allows entries in the grmtools section to specified including `crate_name.entry_name:` For backwards compatibility it infers the crate name from the known entries. This cannot currently be used by crates outside grmtools without error. In the future this may be relaxed.
7807176 to
15cd813
Compare
|
Sounds good to me, I went ahead and squashed it and rewrote the commit message. |
So here is a first foray into adding a default "tool name" for
%grmtoolssection entries,This turned out a bit more complex than I had thought, for one it seemed that since
lex_flagslargely get passeddirectly into the
regexcrate, we should name thoseregex.foorather thangrmtools.foo.I named this "tool name" because there is already a thing we call
namespacein this area, and that likeYaccKind::and the like.