diff --git a/go.mod b/go.mod index 2d677ed..80e8c9d 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,8 @@ module github.com/tamayika/gaq require ( - github.com/alecthomas/participle v0.1.1-0.20181115125005-28bd879b3ab5 + github.com/alecthomas/participle v0.2.0 + github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1 github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.3 // indirect diff --git a/go.sum b/go.sum index 7d5efce..852d40e 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,10 @@ github.com/alecthomas/participle v0.1.0 h1:CIpa5JECC7Y8eDoMoDdPmsrfZgSBO0IeCe+2z github.com/alecthomas/participle v0.1.0/go.mod h1:UkaznBMzS/FVetZ0dhhxVOiSBDgfLmIYp249zU1w/Z0= github.com/alecthomas/participle v0.1.1-0.20181115125005-28bd879b3ab5 h1:xiezf7zOPfxzj607UcJaUukR9KzRDZhce30gO+VIuoI= github.com/alecthomas/participle v0.1.1-0.20181115125005-28bd879b3ab5/go.mod h1:SW6HZGeZgSIpcUWX3fXpfZhuaWHnmoD5KCVaqSaNTkk= +github.com/alecthomas/participle v0.2.0 h1:MBYD61je/vgb5ktXrXth/OdH23fn1lNnT5cZLw3fkh8= +github.com/alecthomas/participle v0.2.0/go.mod h1:SW6HZGeZgSIpcUWX3fXpfZhuaWHnmoD5KCVaqSaNTkk= +github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1 h1:GDQdwm/gAcJcLAKQQZGOJ4knlw+7rfEQQcmwTbt4p5E= +github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= diff --git a/pkg/gaq/query/query.go b/pkg/gaq/query/query.go index 44e5bf6..256775a 100644 --- a/pkg/gaq/query/query.go +++ b/pkg/gaq/query/query.go @@ -12,23 +12,23 @@ import ( type Query struct { Pos lexer.Position - Selectors []*Selector `parser:"[ @@ { ',' @@ } ]"` + Selectors []*Selector `parser:"( @@ ( ',' @@ )* )?"` } -// Selector represents multiple selectors node delimited by comma +// Selector represents multiple selectors node delimited by space type Selector struct { Pos lexer.Position - SimpleSelectors []*SimpleSelector `parser:"@@ { @@ }"` + SimpleSelectors []*SimpleSelector `parser:"@@+"` } // SimpleSelector represents node selector with combinator and options type SimpleSelector struct { Pos lexer.Position - Combinator string `parser:"[ @('>' | '+' | '~') ]"` - Name string `parser:"[ @(Ident | '*') ]"` - Options []*SimpleSelectorOption `parser:"{ @@ }"` + Combinator string `parser:"( @('>' | '+' | '~')?"` + Name string `parser:" @(Ident | '*')?"` + Options []*SimpleSelectorOption `parser:" @@* )!"` } // SimpleSelectorOption represents the option for SimpleSelector @@ -44,8 +44,8 @@ type Attribute struct { Pos lexer.Position Name string `parser:"@Ident"` - Operator string `parser:"[ @('=' | ('~' '=') | ('|' '=') | ('^' '=') | ('$' '=') | ('*' '=')) ]"` - Value string `parser:"[ @(String | String2) ]"` + Operator string `parser:"@('=' | ('~' '=') | ('|' '=') | ('^' '=') | ('$' '=') | ('*' '='))?"` + Value string `parser:"@(String | String2)?"` } // Pseudo represents the pseudo option for SimpleSelector @@ -89,7 +89,7 @@ type PseudoHas struct { Pos lexer.Position Name string `parser:"'has'"` - Selectors []*Selector `parser:"'(' @@ { ',' @@ } ')'"` + Selectors []*Selector `parser:"'(' @@ ( ',' @@ )* ')'"` } // PseudoIs represents the is pseudo @@ -97,7 +97,7 @@ type PseudoIs struct { Pos lexer.Position Name string `parser:"'is'"` - Selectors []*Selector `parser:"'(' @@ { ',' @@ } ')'"` + Selectors []*Selector `parser:"'(' @@ ( ',' @@ )* ')'"` } // PseudoLastChild represents the last-child pseudo @@ -119,7 +119,7 @@ type PseudoNot struct { Pos lexer.Position Name string `parser:"'not'"` - Selectors []*Selector `parser:"'(' @@ { ',' @@ } ')'"` + Selectors []*Selector `parser:"'(' @@ ( ',' @@ )* ')'"` } // PseudoRoot represents the root pseudo diff --git a/pkg/gaq/query/query_test.go b/pkg/gaq/query/query_test.go index 02f0818..24a8b13 100644 --- a/pkg/gaq/query/query_test.go +++ b/pkg/gaq/query/query_test.go @@ -24,8 +24,8 @@ func TestParse(t *testing.T) { }, &Query{ Pos: lexer.Position{ - Line: 1, - Column: 1, + Line: 0, + Column: 0, }, }, false,