hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 4814319f396422153ca233df48f37be488eea106
parent d2a731687d2d30f3f9f6b7222ff4f7910305ede9
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sat, 22 Jul 2023 01:02:15 -0400

hare::parse: improve struct/union/enum comments

Comments that appear immediately after a struct/union member now
associate with said member, rather than the one after it. Enum comment
behavior was also slightly tweaked to match that of structs and unions
(if both a comment above and a commment on the same line are present,
the comment above is used).

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mhare/parse/type.ha | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/hare/parse/type.ha b/hare/parse/type.ha @@ -289,7 +289,14 @@ fn struct_union_type(lexer: *lex::lexer) (ast::_type | error) = { switch (want(lexer, ltok::RBRACE, ltok::COMMA)?.0) { case ltok::RBRACE => break; - case ltok::COMMA => void; + case ltok::COMMA => + const linecomment = lex::comment(lexer); + const docs = &membs[len(membs) - 1].docs; + if (linecomment != "" && *docs == "") { + *docs = strings::dup(linecomment); + free(lexer.comment); + lexer.comment = ""; + }; case => abort(); }; }; @@ -433,7 +440,7 @@ fn enum_type(lexer: *lex::lexer) (ast::_type | error) = { switch (want(lexer, ltok::COMMA, ltok::RBRACE)?.0) { case ltok::COMMA => const linecomment = lex::comment(lexer); - if (linecomment != "") { + if (linecomment != "" && comment == "") { free(comment); comment = strings::dup(linecomment); free(lexer.comment);