[go] go/ast: document CommentGroup types

2 views
Skip to first unread message

Mateusz Poliwczak (Gerrit)

unread,
Sep 16, 2025, 2:53:18 AMSep 16
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Mateusz Poliwczak has uploaded the change for review

Commit message

go/ast: document CommentGroup types
Change-Id: I6a6a696484cfbc438468f048f6c7088f4257cdbc

Change diff

diff --git a/src/go/ast/ast.go b/src/go/ast/ast.go
index a3dc0c3..543cb83 100644
--- a/src/go/ast/ast.go
+++ b/src/go/ast/ast.go
@@ -75,6 +75,14 @@

// A CommentGroup represents a sequence of comments
// with no other tokens and no empty lines between.
+//
+// There are two separate types of comment groups, both represented by a CommentGroup:
+// - Line comment group: comments where every comment starts on the same line.
+// Such group is recognized by [go/parser] when, before a COMMENT token,
+// another (non-COMMENT) token appears on the same line before.
+// - Block comment group: a block of comments, comments might start at different lines, but
+// such comments cannot be separated by an empty line.
+// Such group is recognized by [go/parser] when a COMMENT token is the first token on a line.
type CommentGroup struct {
List []*Comment // len(List) > 0
}

Change information

Files:
  • M src/go/ast/ast.go
Change size: XS
Delta: 1 file changed, 8 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I6a6a696484cfbc438468f048f6c7088f4257cdbc
Gerrit-Change-Number: 704115
Gerrit-PatchSet: 1
Gerrit-Owner: Mateusz Poliwczak <mpoliw...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Mateusz Poliwczak (Gerrit)

unread,
Sep 16, 2025, 10:18:54 AMSep 16
to goph...@pubsubhelper.golang.org, Alan Donovan, golang-co...@googlegroups.com
Attention needed from Alan Donovan

Mateusz Poliwczak voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I6a6a696484cfbc438468f048f6c7088f4257cdbc
Gerrit-Change-Number: 704115
Gerrit-PatchSet: 3
Gerrit-Owner: Mateusz Poliwczak <mpoliw...@gmail.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Mateusz Poliwczak <mpoliw...@gmail.com>
Gerrit-Attention: Alan Donovan <adon...@google.com>
Gerrit-Comment-Date: Tue, 16 Sep 2025 14:18:48 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Alan Donovan (Gerrit)

unread,
Sep 16, 2025, 11:07:44 AMSep 16
to Mateusz Poliwczak, goph...@pubsubhelper.golang.org, Robert Griesemer, Go LUCI, golang-co...@googlegroups.com
Attention needed from Mateusz Poliwczak and Robert Griesemer

Alan Donovan added 2 comments

File src/go/ast/ast.go
Line 79, Patchset 3 (Latest):// There are two separate types of comment groups, both represented by a CommentGroup:
Alan Donovan . unresolved

Tighter:

The parser creates two kinds of CommentGroup.
A line comment group is a sequence of comments all on the same line, following a token on that line.
A block comment group is a sequence of comments, starting on a line without tokens.

In other words, the parser promises both "maximal munch", and not to conjoin a line comment group with a block comment in cases such as this:
```
foo // line
// block
```

We should probably await gri's comments before strengthening the parser's postcondition.

Line 80, Patchset 3 (Latest):// - Line comment group: Recognized by [go/parser] when a comment is not the first
// token on the line. Such group ends when a non-comment token, an empty line
Alan Donovan . resolved

Comments are not tokens, BTW.

Open in Gerrit

Related details

Attention is currently required from:
  • Mateusz Poliwczak
  • Robert Griesemer
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I6a6a696484cfbc438468f048f6c7088f4257cdbc
    Gerrit-Change-Number: 704115
    Gerrit-PatchSet: 3
    Gerrit-Owner: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Reviewer: Robert Griesemer <g...@google.com>
    Gerrit-Attention: Robert Griesemer <g...@google.com>
    Gerrit-Attention: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Comment-Date: Tue, 16 Sep 2025 15:07:40 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Robert Griesemer (Gerrit)

    unread,
    12:51 PM (10 hours ago) 12:51 PM
    to Mateusz Poliwczak, goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, golang-co...@googlegroups.com
    Attention needed from Mateusz Poliwczak

    Robert Griesemer added 2 comments

    Patchset-level comments
    File-level comment, Patchset 5 (Latest):
    Robert Griesemer . resolved

    I'll have to re-read the comment group logic to verify correctness of this comment. It's been a while...
    adonovan: how are we strengthening the parser's postcondition?

    File src/go/ast/ast.go
    Line 81, Patchset 5 (Latest):// token on the line. Such group ends when a non-comment token, an empty line
    Robert Griesemer . unresolved

    Since comments are not tokens, maybe:


    ... when a token (not a comment) ...

    Also below.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Mateusz Poliwczak
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I6a6a696484cfbc438468f048f6c7088f4257cdbc
    Gerrit-Change-Number: 704115
    Gerrit-PatchSet: 5
    Gerrit-Owner: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Reviewer: Robert Griesemer <g...@google.com>
    Gerrit-Attention: Mateusz Poliwczak <mpoliw...@gmail.com>
    Gerrit-Comment-Date: Wed, 01 Oct 2025 16:51:33 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Mateusz Poliwczak (Gerrit)

    unread,
    12:58 PM (10 hours ago) 12:58 PM
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Mateusz Poliwczak

    Mateusz Poliwczak uploaded new patchset

    Mateusz Poliwczak uploaded patch set #6 to this change.
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Mateusz Poliwczak
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I6a6a696484cfbc438468f048f6c7088f4257cdbc
    Gerrit-Change-Number: 704115
    Gerrit-PatchSet: 6
    unsatisfied_requirement
    open
    diffy

    Mateusz Poliwczak (Gerrit)

    unread,
    12:59 PM (9 hours ago) 12:59 PM
    to goph...@pubsubhelper.golang.org, Robert Griesemer, Go LUCI, Alan Donovan, golang-co...@googlegroups.com
    Attention needed from Alan Donovan and Robert Griesemer

    Mateusz Poliwczak voted and added 3 comments

    Votes added by Mateusz Poliwczak

    Commit-Queue+1

    3 comments

    Patchset-level comments
    Robert Griesemer . resolved

    I'll have to re-read the comment group logic to verify correctness of this comment. It's been a while...
    adonovan: how are we strengthening the parser's postcondition?

    Mateusz Poliwczak

    I'll have to re-read the comment group logic to verify correctness of this comment. It's been a while...

    FYI skimming CL 703815 might help with that (not sure we want that change though).

    File src/go/ast/ast.go
    Line 79, Patchset 3:// There are two separate types of comment groups, both represented by a CommentGroup:
    Alan Donovan . resolved

    Tighter:

    The parser creates two kinds of CommentGroup.
    A line comment group is a sequence of comments all on the same line, following a token on that line.
    A block comment group is a sequence of comments, starting on a line without tokens.

    In other words, the parser promises both "maximal munch", and not to conjoin a line comment group with a block comment in cases such as this:
    ```
    foo // line
    // block
    ```

    We should probably await gri's comments before strengthening the parser's postcondition.

    Mateusz Poliwczak

    Updated the comment.

    Line 81, Patchset 5:// token on the line. Such group ends when a non-comment token, an empty line
    Robert Griesemer . resolved

    Since comments are not tokens, maybe:


    ... when a token (not a comment) ...

    Also below.

    Mateusz Poliwczak

    I think i prefer the tighter version of this comment (as written by Alan). WDYT?

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Alan Donovan
    • Robert Griesemer
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I6a6a696484cfbc438468f048f6c7088f4257cdbc
      Gerrit-Change-Number: 704115
      Gerrit-PatchSet: 6
      Gerrit-Owner: Mateusz Poliwczak <mpoliw...@gmail.com>
      Gerrit-Reviewer: Alan Donovan <adon...@google.com>
      Gerrit-Reviewer: Mateusz Poliwczak <mpoliw...@gmail.com>
      Gerrit-Reviewer: Robert Griesemer <g...@google.com>
      Gerrit-Attention: Robert Griesemer <g...@google.com>
      Gerrit-Attention: Alan Donovan <adon...@google.com>
      Gerrit-Comment-Date: Wed, 01 Oct 2025 16:59:49 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Robert Griesemer <g...@google.com>
      Comment-In-Reply-To: Alan Donovan <adon...@google.com>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Mateusz Poliwczak (Gerrit)

      unread,
      1:14 PM (9 hours ago) 1:14 PM
      to goph...@pubsubhelper.golang.org, Go LUCI, Robert Griesemer, Alan Donovan, golang-co...@googlegroups.com
      Attention needed from Alan Donovan and Robert Griesemer

      Mateusz Poliwczak voted Commit-Queue+1

      Commit-Queue+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Alan Donovan
      • Robert Griesemer
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I6a6a696484cfbc438468f048f6c7088f4257cdbc
      Gerrit-Change-Number: 704115
      Gerrit-PatchSet: 8
      Gerrit-Owner: Mateusz Poliwczak <mpoliw...@gmail.com>
      Gerrit-Reviewer: Alan Donovan <adon...@google.com>
      Gerrit-Reviewer: Mateusz Poliwczak <mpoliw...@gmail.com>
      Gerrit-Reviewer: Robert Griesemer <g...@google.com>
      Gerrit-Attention: Robert Griesemer <g...@google.com>
      Gerrit-Attention: Alan Donovan <adon...@google.com>
      Gerrit-Comment-Date: Wed, 01 Oct 2025 17:13:57 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages