mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-19 05:36:15 +00:00
libs/pubsub/query: specify peg version in go.mod (#9099)
* libs/pubsub/query: specify peg version in go.mod The code to generate the pubsub queries was dependent on an unspecified version of the peg tool. This brings peg into go.mod so it is on a fixed version. This should also enable dependabot to notify us of future updates to peg. The version of query.peg.go generated from the current version of peg correctly contains the special "Code generated by..." line to indicate to other tools that the file is automatically generated and should therefore be excluded from linters, etc. I removed the make target as there were no git grep results referencing "gen_query_parser"; directly running "go generate" is a reasonable expectation in Go projects. Now that "go run" is module aware, I would typically use "go run" inside the go:generate directive, but in this case we go build to a gitignore-d directory in order to work around the nondeterministic output detailed in pointlander/peg#129. * libs/pubsub/query: check error from (*QueryParser).Init() The newly generated peg code returns an error from Init(); the previous version was niladic. Co-authored-by: Sam Kleinman <garen@tychoish.com>
This commit is contained in:
co-authored by
Sam Kleinman
parent
c4e235243b
commit
4309f54349
@@ -0,0 +1,7 @@
|
||||
# This is a temporary directory to hold the peg binary,
|
||||
# to work around https://github.com/pointlander/peg/issues/129.
|
||||
# Note that once we have a new version of peg fixing #129,
|
||||
# we may still want to keep this .gitignore to prevent anyone
|
||||
# from accidentally running "git add ." and including their built
|
||||
# peg binary in a commit.
|
||||
.bin/
|
||||
@@ -1,11 +1,7 @@
|
||||
gen_query_parser:
|
||||
go get -u -v github.com/pointlander/peg
|
||||
peg -inline -switch query.peg
|
||||
|
||||
fuzzy_test:
|
||||
go get -u -v github.com/dvyukov/go-fuzz/go-fuzz
|
||||
go get -u -v github.com/dvyukov/go-fuzz/go-fuzz-build
|
||||
go-fuzz-build github.com/tendermint/tendermint/libs/pubsub/query/fuzz_test
|
||||
go-fuzz -bin=./fuzz_test-fuzz.zip -workdir=./fuzz_test/output
|
||||
|
||||
.PHONY: gen_query_parser fuzzy_test
|
||||
.PHONY: fuzzy_test
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
package query
|
||||
|
||||
//go:generate peg -inline -switch query.peg
|
||||
// Normally I would use go run,
|
||||
// but the "Code generated by" comment for peg includes the full arg0,
|
||||
// which includes an unpredictable temporary directory,
|
||||
// resulting in a nondeterminstic generated source file.
|
||||
// Using go build is the workaround as detailed in https://github.com/pointlander/peg/issues/129.
|
||||
|
||||
//go:generate go build -o ./.bin/peg github.com/pointlander/peg
|
||||
//go:generate ./.bin/peg -inline -switch query.peg
|
||||
|
||||
@@ -39,7 +39,9 @@ type Condition struct {
|
||||
// invalid.
|
||||
func New(s string) (*Query, error) {
|
||||
p := &QueryParser{Buffer: fmt.Sprintf(`"%s"`, s)}
|
||||
p.Init()
|
||||
if err := p.Init(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := p.Parse(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -101,7 +103,7 @@ func (q *Query) Conditions() ([]Condition, error) {
|
||||
buffer, begin, end := q.parser.Buffer, 0, 0
|
||||
|
||||
// tokens must be in the following order: tag ("tx.gas") -> operator ("=") -> operand ("7")
|
||||
for token := range q.parser.Tokens() {
|
||||
for _, token := range q.parser.Tokens() {
|
||||
switch token.pegRule {
|
||||
case rulePegText:
|
||||
begin, end = int(token.begin), int(token.end)
|
||||
@@ -213,7 +215,7 @@ func (q *Query) Matches(events map[string][]string) (bool, error) {
|
||||
// tokens must be in the following order:
|
||||
|
||||
// tag ("tx.gas") -> operator ("=") -> operand ("7")
|
||||
for token := range q.parser.Tokens() {
|
||||
for _, token := range q.parser.Tokens() {
|
||||
switch token.pegRule {
|
||||
case rulePegText:
|
||||
begin, end = int(token.begin), int(token.end)
|
||||
|
||||
+261
-495
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user