dmitri.shuralyov.com/go/generated

update implementation for 2020 spec changes dmitri.shuralyov.com/go/generated#1

Mergeddmitshur opened this change 2 years ago
Patch Set 2
dmitshur committed 2 years ago commit 1fecd20faaf0d4b4144272b04e2b2aae4534be90
Collapse all
Commit Message
FileFile
@@ -1,9 +1,31 @@
11
Parent:     b1254a4 (remove comment about API being undecided)
22
Author:     Dmitri Shuralyov <dmitri@shuralyov.com>
33
AuthorDate: Mon Jun 21 00:40:49 2021 -0400
44
Commit:     Dmitri Shuralyov <dmitri@shuralyov.com>
5
CommitDate: Sun Aug 1 13:54:44 2021 -0400
5
CommitDate: Sun Dec 12 15:01:05 2021 -0500
66

77
update implementation for 2020 spec changes
dominikh commented 2 years ago (Patch Set 1)

Should capitalize sentence :P

Write Preview Markdown
dmitshur commented 2 years ago (Patch Set 1)

I'm following the Go style for commit messages, which chooses to do:

A rule of thumb is that it should be written so to complete the sentence "This change modifies Go to _____." That means it does not start with a capital letter, is not a complete sentence, and actually summarizes the result of the change.

(From https://go.dev/doc/contribute#first_line and emphasis mine.)

Write Preview Markdown
88

9
With the new specification, it's possible to stop reading a file early
10
even when the generated comment is absent, since the generated comment
11
may no longer appear anywhere in the file. Begin parsing /* */ comment
12
blocks, which may span multiple lines, to be able to be able to detect
13
when we run into the first non-comment, non-blank text in the file.
14

15
It was mentioned in https://go.dev/issue/41196#issuecomment-686607452:
16

17
> [...] the primary focus for these comments is Go code
18
> and more generally Go package sources.
19
> Go package sources today can be Go, assembly, C, C++, Objective C,
20
> SWIG, and Fortran.
21
> The comment being discussed here, like the //go:build comment,
22
> handles all of these these except Fortran, which seems fine.
23

24
The initial scope of this package was to support parsing Go source only,
25
but it happens to work well with many other source types that are found
26
in Go packages. Replace mentions of "a Go source file" in documentation
27
and code with "a source file", to make it apply more generally. If this
28
will mean we need to parse comments differently depending on the source
29
type in the future, we can revisit this decision. Let's see how it goes.
30

931
Fixes issue 1.
generated.go
FileFile
@@ -1,9 +1,9 @@
11
// Package generated provides a function that parses a source file and reports
22
// whether it contains a "// Code generated … DO NOT EDIT." line comment.
33
//
4
// It implements the specification at https://golang.org/s/generatedcode.
dmitshur commented 2 years ago (Patch Set 1)

Shortened 'golang.org' to 'go.dev' here, and on line 24.

Write Preview Markdown
4
// It implements the specification at https://go.dev/s/generatedcode.
55
//
66
// The first priority is correctness (no false negatives, no false positives).
77
// It must return accurate results even if the input source code is formatted
88
// unconventionally.
99
//
@@ -19,11 +19,11 @@ import (
1919
	"os"
2020
)
2121

2222
// Parse parses a source file provided via src, and reports whether
2323
// the file contains a "// Code generated ... DO NOT EDIT." line comment
24
// matching the specification at https://golang.org/s/generatedcode:
24
// matching the specification at https://go.dev/s/generatedcode:
2525
//
2626
// 	To convey to humans and machine tools that code is generated,
2727
// 	generated source should have a line that matches the following
2828
// 	regular expression (in Go syntax):
2929
//