Skip to content

Commit

Permalink
Update participle to 0.2.0 and modify syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
tamayika committed Nov 23, 2018
1 parent a9afd9d commit 8c744e6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
22 changes: 11 additions & 11 deletions pkg/gaq/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -89,15 +89,15 @@ type PseudoHas struct {
Pos lexer.Position

Name string `parser:"'has'"`
Selectors []*Selector `parser:"'(' @@ { ',' @@ } ')'"`
Selectors []*Selector `parser:"'(' @@ ( ',' @@ )* ')'"`
}

// PseudoIs represents the is pseudo
type PseudoIs struct {
Pos lexer.Position

Name string `parser:"'is'"`
Selectors []*Selector `parser:"'(' @@ { ',' @@ } ')'"`
Selectors []*Selector `parser:"'(' @@ ( ',' @@ )* ')'"`
}

// PseudoLastChild represents the last-child pseudo
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/gaq/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func TestParse(t *testing.T) {
},
&Query{
Pos: lexer.Position{
Line: 1,
Column: 1,
Line: 0,
Column: 0,
},
},
false,
Expand Down

0 comments on commit 8c744e6

Please sign in to comment.