Skip to content
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

Proposal for Enum markup #3419

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Proposal for Enum markup #3419

wants to merge 2 commits into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented May 27, 2024

Part of: #2796

Fixes:

Requires:

I kinda wish I could use a <refentry> tag instead, but we need to insert this into a <book> element which requires an intermediate tag anyway, so steal the suboptimal markup from classes.

@haszi do you think this makes sense, and is this not too complicated to add support to PhD for it?

@Girgias Girgias requested a review from TimWolla as a code owner May 27, 2024 23:57
Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

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

Can't comment on the Docbook specifics, but here's some words for you to include to make the page useful right from the start.

reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
reference/random/random.intervalboundary.xml Outdated Show resolved Hide resolved
@haszi
Copy link
Contributor

haszi commented May 28, 2024

@haszi do you think this makes sense, and is this not too complicated to add support to PhD for it?

This is very much in line with the new class markup you used which is great. PhD support should not be an issue and most of the work will be done when the new class markup is converted.

I assume the rendered enum synopsis would look something like this:

enum_synopsis

@TimWolla
Copy link
Member

@haszi Note that related to #3405, enum cases can also have attributes (they are class constants internally). So it's probably to take that into account right away.

</enumitemdescription>
</enumitem>

</enumsynopsis>
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, so far classsynopsis elements only contained the signature itself, but not the descriptions. Is it intentional that it's different for enumsynopsis elements?

Copy link
Member Author

Choose a reason for hiding this comment

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

The DocBook 5.2 markup describes the markup in that manner: https://tdg.docbook.org/tdg/5.2/enumsynopsis (via the <enumitem> tag) so yes.

For reference, the <classsynopsis> description is located here: https://tdg.docbook.org/tdg/5.2/classsynopsis

Copy link
Member

Choose a reason for hiding this comment

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

That's a pity, because this way automatic replacement is going to be much more difficult, since there are free form values in the generated enumsynopsis item, and we should somehow try to preserve them.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a pity, because this way automatic replacement is going to be much more difficult, since there are free form values in the generated enumsynopsis item, and we should somehow try to preserve them.

I'm not sure whether that's difficult? One just needs to ignore the <enumitemdescription> tag, but also, I don't see how an enum would change after it has been introduced.

Copy link
Member

Choose a reason for hiding this comment

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

classsynopsis elements are generated based on the current stub definitions for each class/interface/enum signature which are encountered on class synopses pages (https://github.com/php/php-src/blob/0ad2e4d997549c85aac61120a94ea3da0b709339/build/gen_stub.php#L5560) and then the respective elements are replaced altogether one by one (the replaceAndCompareXmls() call a few lines below).

This means that if there is anything inside classsynopsis elements which are not generatable based on the definitions in stubs, then those things will be removed. A workaround for enums could be that the enum case descriptions are retrieved from the manual pages and they are inserted into the generated elements... This complicates the process, but maybe it's not that difficult if this is going to be the preferred approach.

Also, It has just came to my mind that these descriptions would result in enum definitions which are completely not valid PHP code 🤔 while for the rest of the symbols, we generate at least a remotely valid PHP code since a few years.

<!-- TODO New Reftitle entity -->
&reftitle.classsynopsis;

<enumsynopsis>
Copy link
Member

Choose a reason for hiding this comment

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

Just a FYI: we should also think about the markup for implemented interfaces, enum constants, methods

Copy link
Member Author

Choose a reason for hiding this comment

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

Right... I forgot that PHP enums can do this sort of stuff...

Copy link
Member

@kocsismate kocsismate May 29, 2024

Choose a reason for hiding this comment

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

Yeah, and I've just realized that e.g. fieldsynopsis elements inside enumsynopsis are not even allowed in DocBook. :/ (Or are they?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, they are not, because DocBook (rightfully) assumes that enums are just that, and not our weird thing based on objects.

I think we might need to use the <classsynopsis> tags when an enum has constants, properties, or methods. However, I would imagine this to be rare for internal enums.

<enumname>IntervalBoundary</enumname>
<!-- <modifier role="enum_backing_type">string|int</modifier> -->

<enumitem>
Copy link
Member

Choose a reason for hiding this comment

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

Other types of symbols have a dedicated section title for classes and interfaces. Would it be a good idea to add them for enums as well?

@kocsismate
Copy link
Member

I've just drafted a PR which adds support for this feature in stubs: php/php-src#14369 I intentionally modified Random\IntervalBoundary and also checked in the generated result for testing purposes.

@haszi
Copy link
Contributor

haszi commented Jun 22, 2024

Since all enums implement either the UnitEnum or the BackedEnum interface and inherit their default method implementation, all enum markup will have to include both an <enumsynopsis> and a <classsynopsis> element. Neither of these can have the other as its child but we could have one after the other in the synopsis <section> like this (I think this is valid DocBook 5.2 markup):

 <section xml:id="enum.intervalboundary.synopsis">
   &reftitle.classsynopsis;

  <enumsynopsis>
   ... // enum (cases) markup
  </enumsynopsis>

  <classsynopsis>
   ... // regular class markup
  </classsynopsis>
 </section>

<enumname> in the <enumsynopsis> element would define the enum's name and any class/interface name in the <classynopsis> element would be ignored.

What do you think?

@kocsismate
Copy link
Member

in the element would define the enum's name and any class/interface name in the element would be ignored.

Hmm, interesting option... I wouldn't have thought about it. But I think I'd prefer to just have one element which has to be classynopsis because of the restrictions we face.

@TimWolla
Copy link
Member

This will now also be required for RoundingMode (and some other enums) in 8.4.

@cmb69
Copy link
Member

cmb69 commented Oct 22, 2024

Hmm, this is ugly. We can't use <enumsynopsis> due to its limitation, and we can't use <classsynopsis> because its class attribute only supports "class" and "interface". I'm afraid we need to redesign enums altogether. ;)

Okay, let's be pragmatic and use <classsynopsis> (and role="enum" if necessary).

@Girgias
Copy link
Member Author

Girgias commented Oct 22, 2024

Hmm, this is ugly. We can't use <enumsynopsis> due to its limitation, and we can't use <classsynopsis> because its class attribute only supports "class" and "interface". I'm afraid we need to redesign enums altogether. ;)

Okay, let's be pragmatic and use <classsynopsis> (and role="enum" if necessary).

We will need the role="enum" as otherwise the generated markup by PhD will make it look like classes.

I still don't think any internal enum is going to actually implement interfaces or have any sort of properties, even if this is allowed in userland. So the "problem" seems rather theoretical, and even then it would be possible to add the above "hack fix" with the role="enum".

@cmb69
Copy link
Member

cmb69 commented Oct 22, 2024

I still don't think any internal enum is going to actually implement interfaces or have any sort of properties, even if this is allowed in userland. So the "problem" seems rather theoretical, and even then it would be possible to add the above "hack fix" with the role="enum".

I'm a bit worried about translations. If we have a number of enum documented with <enumsynopsis>, and later need to change everything …

On the other hand, maybe we will never need more, and I'm overthinking.

@Girgias
Copy link
Member Author

Girgias commented Oct 23, 2024

I still don't think any internal enum is going to actually implement interfaces or have any sort of properties, even if this is allowed in userland. So the "problem" seems rather theoretical, and even then it would be possible to add the above "hack fix" with the role="enum".

I'm a bit worried about translations. If we have a number of enum documented with <enumsynopsis>, and later need to change everything …

On the other hand, maybe we will never need more, and I'm overthinking.

What I meant, is that it would be perfectly fine for both markups to coexist, where the <classsynopsis class="class" role="enum"> usage would be reserved for "complex" enums that actually behave like classes.

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.

5 participants