diff options
author | Olivier Mengué <olivier.mengue@gmail.com> | 2024-01-16 00:16:25 +0100 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-04-02 13:59:01 +0000 |
commit | 061181621641856a90bf555e702a70cac59cb584 (patch) | |
tree | 991baaef86a350a361deb488d02b66ba1dd84c3f /src/regexp | |
parent | be50b58d70704d21cc1be9b69a98491a5e977b64 (diff) | |
download | go-061181621641856a90bf555e702a70cac59cb584.tar.gz go-061181621641856a90bf555e702a70cac59cb584.zip |
regexp/syntax: cleanup code generation in perl_groups.go
Cleanup code generation of perl_groups.go:
* Fix the generated code header to follow the standard https://go.dev/s/generatedcode
* Apply gofmt as last step of code generation
* Add //go:generate lines in parse.go to trigger code generation
* Adapt make_perl_groups.pl to handle writing directly to the output
file (as we can't use shell redirection in go:generate lines)
* use strict; use warnings;
Change-Id: I675241da03dd3f6facc9eb9de00999bd9203ad70
Reviewed-on: https://go-review.googlesource.com/c/go/+/555995
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/regexp')
-rwxr-xr-x | src/regexp/syntax/make_perl_groups.pl | 27 | ||||
-rw-r--r-- | src/regexp/syntax/parse.go | 2 | ||||
-rw-r--r-- | src/regexp/syntax/perl_groups.go | 3 |
3 files changed, 24 insertions, 8 deletions
diff --git a/src/regexp/syntax/make_perl_groups.pl b/src/regexp/syntax/make_perl_groups.pl index 80a2c9ae6b..fafa41cf2c 100755 --- a/src/regexp/syntax/make_perl_groups.pl +++ b/src/regexp/syntax/make_perl_groups.pl @@ -11,7 +11,10 @@ # Perl about each letter from 0-128 and write down # its answer. -@posixclasses = ( +use strict; +use warnings; + +my @posixclasses = ( "[:alnum:]", "[:alpha:]", "[:ascii:]", @@ -28,13 +31,13 @@ "[:xdigit:]", ); -@perlclasses = ( +my @perlclasses = ( "\\d", "\\s", "\\w", ); -%overrides = ( +my %overrides = ( # Prior to Perl 5.18, \s did not match vertical tab. # RE2 preserves that original behaviour. "\\s:11" => 0, @@ -70,7 +73,7 @@ sub PrintClass($$@) { } print "}\n\n"; my $n = @ranges; - $negname = $name; + my $negname = $name; if ($negname =~ /:/) { $negname =~ s/:/:^/; } else { @@ -97,13 +100,25 @@ sub PrintClasses($@) { my $count = @entries; } +# Prepare gofmt command +my $gofmt; + +if (@ARGV > 0 && $ARGV[0] =~ /\.go$/) { + # Send the output of gofmt to the given file + open($gofmt, '|-', 'gofmt >'.$ARGV[0]) or die; +} else { + open($gofmt, '|-', 'gofmt') or die; +} + +# Redirect STDOUT to gofmt input +select $gofmt; + print <<EOF; // Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// GENERATED BY make_perl_groups.pl; DO NOT EDIT. -// make_perl_groups.pl >perl_groups.go +// Code generated by make_perl_groups.pl; DO NOT EDIT. package syntax diff --git a/src/regexp/syntax/parse.go b/src/regexp/syntax/parse.go index 8f16f6308f..26242902f1 100644 --- a/src/regexp/syntax/parse.go +++ b/src/regexp/syntax/parse.go @@ -1576,6 +1576,8 @@ type charGroup struct { class []rune } +//go:generate perl make_perl_groups.pl perl_groups.go + // parsePerlClassEscape parses a leading Perl character class escape like \d // from the beginning of s. If one is present, it appends the characters to r // and returns the new slice r and the remainder of the string. diff --git a/src/regexp/syntax/perl_groups.go b/src/regexp/syntax/perl_groups.go index effe4e6862..675466e5a0 100644 --- a/src/regexp/syntax/perl_groups.go +++ b/src/regexp/syntax/perl_groups.go @@ -2,8 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// GENERATED BY make_perl_groups.pl; DO NOT EDIT. -// make_perl_groups.pl >perl_groups.go +// Code generated by make_perl_groups.pl; DO NOT EDIT. package syntax |