diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 00000000..d69b52c3 Binary files /dev/null and b/assets/logo.png differ diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index a8dc296e..8a6a638c 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -497,9 +497,11 @@ func TestFor(t *testing.T) { Convey("Should compile query with LIMIT 2, 2", t, func() { c := compiler.New() + // 4 is offset + // 2 is count prog, err := c.Compile(` - FOR i IN [ 1, 2, 3, 4, 1, 3 ] - LIMIT 2, 2 + FOR i IN [ 1,2,3,4,5,6,7,8 ] + LIMIT 4, 2 RETURN i `) @@ -509,7 +511,7 @@ func TestFor(t *testing.T) { So(err, ShouldBeNil) - So(string(out), ShouldEqual, `[3,4]`) + So(string(out), ShouldEqual, `[5,6]`) }) Convey("Should compile query with FILTER i > 2", t, func() { diff --git a/pkg/compiler/visitor.go b/pkg/compiler/visitor.go index 2126ecca..3ea47a20 100644 --- a/pkg/compiler/visitor.go +++ b/pkg/compiler/visitor.go @@ -292,29 +292,37 @@ func (v *visitor) doVisitForExpression(ctx *fql.ForExpressionContext, scope *sco } func (v *visitor) createLimit(ctx *fql.LimitClauseContext) (int, int, error) { - var limit int + var err error + var count int var offset int intLiterals := ctx.AllIntegerLiteral() - limitLiteral := intLiterals[0] - limit, err := strconv.Atoi(limitLiteral.GetText()) - - if err != nil { - return 0, 0, err - } - if len(intLiterals) > 1 { - offsetLiteral := intLiterals[1] + offset, err = v.parseInt(intLiterals[0]) - offset, err = strconv.Atoi(offsetLiteral.GetText()) + if err != nil { + return 0, 0, err + } + + count, err = v.parseInt(intLiterals[1]) + + if err != nil { + return 0, 0, err + } + } else { + count, err = strconv.Atoi(intLiterals[0].GetText()) if err != nil { return 0, 0, err } } - return limit, offset, nil + return count, offset, nil +} + +func (v *visitor) parseInt(node antlr.TerminalNode) (int, error) { + return strconv.Atoi(node.GetText()) } func (v *visitor) createFilter(ctx *fql.FilterClauseContext, scope *scope) (core.Expression, error) {