Skip to content

Commit 65faf70

Browse files
dmitshurgopherbot
authored andcommitted
cmd/watchflakes/internal/script: lex !~ as a single token
Even though both ~ and !~ operators are documented as supported at https://go.dev/wiki/Watchflakes, it seems only the former was ever supported in practice. As it was uncovered when I tried the latter in https://go.dev/issue/66337#issuecomment-2569872000, it fails to parse with an "unexpected !" error. The problem is that lex doesn't find the !~ token, it reports that sequence as separate tokens ! and ~. Fix its logic. Fixes golang/go#71119. Change-Id: I08dd845a59e976a5eb2687924dce972680c90077 Reviewed-on: https://go-review.googlesource.com/c/build/+/640275 Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 05d007b commit 65faf70

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

cmd/watchflakes/internal/script/script.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,23 @@ Top:
454454
p.i++
455455
p.tok = p.s[p.pos:p.i]
456456
return
457-
case '<': // <-, <=
457+
case '<': // < <- <=
458458
p.pos = p.i
459459
p.i++
460460
if p.i < len(p.s) && (p.s[p.i] == '-' || p.s[p.i] == '=') {
461461
p.i++
462462
}
463463
p.tok = p.s[p.pos:p.i]
464464
return
465-
case '!', '>': // ! != > >=
465+
case '!': // ! !~ !=
466+
p.pos = p.i
467+
p.i++
468+
if p.i < len(p.s) && (p.s[p.i] == '~' || p.s[p.i] == '=') {
469+
p.i++
470+
}
471+
p.tok = p.s[p.pos:p.i]
472+
return
473+
case '>': // > >=
466474
p.pos = p.i
467475
p.i++
468476
if p.i < len(p.s) && p.s[p.i] == '=' {

cmd/watchflakes/internal/script/script_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var lexTests = [...]struct {
2525
{"x ~", "a ~"},
2626
{"x &", "a err: :1.3: invalid syntax at &"},
2727
{"x &y", "a err: :1.3: invalid syntax at &"},
28-
{"output !~ `content`", "a ! ~ `"},
28+
{"output !~ `content`", "a !~ `"},
2929
}
3030

3131
func TestLex(t *testing.T) {

cmd/watchflakes/script_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,17 @@ var scriptTests = [...]struct {
9696
{
9797
`default <- pkg == "cmd/go" && test == "TestScript" &&
9898
output !~ ` + "`" + `The process cannot access the file because it is being used by another process.` + "`" + ` # tracked in go.dev/issue/71112`,
99-
nil,
100-
"script:2.22: unexpected !",
99+
[]*script.Rule{{
100+
Action: "default",
101+
Pattern: &script.AndExpr{
102+
X: &script.AndExpr{
103+
X: &script.CmpExpr{Field: "pkg", Op: "==", Literal: "cmd/go"},
104+
Y: &script.CmpExpr{Field: "test", Op: "==", Literal: "TestScript"},
105+
},
106+
Y: &script.RegExpr{Field: "output", Not: true, Regexp: regexp.MustCompile(`(?m)The process cannot access the file because it is being used by another process.`)},
107+
},
108+
}},
109+
"",
101110
},
102111
{
103112
`post <- pkg ~ "^cmd/go"`,

0 commit comments

Comments
 (0)