Skip to content

Commit

Permalink
Modify PEG rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 committed Jun 13, 2024
1 parent 5651d4f commit ef9e1ae
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 504 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Finschia/ostracon

go 1.20
go 1.22

require (
github.com/BurntSushi/toml v1.3.2
Expand Down Expand Up @@ -232,6 +232,9 @@ require (
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/profile v1.7.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/pointlander/compress v1.1.1-0.20190518213731-ff44bd196cc3 // indirect
github.com/pointlander/jetset v1.0.1-0.20190518214125-eee7eff80bd4 // indirect
github.com/pointlander/peg v1.0.1 // indirect
github.com/polyfloyd/go-errorlint v1.4.5 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,12 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pointlander/compress v1.1.1-0.20190518213731-ff44bd196cc3 h1:hUmXhbljNFtrH5hzV9kiRoddZ5nfPTq3K0Sb2hYYiqE=
github.com/pointlander/compress v1.1.1-0.20190518213731-ff44bd196cc3/go.mod h1:q5NXNGzqj5uPnVuhGkZfmgHqNUhf15VLi6L9kW0VEc0=
github.com/pointlander/jetset v1.0.1-0.20190518214125-eee7eff80bd4 h1:RHHRCZeaNyBXdYPMjZNH8/XHDBH38TZzw8izrW7dmBE=
github.com/pointlander/jetset v1.0.1-0.20190518214125-eee7eff80bd4/go.mod h1:RdR1j20Aj5pB6+fw6Y9Ur7lMHpegTEjY1vc19hEZL40=
github.com/pointlander/peg v1.0.1 h1:mgA/GQE8TeS9MdkU6Xn6iEzBmQUQCNuWD7rHCK6Mjs0=
github.com/pointlander/peg v1.0.1/go.mod h1:5hsGDQR2oZI4QoWz0/Kdg3VSVEC31iJw/b7WjqCBGRI=
github.com/polyfloyd/go-errorlint v1.4.5 h1:70YWmMy4FgRHehGNOUask3HtSFSOLKgmDn7ryNe7LqI=
github.com/polyfloyd/go-errorlint v1.4.5/go.mod h1:sIZEbFoDOCnTYYZoVkjc4hTnM459tuWA9H/EkdXwsKk=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
Expand Down
6 changes: 4 additions & 2 deletions libs/pubsub/query/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
gen_query_parser:
go get -u -v github.com/pointlander/peg
gen_query_parser: peg
peg -inline -switch query.peg

peg:
@go install github.com/pointlander/[email protected]

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
Expand Down
5 changes: 5 additions & 0 deletions libs/pubsub/query/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func TestParser(t *testing.T) {

{"hash='136E18F7E4C348B780CF873A0BF43922E5BAFA63'", true},
{"hash=136E18F7E4C348B780CF873A0BF43922E5BAFA63", false},

{"fnsa.dummy.v1.EventDummy.seq='\"1\"'", true},
{"fnsa.dummy.v1.EventDummy.descr='\\\"slash included\\\"'", true},
{"fnsa.dummy.v1.EventDummy.desc2='\"single quote \\' included\"'", true},
{"fnsa.dummy.v1.EventDummy.desc3='\"single quote ' included\"'", false},
}

for _, c := range cases {
Expand Down
4 changes: 2 additions & 2 deletions libs/pubsub/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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)
Expand Down Expand Up @@ -213,7 +213,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)
Expand Down
2 changes: 1 addition & 1 deletion libs/pubsub/query/query.peg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ condition <- tag ' '* (le ' '* (number / time / date)
)

tag <- < (![ \t\n\r\\()"'=><] .)+ >
value <- < '\'' (!["'] .)* '\''>
value <- < '\'' (('\\' .) / (!['] .))* '\''>
number <- < ('0'
/ [1-9] digit* ('.' digit*)?) >
digit <- [0-9]
Expand Down
Loading

0 comments on commit ef9e1ae

Please sign in to comment.