Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/int64-parse
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex committed May 4, 2021
2 parents 152c464 + 4c79cb4 commit 0718a96
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
20 changes: 18 additions & 2 deletions ferret.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ type Instance struct {
drivers *drivers.Container
}

func New() *Instance {
func New(setters ...Option) *Instance {
opts := NewOptions(setters)

return &Instance{
compiler: compiler.New(),
compiler: compiler.New(opts.compiler...),
drivers: drivers.NewContainer(),
}
}
Expand All @@ -33,6 +35,10 @@ func (i *Instance) Compile(query string) (*runtime.Program, error) {
return i.compiler.Compile(query)
}

func (i *Instance) MustCompile(query string) *runtime.Program {
return i.compiler.MustCompile(query)
}

func (i *Instance) Exec(ctx context.Context, query string, opts ...runtime.Option) ([]byte, error) {
p, err := i.Compile(query)

Expand All @@ -46,3 +52,13 @@ func (i *Instance) Exec(ctx context.Context, query string, opts ...runtime.Optio

return p.Run(ctx, opts...)
}

func (i *Instance) MustExec(ctx context.Context, query string, opts ...runtime.Option) []byte {
out, err := i.Exec(ctx, query, opts...)

if err != nil {
panic(err)
}

return out
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/PuerkitoBio/goquery v1.6.1
github.com/antchfx/htmlquery v1.2.3
github.com/antchfx/xpath v1.1.11
github.com/antlr/antlr4 v0.0.0-20200417160354-8c50731894e0
github.com/antlr/antlr4 v0.0.0-20210503161921-88ad58426b90
github.com/corpix/uarand v0.1.1
github.com/gobwas/glob v0.2.3
github.com/gorilla/css v1.0.0
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/antchfx/htmlquery v1.2.3/go.mod h1:B0ABL+F5irhhMWg54ymEZinzMSi0Kt3I2i
github.com/antchfx/xpath v1.1.6/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk=
github.com/antchfx/xpath v1.1.11 h1:WOFtK8TVAjLm3lbgqeP0arlHpvCEeTANeWZ/csPpJkQ=
github.com/antchfx/xpath v1.1.11/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
github.com/antlr/antlr4 v0.0.0-20200417160354-8c50731894e0 h1:j7MyDjg6pb7A2ziow17FDZ2Oj5vGnJsLyDmjpN4Jkcg=
github.com/antlr/antlr4 v0.0.0-20200417160354-8c50731894e0/go.mod h1:T7PbCXFs94rrTttyxjbyT5+/1V8T2TYDejxUfHJjw1Y=
github.com/antlr/antlr4 v0.0.0-20210503161921-88ad58426b90 h1:cAZnSAoHQ/c4jiymsGPsUzDXVot50CtiEMQNQTf7W6o=
github.com/antlr/antlr4 v0.0.0-20210503161921-88ad58426b90/go.mod h1:T7PbCXFs94rrTttyxjbyT5+/1V8T2TYDejxUfHJjw1Y=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
Expand Down Expand Up @@ -101,8 +101,8 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
Expand Down
29 changes: 29 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ferret

import "github.com/MontFerret/ferret/pkg/compiler"

type (
Options struct {
compiler []compiler.Option
}

Option func(opts *Options)
)

func NewOptions(setters []Option) *Options {
res := &Options{
compiler: make([]compiler.Option, 0, 2),
}

for _, setter := range setters {
setter(res)
}

return res
}

func WithoutStdlib() Option {
return func(opts *Options) {
opts.compiler = append(opts.compiler, compiler.WithoutStdlib())
}
}

0 comments on commit 0718a96

Please # to comment.