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

Represent toplevel comments in the AST #406

Open
BinderDavid opened this issue Dec 4, 2024 · 4 comments
Open

Represent toplevel comments in the AST #406

BinderDavid opened this issue Dec 4, 2024 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@BinderDavid
Copy link
Collaborator

Comments which are not doc comments are currently discarded during the lexing phase and not represented in the AST. This choice has one important downside: The comments are deleted if we perform de/-refunctionalization or use the code formatter. But toplevel comments are important in tutorials and examples, and we should guarantee that they are preserved during xfunc.

@BinderDavid BinderDavid added enhancement New feature or request good first issue Good for newcomers labels Dec 4, 2024
@BinderDavid
Copy link
Collaborator Author

We need some sort of syntax for this. I think we could take inspiration from GHC's use of notes: https://www.stackbuilders.com/insights/the-notes-of-ghc/ and introduce the note declaration.
Maybe something like this:

-- | foo bar
-- | baz
-- | - enumeration point 1
-- | - enumeration point 2
-- | ** something important**
note foo-bar

I.e. notes are a simple toplevel declaration note <identifier> with a doc-comment which contains the payload.

@timsueberkrueb
Copy link
Collaborator

We should also consider top-level doc comments for modules, e.g. prefixed //! in Rust. Could this also be subsumed by notes or would this be something separate?

@BinderDavid
Copy link
Collaborator Author

We should also consider top-level doc comments for modules, e.g. prefixed //! in Rust. Could this also be subsumed by notes or would this be something separate?

I think we can design these features together. Personally, I dislike the fact that Rust has multiple syntaxes for doc comments both before and after elements, i.e. both /// and //!, and I would like to have a consistent style where doc-comments always come first. We could start by just displaying notes in the documentation generator, and later special case a note which has the name of the module? E.g. note data::nat is special-cased? This would also allow to reference module documentation from within other doc comments.

@BinderDavid
Copy link
Collaborator Author

Or wait, if we allow name-spaced references to notes then if the module foo has a note bar then we could reference the note foo::bar. And we could have a convention that note doc contains the documentation of the module, which we would then reference with data::bool::doc or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants