Skip to content

Simplify Header::Value - #666

Merged
ltratt merged 1 commit into
softdevteam:masterfrom
ratmice:grmtools_section_value
Sep 10, 2026
Merged

Simplify Header::Value#666
ltratt merged 1 commit into
softdevteam:masterfrom
ratmice:grmtools_section_value

Conversation

@ratmice

@ratmice ratmice commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

This is an experiment to see if we can do away with Value<T> and all it's friends Setting, Namespaced, etc.
Replacing it with the much simpler GrmtoolsSectionValue<T>. This can lead to slightly worse error messages.
e.g. because we're checking YaccKind as a whole including YaccOriginalActionKind. But I think it is pretty much limited to that. We could do better, by attempting to parse the RustLike(string) rather than the simple matching I've done here. (As well as derive an inner span).

Sadly this patch has ended up kind of redoing some of the case-insensitivity migration in #665
This came up because when experimenting with integrading the lookup methods with the used value checking.
This involved changing the value owned by the GrammarAST from a HashMap<GrmtoolsSectionValue> to the Header<T>. Then the lookup methods would have to clone the value and return an owned GrmtoolsSectionValue, because there was none to borrow anymore.

It feels like this solves that borrowing issue, but also is a much simpler structure, and so cleans up the code a lot?

Comment thread cfgrammar/src/lib/header.rs Outdated
Comment thread lrpar/src/lib/parser.rs Outdated
@ratmice
ratmice marked this pull request as ready for review August 29, 2026 06:01
Comment thread cfgrammar/src/lib/header.rs Outdated
Comment thread cfgrammar/src/lib/header.rs Outdated
Comment thread cfgrammar/src/lib/header.rs Outdated
mut i: usize,
) -> Result<(Namespaced<Span>, usize), HeaderError<Span>> {
// Either a name alone, or a namespace which will be followed by a member.
fn parse_rustlike(&self, mut i: usize) -> Result<((String, Span), usize), HeaderError<Span>> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I marginally prefer "namespaced" as a name ("Rustlike" felt like it could cover a lot of things). I don't feel strongly, though.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly about it either, I don't mind switching it back.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched this back to Namespaced in 12efed9

@ltratt

ltratt commented Aug 31, 2026

Copy link
Copy Markdown
Member

It's hard not to like a PR which deletes this much stuff with such a minor impact on functionality! It suggests to me that it's heading in the right direction!

@ratmice ratmice changed the title use simpler GrmtoolsSectionValue throughout Simplify Header::Value Aug 31, 2026
@ratmice ratmice changed the title Simplify Header::Value Simplify Header::Value Aug 31, 2026
Num(u64, T),
Bool(bool, T),
Array(Vec<Value<T>>, T),
/// A Rust like value, with an optional type namespace.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume that "optional" here means "non-empty string"?

@ratmice ratmice Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite (Edit: I may have misread non-empty as "empty string"), I was about to say I should include an example, but now notice I did, by "optional type namespace" I meant: YaccKind::Grmtools where YaccKind:: is the optional type namespace,
and it's optional because the YaccKind:: can be omitted by just specifying Grmtools.

Maybe I need to specify Grmtools is omitting the optional type namespace in the later example?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to clarify the comment in a2661d3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so we expect the optional namespace to end with :: I think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah exactly, the actual rule (from grmtools-section.test) is a little bit more complex than just starting with an optional prefix, because it's a recursive rule.

    namespaced -> (String, Span): IDENT | IDENT '::' IDENT;
    val -> Value<Span>: namespaced | namespaced '(' namespaced ')' | ... ;

In the "Further examples" you can see one of the recursive rules with and without the optional namespace: like Original(UserAction)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

@ltratt

ltratt commented Sep 9, 2026

Copy link
Copy Markdown
Member

I have one further, minor, comment, but I think we're close with this one.

@ltratt

ltratt commented Sep 10, 2026

Copy link
Copy Markdown
Member

I think this is ready for squashing. If you agree, please go ahead.

This simplifies the `Value` type by making it more json like,
It avoids the complexity of exposing the AST form of namespaced rust like values,
by converting them back into their string representation.
@ratmice
ratmice force-pushed the grmtools_section_value branch from a2661d3 to d1af629 Compare September 10, 2026 08:57
@ratmice

ratmice commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

Squashed, I also tried to write a higher level overview in the commit message explaining it.

@ltratt
ltratt added this pull request to the merge queue Sep 10, 2026
Merged via the queue into softdevteam:master with commit d600e09 Sep 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants