]> Cypherpunks repositories - gostls13.git/commitdiff
regexp/syntax: fix comment on p.literal and simplify
authorRuss Cox <rsc@golang.org>
Sat, 7 Mar 2020 14:35:12 +0000 (09:35 -0500)
committerEmmanuel Odeke <emm.odeke@gmail.com>
Fri, 17 Apr 2020 22:12:02 +0000 (22:12 +0000)
p.literal's doc comment said it returned a value but it doesn't.
While we're here, p.newLiteral is only called from p.literal,
so simplify the code by merging the two.

Change-Id: Ia357937a99f4e7473f0f1ec837113a39eaeb83d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/222659
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/regexp/syntax/parse.go

index 8c6d43a70636944fca38dd5a8af0e3158614fc87..7b4030935a7bb5056163af5794786cd6c6b727ec 100644 (file)
@@ -177,16 +177,16 @@ func (p *parser) maybeConcat(r rune, flags Flags) bool {
        return false // did not push r
 }
 
-// newLiteral returns a new OpLiteral Regexp with the given flags
-func (p *parser) newLiteral(r rune, flags Flags) *Regexp {
+// literal pushes a literal regexp for the rune r on the stack.
+func (p *parser) literal(r rune) {
        re := p.newRegexp(OpLiteral)
-       re.Flags = flags
-       if flags&FoldCase != 0 {
+       re.Flags = p.flags
+       if p.flags&FoldCase != 0 {
                r = minFoldRune(r)
        }
        re.Rune0[0] = r
        re.Rune = re.Rune0[:1]
-       return re
+       p.push(re)
 }
 
 // minFoldRune returns the minimum rune fold-equivalent to r.
@@ -204,12 +204,6 @@ func minFoldRune(r rune) rune {
        return min
 }
 
-// literal pushes a literal regexp for the rune r on the stack
-// and returns that regexp.
-func (p *parser) literal(r rune) {
-       p.push(p.newLiteral(r, p.flags))
-}
-
 // op pushes a regexp with the given op onto the stack
 // and returns that regexp.
 func (p *parser) op(op Op) *Regexp {