ozra / onyx-lang

The Onyx Programming Language
Other
96 stars 5 forks source link

Comments and Doc Comments Syntax #10

Open ozra opened 8 years ago

ozra commented 8 years ago
-- here's a comment
say "ok!" -- and here

--| This function blows up this universe!
--| Will be better documented after Ragnarök
some-func(x Int) -> x / 0

-- _[ed: added 17-04-05]:_

--/ A Multi Line Doc Comment
    that ends when
    dedent is reached
some-func(x --[an inline comment here]-- Int) -> x

--\ Or Maybe Backslash
    or maybe both, that
       could work
    too

Prior Art

Propositions

  1. -- and (--| or --:) (double hyphens only) for comments and doc comments
  2. As per above an also: and (—| or —:) (EMDASH [\u2014]) interchangeably for comments and doc comments respectively
  3. [ed: added 17-04-05]: Different forms of symmetric and multiline comments also: --[ comment ]--, --/ begin comments that close with dedent, etc.
    • Also here it is probably good to designate classes of intent to different comment-markers: simply code put out of action, dev-to-dev comment on impl-details, etc. vs. officially documenting comments (for doc-extraction).

Motivation

Allowing EMDASH (, \u2014) could be nice. It looks more like natural writing and stands out a bit. Getting unicode into a de facto position is desirable, but relying on it is still a bit of fringe work.

Allowing them both makes it simple for those who:

Even though most of us prefer monotype while editing (hell, I know some people who prefer monotype for everything, even book reading!), EMDASH still looks a great deal wider than hyphen in most fonts, so it is clear (even without highlighting).

One downside is that it might not be available in all monotype fonts.

Style uniformity in a project is solved via formatter. Everyone should decide on a style and configure the formatter for it. One for checking in to project (project style), and one for personal editing. This way the project can have -- as mandatory style, while you use during your editing sessions, if you prefer it.

NOTE

Currently the -- style is implemented. Distinction semantically between comments and doc comments is not decided by the notation yet, but currently by proximity.

[ed: added 17-04-05]: The suggestions above added with this edit/date marker are just ideas and not implemented yet.

stugol commented 8 years ago

Does the lack of # as a comment prefix cause a problem with shebang lines?

#!/usr/bin/onyx
ozra commented 8 years ago

There is a parsing exception allowing the shebang on the first line.

stugol commented 8 years ago

Neat.

ozra commented 7 years ago

Edited the OP and added multi-line / inline comment ideas.