diff --git a/Makefile b/Makefile index 67fe57e618..c5a409df26 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ # * All recursive Makefiles must support the targets: all and clean. # -SUBDIRS = ast parser internal/scanner +SUBDIRS = ast internal/scanner GO_ARGS=-tags '$(GO_TAGS)' @@ -25,7 +25,6 @@ export GO_VET=env GO111MODULE=on go vet $(GO_ARGS) # List of utilities to build as part of the build process UTILS := \ - bin/$(GOOS)/pigeon \ bin/$(GOOS)/cmpgen all: $(UTILS) $(SUBDIRS) @@ -36,9 +35,6 @@ $(SUBDIRS): $(UTILS) clean: $(SUBDIRS) rm -rf bin -bin/$(GOOS)/pigeon: go.mod go.sum - $(GO_BUILD) -o $@ github.com/mna/pigeon - bin/$(GOOS)/cmpgen: ./ast/asttest/cmpgen/main.go $(GO_BUILD) -o $@ ./ast/asttest/cmpgen diff --git a/go.mod b/go.mod index 0abfe6a39f..c076e85e4a 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/mattn/go-runewidth v0.0.3 // indirect github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/mna/pigeon v1.0.1-0.20180808201053-bb0192cfc2ae github.com/opentracing/opentracing-go v1.0.2 github.com/pierrec/lz4 v2.0.5+incompatible // indirect github.com/pkg/errors v0.8.0 @@ -39,7 +38,6 @@ require ( golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 // indirect golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba // indirect - golang.org/x/tools v0.0.0-20181121193951-91f80e683c10 // indirect gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca google.golang.org/appengine v1.2.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect diff --git a/go.sum b/go.sum index f02823c13b..f671aefe40 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,6 @@ github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104 h1:d8RFOZ2IiFtFWBcKEH github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mna/pigeon v1.0.1-0.20180808201053-bb0192cfc2ae h1:mQO+oxi0kpii/TX+ltfTCFuYkOjEn53JhaOObiMuvnk= -github.com/mna/pigeon v1.0.1-0.20180808201053-bb0192cfc2ae/go.mod h1:Iym28+kJVnC1hfQvv5MUtI6AiFFzvQjHcvI4RFTG/04= github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= @@ -93,8 +91,6 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181121193951-91f80e683c10 h1:6aZMfwu0xab6imbp0uu++D3WXR+p0+RDYOqqb0uY8KU= -golang.org/x/tools v0.0.0-20181121193951-91f80e683c10/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca h1:PupagGYwj8+I4ubCxcmcBRk3VlUWtTg5huQpZR9flmE= gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6 h1:4WsZyVtkthqrHTbDCJfiTs8IWNYE4uvsSDgaV6xpp+o= diff --git a/internal/parser/parser_test.go b/internal/parser/parser_test.go index d4e06c1a71..0e4dfabbdf 100644 --- a/internal/parser/parser_test.go +++ b/internal/parser/parser_test.go @@ -438,6 +438,28 @@ func testParser(runFn func(name string, fn func(t testing.TB))) { }, }, }, + { + name: "declare variable as an empty array", + raw: `howdy = []`, + want: &ast.Program{ + BaseNode: base("1:1", "1:11"), + Body: []ast.Statement{ + &ast.VariableDeclaration{ + BaseNode: base("1:1", "1:11"), + Declarations: []*ast.VariableDeclarator{{ + BaseNode: base("1:1", "1:11"), + ID: &ast.Identifier{ + BaseNode: base("1:1", "1:6"), + Name: "howdy", + }, + Init: &ast.ArrayExpression{ + BaseNode: base("1:9", "1:11"), + }, + }}, + }, + }, + }, + }, { name: "use variable to declare something", raw: `howdy = 1 diff --git a/interpreter/interpreter.go b/interpreter/interpreter.go index 2bee063bf1..329ef46fb9 100644 --- a/interpreter/interpreter.go +++ b/interpreter/interpreter.go @@ -10,6 +10,11 @@ import ( "github.com/pkg/errors" ) +var topScope = NewScopeWithValues(map[string]values.Value{ + "true": values.NewBool(true), + "false": values.NewBool(false), +}) + // Interpreter used to interpret a Flux program type Interpreter struct { values []values.Value @@ -21,7 +26,7 @@ type Interpreter struct { // NewInterpreter instantiates a new Flux Interpreter whose builtin values are not mutable. // Options are always mutable. func NewInterpreter(options, builtins map[string]values.Value, types *TypeScope) *Interpreter { - optionScope := NewScopeWithValues(options) + optionScope := topScope.NestWithValues(options) globalScope := optionScope.NestWithValues(builtins) interpreter := &Interpreter{ options: optionScope, @@ -34,7 +39,7 @@ func NewInterpreter(options, builtins map[string]values.Value, types *TypeScope) // NewMutableInterpreter instantiates a new Flux Interpreter whose builtin values are mutable. // Options are always mutable. func NewMutableInterpreter(options, builtins map[string]values.Value, types *TypeScope) *Interpreter { - optionScope := NewScopeWithValues(options) + optionScope := topScope.NestWithValues(options) globalScope := optionScope.NestWithValues(builtins) interpreter := &Interpreter{ options: optionScope, diff --git a/parser/Makefile b/parser/Makefile deleted file mode 100644 index 854a891e97..0000000000 --- a/parser/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -all: flux.go - -flux.go: flux.peg parser.go parser_debug.go ../bin/$(GOOS)/pigeon - PATH=../bin/${GOOS}:${PATH} $(GO_GENERATE) -x ./... - -clean: - rm -f flux.go - -.PHONY: all clean diff --git a/parser/flux.go b/parser/flux.go deleted file mode 100644 index f6ddef6b84..0000000000 --- a/parser/flux.go +++ /dev/null @@ -1,5349 +0,0 @@ -// Code generated by pigeon; DO NOT EDIT. - -package parser - -import ( - "bytes" - "errors" - "fmt" - "io" - "io/ioutil" - "math" - "os" - "sort" - "strings" - "unicode" - "unicode/utf8" -) - -// DO NOT EDIT: This file is auto generated by the pigeon PEG parser generator. - -var g = &grammar{ - rules: []*rule{ - { - name: "Start", - pos: position{line: 8, col: 1, offset: 102}, - expr: &actionExpr{ - pos: position{line: 9, col: 5, offset: 112}, - run: (*parser).callonStart1, - expr: &seqExpr{ - pos: position{line: 9, col: 5, offset: 112}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 9, col: 5, offset: 112}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 9, col: 8, offset: 115}, - label: "program", - expr: &ruleRefExpr{ - pos: position{line: 9, col: 16, offset: 123}, - name: "Program", - }, - }, - &ruleRefExpr{ - pos: position{line: 9, col: 24, offset: 131}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 9, col: 27, offset: 134}, - name: "EOF", - }, - }, - }, - }, - }, - { - name: "Program", - pos: position{line: 13, col: 1, offset: 173}, - expr: &actionExpr{ - pos: position{line: 14, col: 5, offset: 185}, - run: (*parser).callonProgram1, - expr: &labeledExpr{ - pos: position{line: 14, col: 5, offset: 185}, - label: "body", - expr: &ruleRefExpr{ - pos: position{line: 14, col: 10, offset: 190}, - name: "SourceElements", - }, - }, - }, - }, - { - name: "SourceElements", - pos: position{line: 18, col: 1, offset: 256}, - expr: &actionExpr{ - pos: position{line: 19, col: 5, offset: 275}, - run: (*parser).callonSourceElements1, - expr: &seqExpr{ - pos: position{line: 19, col: 5, offset: 275}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 19, col: 5, offset: 275}, - label: "head", - expr: &ruleRefExpr{ - pos: position{line: 19, col: 10, offset: 280}, - name: "SourceElement", - }, - }, - &labeledExpr{ - pos: position{line: 19, col: 24, offset: 294}, - label: "tail", - expr: &zeroOrMoreExpr{ - pos: position{line: 19, col: 29, offset: 299}, - expr: &seqExpr{ - pos: position{line: 19, col: 30, offset: 300}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 19, col: 30, offset: 300}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 19, col: 33, offset: 303}, - name: "SourceElement", - }, - &ruleRefExpr{ - pos: position{line: 19, col: 47, offset: 317}, - name: "__", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "SourceElement", - pos: position{line: 23, col: 1, offset: 365}, - expr: &ruleRefExpr{ - pos: position{line: 24, col: 5, offset: 383}, - name: "Statement", - }, - }, - { - name: "Statement", - pos: position{line: 26, col: 1, offset: 394}, - expr: &choiceExpr{ - pos: position{line: 27, col: 5, offset: 408}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 27, col: 5, offset: 408}, - name: "VariableStatement", - }, - &ruleRefExpr{ - pos: position{line: 28, col: 5, offset: 430}, - name: "OptionStatement", - }, - &ruleRefExpr{ - pos: position{line: 29, col: 5, offset: 450}, - name: "ReturnStatement", - }, - &ruleRefExpr{ - pos: position{line: 30, col: 5, offset: 470}, - name: "ExpressionStatement", - }, - &ruleRefExpr{ - pos: position{line: 31, col: 5, offset: 494}, - name: "BlockStatement", - }, - }, - }, - }, - { - name: "OptionStatement", - pos: position{line: 34, col: 1, offset: 511}, - expr: &actionExpr{ - pos: position{line: 35, col: 5, offset: 531}, - run: (*parser).callonOptionStatement1, - expr: &seqExpr{ - pos: position{line: 35, col: 5, offset: 531}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 35, col: 5, offset: 531}, - val: "option", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 35, col: 14, offset: 540}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 35, col: 17, offset: 543}, - label: "id", - expr: &ruleRefExpr{ - pos: position{line: 35, col: 20, offset: 546}, - name: "Identifier", - }, - }, - &ruleRefExpr{ - pos: position{line: 35, col: 31, offset: 557}, - name: "__", - }, - &litMatcher{ - pos: position{line: 35, col: 34, offset: 560}, - val: "=", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 35, col: 38, offset: 564}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 35, col: 41, offset: 567}, - label: "expr", - expr: &ruleRefExpr{ - pos: position{line: 35, col: 46, offset: 572}, - name: "Expr", - }, - }, - }, - }, - }, - }, - { - name: "VariableStatement", - pos: position{line: 39, col: 1, offset: 631}, - expr: &actionExpr{ - pos: position{line: 40, col: 5, offset: 653}, - run: (*parser).callonVariableStatement1, - expr: &labeledExpr{ - pos: position{line: 40, col: 5, offset: 653}, - label: "declaration", - expr: &ruleRefExpr{ - pos: position{line: 40, col: 17, offset: 665}, - name: "VariableDeclaration", - }, - }, - }, - }, - { - name: "ReturnStatement", - pos: position{line: 44, col: 1, offset: 744}, - expr: &actionExpr{ - pos: position{line: 45, col: 5, offset: 764}, - run: (*parser).callonReturnStatement1, - expr: &seqExpr{ - pos: position{line: 45, col: 5, offset: 764}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 45, col: 5, offset: 764}, - val: "return", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 45, col: 14, offset: 773}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 45, col: 17, offset: 776}, - label: "argument", - expr: &ruleRefExpr{ - pos: position{line: 45, col: 26, offset: 785}, - name: "Expr", - }, - }, - }, - }, - }, - }, - { - name: "ExpressionStatement", - pos: position{line: 49, col: 1, offset: 848}, - expr: &actionExpr{ - pos: position{line: 50, col: 5, offset: 872}, - run: (*parser).callonExpressionStatement1, - expr: &labeledExpr{ - pos: position{line: 50, col: 5, offset: 872}, - label: "expr", - expr: &ruleRefExpr{ - pos: position{line: 50, col: 10, offset: 877}, - name: "Expr", - }, - }, - }, - }, - { - name: "BlockStatement", - pos: position{line: 54, col: 1, offset: 936}, - expr: &actionExpr{ - pos: position{line: 55, col: 5, offset: 955}, - run: (*parser).callonBlockStatement1, - expr: &seqExpr{ - pos: position{line: 55, col: 5, offset: 955}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 55, col: 5, offset: 955}, - val: "{", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 55, col: 9, offset: 959}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 55, col: 12, offset: 962}, - label: "body", - expr: &zeroOrMoreExpr{ - pos: position{line: 55, col: 17, offset: 967}, - expr: &seqExpr{ - pos: position{line: 55, col: 19, offset: 969}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 55, col: 19, offset: 969}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 55, col: 22, offset: 972}, - name: "Statement", - }, - &ruleRefExpr{ - pos: position{line: 55, col: 32, offset: 982}, - name: "__", - }, - }, - }, - }, - }, - &ruleRefExpr{ - pos: position{line: 55, col: 38, offset: 988}, - name: "__", - }, - &litMatcher{ - pos: position{line: 55, col: 41, offset: 991}, - val: "}", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "VariableDeclaration", - pos: position{line: 59, col: 1, offset: 1048}, - expr: &actionExpr{ - pos: position{line: 60, col: 5, offset: 1072}, - run: (*parser).callonVariableDeclaration1, - expr: &seqExpr{ - pos: position{line: 60, col: 5, offset: 1072}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 60, col: 5, offset: 1072}, - label: "id", - expr: &ruleRefExpr{ - pos: position{line: 60, col: 8, offset: 1075}, - name: "Identifier", - }, - }, - &ruleRefExpr{ - pos: position{line: 60, col: 19, offset: 1086}, - name: "__", - }, - &litMatcher{ - pos: position{line: 60, col: 22, offset: 1089}, - val: "=", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 60, col: 26, offset: 1093}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 60, col: 29, offset: 1096}, - label: "init", - expr: &ruleRefExpr{ - pos: position{line: 60, col: 34, offset: 1101}, - name: "Expr", - }, - }, - }, - }, - }, - }, - { - name: "MemberExpressions", - pos: position{line: 65, col: 1, offset: 1162}, - expr: &actionExpr{ - pos: position{line: 66, col: 5, offset: 1184}, - run: (*parser).callonMemberExpressions1, - expr: &seqExpr{ - pos: position{line: 66, col: 5, offset: 1184}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 66, col: 5, offset: 1184}, - label: "head", - expr: &ruleRefExpr{ - pos: position{line: 66, col: 10, offset: 1189}, - name: "Identifier", - }, - }, - &labeledExpr{ - pos: position{line: 67, col: 5, offset: 1231}, - label: "tail", - expr: &zeroOrMoreExpr{ - pos: position{line: 67, col: 10, offset: 1236}, - expr: &actionExpr{ - pos: position{line: 68, col: 10, offset: 1247}, - run: (*parser).callonMemberExpressions7, - expr: &seqExpr{ - pos: position{line: 68, col: 10, offset: 1247}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 68, col: 10, offset: 1247}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 68, col: 13, offset: 1250}, - label: "property", - expr: &ruleRefExpr{ - pos: position{line: 68, col: 22, offset: 1259}, - name: "MemberExpressionProperty", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "MemberExpressionProperty", - pos: position{line: 76, col: 1, offset: 1399}, - expr: &choiceExpr{ - pos: position{line: 77, col: 5, offset: 1428}, - alternatives: []interface{}{ - &actionExpr{ - pos: position{line: 77, col: 5, offset: 1428}, - run: (*parser).callonMemberExpressionProperty2, - expr: &seqExpr{ - pos: position{line: 77, col: 5, offset: 1428}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 77, col: 5, offset: 1428}, - val: ".", - ignoreCase: false, - }, - &labeledExpr{ - pos: position{line: 77, col: 9, offset: 1432}, - label: "property", - expr: &ruleRefExpr{ - pos: position{line: 77, col: 18, offset: 1441}, - name: "Identifier", - }, - }, - }, - }, - }, - &actionExpr{ - pos: position{line: 80, col: 7, offset: 1514}, - run: (*parser).callonMemberExpressionProperty7, - expr: &seqExpr{ - pos: position{line: 80, col: 7, offset: 1514}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 80, col: 7, offset: 1514}, - val: "[", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 80, col: 11, offset: 1518}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 80, col: 14, offset: 1521}, - label: "property", - expr: &ruleRefExpr{ - pos: position{line: 80, col: 23, offset: 1530}, - name: "StringLiteral", - }, - }, - &ruleRefExpr{ - pos: position{line: 80, col: 37, offset: 1544}, - name: "__", - }, - &litMatcher{ - pos: position{line: 80, col: 40, offset: 1547}, - val: "]", - ignoreCase: false, - }, - }, - }, - }, - &actionExpr{ - pos: position{line: 83, col: 7, offset: 1616}, - run: (*parser).callonMemberExpressionProperty15, - expr: &seqExpr{ - pos: position{line: 83, col: 7, offset: 1616}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 83, col: 7, offset: 1616}, - val: "[", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 83, col: 11, offset: 1620}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 83, col: 14, offset: 1623}, - label: "property", - expr: &ruleRefExpr{ - pos: position{line: 83, col: 23, offset: 1632}, - name: "Primary", - }, - }, - &ruleRefExpr{ - pos: position{line: 83, col: 31, offset: 1640}, - name: "__", - }, - &litMatcher{ - pos: position{line: 83, col: 34, offset: 1643}, - val: "]", - ignoreCase: false, - }, - }, - }, - }, - }, - }, - }, - { - name: "CallExpression", - pos: position{line: 87, col: 1, offset: 1689}, - expr: &actionExpr{ - pos: position{line: 88, col: 5, offset: 1708}, - run: (*parser).callonCallExpression1, - expr: &seqExpr{ - pos: position{line: 88, col: 5, offset: 1708}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 88, col: 5, offset: 1708}, - label: "head", - expr: &actionExpr{ - pos: position{line: 89, col: 7, offset: 1721}, - run: (*parser).callonCallExpression4, - expr: &seqExpr{ - pos: position{line: 89, col: 7, offset: 1721}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 89, col: 7, offset: 1721}, - label: "callee", - expr: &ruleRefExpr{ - pos: position{line: 89, col: 14, offset: 1728}, - name: "MemberExpressions", - }, - }, - &ruleRefExpr{ - pos: position{line: 89, col: 32, offset: 1746}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 89, col: 35, offset: 1749}, - label: "args", - expr: &ruleRefExpr{ - pos: position{line: 89, col: 40, offset: 1754}, - name: "Arguments", - }, - }, - }, - }, - }, - }, - &labeledExpr{ - pos: position{line: 93, col: 5, offset: 1837}, - label: "tail", - expr: &zeroOrMoreExpr{ - pos: position{line: 93, col: 10, offset: 1842}, - expr: &choiceExpr{ - pos: position{line: 94, col: 9, offset: 1852}, - alternatives: []interface{}{ - &actionExpr{ - pos: position{line: 94, col: 9, offset: 1852}, - run: (*parser).callonCallExpression14, - expr: &seqExpr{ - pos: position{line: 94, col: 9, offset: 1852}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 94, col: 9, offset: 1852}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 94, col: 12, offset: 1855}, - label: "args", - expr: &ruleRefExpr{ - pos: position{line: 94, col: 17, offset: 1860}, - name: "Arguments", - }, - }, - }, - }, - }, - &actionExpr{ - pos: position{line: 97, col: 10, offset: 1943}, - run: (*parser).callonCallExpression19, - expr: &seqExpr{ - pos: position{line: 97, col: 10, offset: 1943}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 97, col: 10, offset: 1943}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 97, col: 13, offset: 1946}, - label: "property", - expr: &ruleRefExpr{ - pos: position{line: 97, col: 22, offset: 1955}, - name: "MemberExpressionProperty", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "PipeExpression", - pos: position{line: 105, col: 1, offset: 2093}, - expr: &actionExpr{ - pos: position{line: 106, col: 5, offset: 2112}, - run: (*parser).callonPipeExpression1, - expr: &seqExpr{ - pos: position{line: 106, col: 5, offset: 2112}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 106, col: 5, offset: 2112}, - label: "head", - expr: &ruleRefExpr{ - pos: position{line: 106, col: 10, offset: 2117}, - name: "PipeExpressionHead", - }, - }, - &ruleRefExpr{ - pos: position{line: 106, col: 29, offset: 2136}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 106, col: 32, offset: 2139}, - label: "tail", - expr: &oneOrMoreExpr{ - pos: position{line: 106, col: 37, offset: 2144}, - expr: &seqExpr{ - pos: position{line: 106, col: 38, offset: 2145}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 106, col: 38, offset: 2145}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 106, col: 41, offset: 2148}, - name: "PipeExpressionPipe", - }, - &ruleRefExpr{ - pos: position{line: 106, col: 60, offset: 2167}, - name: "__", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "PipeExpressionHead", - pos: position{line: 110, col: 1, offset: 2231}, - expr: &choiceExpr{ - pos: position{line: 111, col: 5, offset: 2254}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 111, col: 5, offset: 2254}, - name: "CallExpression", - }, - &ruleRefExpr{ - pos: position{line: 112, col: 5, offset: 2395}, - name: "Literal", - }, - &ruleRefExpr{ - pos: position{line: 113, col: 5, offset: 2407}, - name: "Array", - }, - &ruleRefExpr{ - pos: position{line: 114, col: 5, offset: 2417}, - name: "MemberExpressions", - }, - &ruleRefExpr{ - pos: position{line: 115, col: 5, offset: 2439}, - name: "Identifier", - }, - &ruleRefExpr{ - pos: position{line: 116, col: 5, offset: 2454}, - name: "ObjectExpression", - }, - &ruleRefExpr{ - pos: position{line: 117, col: 5, offset: 2475}, - name: "ArrowFunctionExpression", - }, - &ruleRefExpr{ - pos: position{line: 118, col: 5, offset: 2503}, - name: "Parens", - }, - }, - }, - }, - { - name: "PipeExpressionPipe", - pos: position{line: 120, col: 1, offset: 2511}, - expr: &actionExpr{ - pos: position{line: 121, col: 5, offset: 2534}, - run: (*parser).callonPipeExpressionPipe1, - expr: &seqExpr{ - pos: position{line: 121, col: 5, offset: 2534}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 121, col: 5, offset: 2534}, - val: "|>", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 121, col: 10, offset: 2539}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 121, col: 13, offset: 2542}, - label: "call", - expr: &ruleRefExpr{ - pos: position{line: 121, col: 18, offset: 2547}, - name: "CallExpression", - }, - }, - }, - }, - }, - }, - { - name: "Arguments", - pos: position{line: 125, col: 1, offset: 2624}, - expr: &actionExpr{ - pos: position{line: 126, col: 5, offset: 2638}, - run: (*parser).callonArguments1, - expr: &seqExpr{ - pos: position{line: 126, col: 5, offset: 2638}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 126, col: 5, offset: 2638}, - val: "(", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 126, col: 9, offset: 2642}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 126, col: 12, offset: 2645}, - label: "args", - expr: &zeroOrOneExpr{ - pos: position{line: 126, col: 17, offset: 2650}, - expr: &ruleRefExpr{ - pos: position{line: 126, col: 18, offset: 2651}, - name: "ObjectProperties", - }, - }, - }, - &ruleRefExpr{ - pos: position{line: 126, col: 37, offset: 2670}, - name: "__", - }, - &litMatcher{ - pos: position{line: 126, col: 40, offset: 2673}, - val: ")", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "ArrowFunctionExpression", - pos: position{line: 130, col: 1, offset: 2709}, - expr: &actionExpr{ - pos: position{line: 131, col: 5, offset: 2737}, - run: (*parser).callonArrowFunctionExpression1, - expr: &seqExpr{ - pos: position{line: 131, col: 5, offset: 2737}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 131, col: 5, offset: 2737}, - val: "(", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 131, col: 9, offset: 2741}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 131, col: 12, offset: 2744}, - label: "params", - expr: &zeroOrOneExpr{ - pos: position{line: 131, col: 19, offset: 2751}, - expr: &ruleRefExpr{ - pos: position{line: 131, col: 19, offset: 2751}, - name: "ArrowFunctionParams", - }, - }, - }, - &ruleRefExpr{ - pos: position{line: 131, col: 40, offset: 2772}, - name: "__", - }, - &litMatcher{ - pos: position{line: 131, col: 43, offset: 2775}, - val: ")", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 131, col: 47, offset: 2779}, - name: "__", - }, - &litMatcher{ - pos: position{line: 131, col: 50, offset: 2782}, - val: "=>", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 131, col: 55, offset: 2787}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 131, col: 58, offset: 2790}, - label: "body", - expr: &ruleRefExpr{ - pos: position{line: 131, col: 63, offset: 2795}, - name: "ArrowFunctionBody", - }, - }, - &ruleRefExpr{ - pos: position{line: 131, col: 81, offset: 2813}, - name: "__", - }, - }, - }, - }, - }, - { - name: "ArrowFunctionParams", - pos: position{line: 135, col: 1, offset: 2882}, - expr: &actionExpr{ - pos: position{line: 136, col: 5, offset: 2906}, - run: (*parser).callonArrowFunctionParams1, - expr: &seqExpr{ - pos: position{line: 136, col: 5, offset: 2906}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 136, col: 5, offset: 2906}, - label: "first", - expr: &ruleRefExpr{ - pos: position{line: 136, col: 11, offset: 2912}, - name: "ArrowFunctionParam", - }, - }, - &ruleRefExpr{ - pos: position{line: 136, col: 30, offset: 2931}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 136, col: 33, offset: 2934}, - label: "rest", - expr: &zeroOrMoreExpr{ - pos: position{line: 136, col: 38, offset: 2939}, - expr: &ruleRefExpr{ - pos: position{line: 136, col: 38, offset: 2939}, - name: "ArrowFunctionParamsRest", - }, - }, - }, - &zeroOrOneExpr{ - pos: position{line: 136, col: 63, offset: 2964}, - expr: &litMatcher{ - pos: position{line: 136, col: 63, offset: 2964}, - val: ",", - ignoreCase: false, - }, - }, - }, - }, - }, - }, - { - name: "ArrowFunctionParamsRest", - pos: position{line: 140, col: 1, offset: 3049}, - expr: &actionExpr{ - pos: position{line: 141, col: 5, offset: 3077}, - run: (*parser).callonArrowFunctionParamsRest1, - expr: &seqExpr{ - pos: position{line: 141, col: 5, offset: 3077}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 141, col: 5, offset: 3077}, - val: ",", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 141, col: 9, offset: 3081}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 141, col: 13, offset: 3085}, - label: "arg", - expr: &ruleRefExpr{ - pos: position{line: 141, col: 17, offset: 3089}, - name: "ArrowFunctionParam", - }, - }, - &ruleRefExpr{ - pos: position{line: 141, col: 36, offset: 3108}, - name: "__", - }, - }, - }, - }, - }, - { - name: "ArrowFunctionParam", - pos: position{line: 145, col: 1, offset: 3142}, - expr: &choiceExpr{ - pos: position{line: 146, col: 5, offset: 3165}, - alternatives: []interface{}{ - &actionExpr{ - pos: position{line: 146, col: 5, offset: 3165}, - run: (*parser).callonArrowFunctionParam2, - expr: &seqExpr{ - pos: position{line: 146, col: 5, offset: 3165}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 146, col: 5, offset: 3165}, - label: "key", - expr: &ruleRefExpr{ - pos: position{line: 146, col: 9, offset: 3169}, - name: "Identifier", - }, - }, - &ruleRefExpr{ - pos: position{line: 146, col: 20, offset: 3180}, - name: "__", - }, - &litMatcher{ - pos: position{line: 146, col: 23, offset: 3183}, - val: "=", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 146, col: 27, offset: 3187}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 146, col: 30, offset: 3190}, - label: "value", - expr: &ruleRefExpr{ - pos: position{line: 146, col: 36, offset: 3196}, - name: "Primary", - }, - }, - &ruleRefExpr{ - pos: position{line: 146, col: 45, offset: 3205}, - name: "__", - }, - }, - }, - }, - &actionExpr{ - pos: position{line: 149, col: 5, offset: 3269}, - run: (*parser).callonArrowFunctionParam12, - expr: &seqExpr{ - pos: position{line: 149, col: 5, offset: 3269}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 149, col: 5, offset: 3269}, - label: "key", - expr: &ruleRefExpr{ - pos: position{line: 149, col: 9, offset: 3273}, - name: "Identifier", - }, - }, - &ruleRefExpr{ - pos: position{line: 149, col: 20, offset: 3284}, - name: "__", - }, - }, - }, - }, - }, - }, - }, - { - name: "ArrowFunctionBody", - pos: position{line: 154, col: 1, offset: 3345}, - expr: &choiceExpr{ - pos: position{line: 155, col: 5, offset: 3367}, - alternatives: []interface{}{ - &actionExpr{ - pos: position{line: 155, col: 5, offset: 3367}, - run: (*parser).callonArrowFunctionBody2, - expr: &labeledExpr{ - pos: position{line: 155, col: 5, offset: 3367}, - label: "body", - expr: &ruleRefExpr{ - pos: position{line: 155, col: 10, offset: 3372}, - name: "Expr", - }, - }, - }, - &actionExpr{ - pos: position{line: 158, col: 5, offset: 3412}, - run: (*parser).callonArrowFunctionBody5, - expr: &labeledExpr{ - pos: position{line: 158, col: 5, offset: 3412}, - label: "body", - expr: &ruleRefExpr{ - pos: position{line: 158, col: 10, offset: 3417}, - name: "BlockStatement", - }, - }, - }, - }, - }, - }, - { - name: "ObjectExpression", - pos: position{line: 162, col: 1, offset: 3460}, - expr: &actionExpr{ - pos: position{line: 163, col: 5, offset: 3481}, - run: (*parser).callonObjectExpression1, - expr: &seqExpr{ - pos: position{line: 163, col: 5, offset: 3481}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 163, col: 5, offset: 3481}, - val: "{", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 163, col: 9, offset: 3485}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 163, col: 12, offset: 3488}, - label: "object", - expr: &zeroOrOneExpr{ - pos: position{line: 163, col: 19, offset: 3495}, - expr: &ruleRefExpr{ - pos: position{line: 163, col: 20, offset: 3496}, - name: "ObjectProperties", - }, - }, - }, - &ruleRefExpr{ - pos: position{line: 163, col: 39, offset: 3515}, - name: "__", - }, - &litMatcher{ - pos: position{line: 163, col: 42, offset: 3518}, - val: "}", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "ObjectProperties", - pos: position{line: 167, col: 1, offset: 3552}, - expr: &actionExpr{ - pos: position{line: 168, col: 5, offset: 3573}, - run: (*parser).callonObjectProperties1, - expr: &seqExpr{ - pos: position{line: 168, col: 5, offset: 3573}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 168, col: 5, offset: 3573}, - label: "first", - expr: &ruleRefExpr{ - pos: position{line: 168, col: 11, offset: 3579}, - name: "Property", - }, - }, - &ruleRefExpr{ - pos: position{line: 168, col: 20, offset: 3588}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 168, col: 23, offset: 3591}, - label: "rest", - expr: &zeroOrMoreExpr{ - pos: position{line: 168, col: 28, offset: 3596}, - expr: &ruleRefExpr{ - pos: position{line: 168, col: 28, offset: 3596}, - name: "PropertiesRest", - }, - }, - }, - &ruleRefExpr{ - pos: position{line: 168, col: 44, offset: 3612}, - name: "__", - }, - &zeroOrOneExpr{ - pos: position{line: 168, col: 47, offset: 3615}, - expr: &litMatcher{ - pos: position{line: 168, col: 47, offset: 3615}, - val: ",", - ignoreCase: false, - }, - }, - }, - }, - }, - }, - { - name: "PropertiesRest", - pos: position{line: 172, col: 1, offset: 3681}, - expr: &actionExpr{ - pos: position{line: 173, col: 5, offset: 3700}, - run: (*parser).callonPropertiesRest1, - expr: &seqExpr{ - pos: position{line: 173, col: 5, offset: 3700}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 173, col: 5, offset: 3700}, - val: ",", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 173, col: 9, offset: 3704}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 173, col: 13, offset: 3708}, - label: "arg", - expr: &ruleRefExpr{ - pos: position{line: 173, col: 17, offset: 3712}, - name: "Property", - }, - }, - }, - }, - }, - }, - { - name: "Property", - pos: position{line: 177, col: 1, offset: 3752}, - expr: &actionExpr{ - pos: position{line: 178, col: 5, offset: 3765}, - run: (*parser).callonProperty1, - expr: &seqExpr{ - pos: position{line: 178, col: 5, offset: 3765}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 178, col: 5, offset: 3765}, - label: "key", - expr: &ruleRefExpr{ - pos: position{line: 178, col: 9, offset: 3769}, - name: "Identifier", - }, - }, - &ruleRefExpr{ - pos: position{line: 178, col: 20, offset: 3780}, - name: "__", - }, - &litMatcher{ - pos: position{line: 178, col: 24, offset: 3784}, - val: ":", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 178, col: 28, offset: 3788}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 178, col: 31, offset: 3791}, - label: "value", - expr: &ruleRefExpr{ - pos: position{line: 178, col: 37, offset: 3797}, - name: "Expr", - }, - }, - }, - }, - }, - }, - { - name: "Expr", - pos: position{line: 189, col: 1, offset: 4047}, - expr: &ruleRefExpr{ - pos: position{line: 190, col: 5, offset: 4056}, - name: "LogicalExpression", - }, - }, - { - name: "LogicalOperators", - pos: position{line: 192, col: 1, offset: 4075}, - expr: &actionExpr{ - pos: position{line: 193, col: 5, offset: 4096}, - run: (*parser).callonLogicalOperators1, - expr: &choiceExpr{ - pos: position{line: 193, col: 6, offset: 4097}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 193, col: 6, offset: 4097}, - val: "or", - ignoreCase: true, - }, - &litMatcher{ - pos: position{line: 193, col: 14, offset: 4105}, - val: "and", - ignoreCase: true, - }, - }, - }, - }, - }, - { - name: "LogicalExpression", - pos: position{line: 197, col: 1, offset: 4157}, - expr: &actionExpr{ - pos: position{line: 198, col: 5, offset: 4179}, - run: (*parser).callonLogicalExpression1, - expr: &seqExpr{ - pos: position{line: 198, col: 5, offset: 4179}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 198, col: 5, offset: 4179}, - label: "head", - expr: &ruleRefExpr{ - pos: position{line: 198, col: 10, offset: 4184}, - name: "Equality", - }, - }, - &labeledExpr{ - pos: position{line: 198, col: 19, offset: 4193}, - label: "tail", - expr: &zeroOrMoreExpr{ - pos: position{line: 198, col: 24, offset: 4198}, - expr: &seqExpr{ - pos: position{line: 198, col: 26, offset: 4200}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 198, col: 26, offset: 4200}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 198, col: 30, offset: 4204}, - name: "LogicalOperators", - }, - &ruleRefExpr{ - pos: position{line: 198, col: 47, offset: 4221}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 198, col: 51, offset: 4225}, - name: "Equality", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "EqualityOperators", - pos: position{line: 202, col: 1, offset: 4304}, - expr: &actionExpr{ - pos: position{line: 203, col: 5, offset: 4326}, - run: (*parser).callonEqualityOperators1, - expr: &choiceExpr{ - pos: position{line: 203, col: 6, offset: 4327}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 203, col: 6, offset: 4327}, - val: "==", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 203, col: 13, offset: 4334}, - val: "!=", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 203, col: 20, offset: 4341}, - val: "=~", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 203, col: 27, offset: 4348}, - val: "!~", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "Equality", - pos: position{line: 207, col: 1, offset: 4393}, - expr: &actionExpr{ - pos: position{line: 208, col: 5, offset: 4406}, - run: (*parser).callonEquality1, - expr: &seqExpr{ - pos: position{line: 208, col: 5, offset: 4406}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 208, col: 5, offset: 4406}, - label: "head", - expr: &ruleRefExpr{ - pos: position{line: 208, col: 10, offset: 4411}, - name: "Relational", - }, - }, - &labeledExpr{ - pos: position{line: 208, col: 21, offset: 4422}, - label: "tail", - expr: &zeroOrMoreExpr{ - pos: position{line: 208, col: 26, offset: 4427}, - expr: &seqExpr{ - pos: position{line: 208, col: 28, offset: 4429}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 208, col: 28, offset: 4429}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 208, col: 31, offset: 4432}, - name: "EqualityOperators", - }, - &ruleRefExpr{ - pos: position{line: 208, col: 49, offset: 4450}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 208, col: 52, offset: 4453}, - name: "Relational", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "RelationalOperators", - pos: position{line: 212, col: 1, offset: 4533}, - expr: &actionExpr{ - pos: position{line: 213, col: 5, offset: 4557}, - run: (*parser).callonRelationalOperators1, - expr: &choiceExpr{ - pos: position{line: 213, col: 9, offset: 4561}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 213, col: 9, offset: 4561}, - val: "<=", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 214, col: 9, offset: 4574}, - val: "<", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 215, col: 9, offset: 4586}, - val: ">=", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 216, col: 9, offset: 4599}, - val: ">", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 217, col: 9, offset: 4611}, - val: "startswith", - ignoreCase: true, - }, - &litMatcher{ - pos: position{line: 218, col: 9, offset: 4633}, - val: "in", - ignoreCase: true, - }, - &litMatcher{ - pos: position{line: 219, col: 9, offset: 4647}, - val: "not empty", - ignoreCase: true, - }, - &litMatcher{ - pos: position{line: 220, col: 9, offset: 4668}, - val: "empty", - ignoreCase: true, - }, - }, - }, - }, - }, - { - name: "Relational", - pos: position{line: 225, col: 1, offset: 4726}, - expr: &actionExpr{ - pos: position{line: 226, col: 5, offset: 4741}, - run: (*parser).callonRelational1, - expr: &seqExpr{ - pos: position{line: 226, col: 5, offset: 4741}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 226, col: 5, offset: 4741}, - label: "head", - expr: &ruleRefExpr{ - pos: position{line: 226, col: 10, offset: 4746}, - name: "Additive", - }, - }, - &labeledExpr{ - pos: position{line: 226, col: 19, offset: 4755}, - label: "tail", - expr: &zeroOrMoreExpr{ - pos: position{line: 226, col: 24, offset: 4760}, - expr: &seqExpr{ - pos: position{line: 226, col: 26, offset: 4762}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 226, col: 26, offset: 4762}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 226, col: 29, offset: 4765}, - name: "RelationalOperators", - }, - &ruleRefExpr{ - pos: position{line: 226, col: 49, offset: 4785}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 226, col: 52, offset: 4788}, - name: "Additive", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "AdditiveOperator", - pos: position{line: 230, col: 1, offset: 4866}, - expr: &actionExpr{ - pos: position{line: 231, col: 5, offset: 4887}, - run: (*parser).callonAdditiveOperator1, - expr: &choiceExpr{ - pos: position{line: 231, col: 6, offset: 4888}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 231, col: 6, offset: 4888}, - val: "+", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 231, col: 12, offset: 4894}, - val: "-", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "Additive", - pos: position{line: 235, col: 1, offset: 4942}, - expr: &actionExpr{ - pos: position{line: 236, col: 5, offset: 4955}, - run: (*parser).callonAdditive1, - expr: &seqExpr{ - pos: position{line: 236, col: 5, offset: 4955}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 236, col: 5, offset: 4955}, - label: "head", - expr: &ruleRefExpr{ - pos: position{line: 236, col: 10, offset: 4960}, - name: "Multiplicative", - }, - }, - &labeledExpr{ - pos: position{line: 236, col: 25, offset: 4975}, - label: "tail", - expr: &zeroOrMoreExpr{ - pos: position{line: 236, col: 30, offset: 4980}, - expr: &seqExpr{ - pos: position{line: 236, col: 32, offset: 4982}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 236, col: 32, offset: 4982}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 236, col: 35, offset: 4985}, - name: "AdditiveOperator", - }, - &ruleRefExpr{ - pos: position{line: 236, col: 52, offset: 5002}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 236, col: 55, offset: 5005}, - name: "Multiplicative", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "MultiplicativeOperator", - pos: position{line: 240, col: 1, offset: 5089}, - expr: &actionExpr{ - pos: position{line: 241, col: 5, offset: 5116}, - run: (*parser).callonMultiplicativeOperator1, - expr: &choiceExpr{ - pos: position{line: 241, col: 6, offset: 5117}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 241, col: 6, offset: 5117}, - val: "*", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 241, col: 12, offset: 5123}, - val: "/", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "Multiplicative", - pos: position{line: 245, col: 1, offset: 5167}, - expr: &actionExpr{ - pos: position{line: 246, col: 5, offset: 5186}, - run: (*parser).callonMultiplicative1, - expr: &seqExpr{ - pos: position{line: 246, col: 5, offset: 5186}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 246, col: 5, offset: 5186}, - label: "head", - expr: &ruleRefExpr{ - pos: position{line: 246, col: 10, offset: 5191}, - name: "UnaryExpression", - }, - }, - &labeledExpr{ - pos: position{line: 246, col: 26, offset: 5207}, - label: "tail", - expr: &zeroOrMoreExpr{ - pos: position{line: 246, col: 31, offset: 5212}, - expr: &seqExpr{ - pos: position{line: 246, col: 33, offset: 5214}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 246, col: 33, offset: 5214}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 246, col: 36, offset: 5217}, - name: "MultiplicativeOperator", - }, - &ruleRefExpr{ - pos: position{line: 246, col: 59, offset: 5240}, - name: "__", - }, - &ruleRefExpr{ - pos: position{line: 246, col: 62, offset: 5243}, - name: "UnaryExpression", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "UnaryOperator", - pos: position{line: 250, col: 1, offset: 5328}, - expr: &actionExpr{ - pos: position{line: 251, col: 5, offset: 5346}, - run: (*parser).callonUnaryOperator1, - expr: &choiceExpr{ - pos: position{line: 251, col: 6, offset: 5347}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 251, col: 6, offset: 5347}, - val: "-", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 251, col: 12, offset: 5353}, - val: "not", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "UnaryExpression", - pos: position{line: 255, col: 1, offset: 5399}, - expr: &choiceExpr{ - pos: position{line: 256, col: 5, offset: 5419}, - alternatives: []interface{}{ - &actionExpr{ - pos: position{line: 256, col: 5, offset: 5419}, - run: (*parser).callonUnaryExpression2, - expr: &seqExpr{ - pos: position{line: 256, col: 5, offset: 5419}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 256, col: 5, offset: 5419}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 256, col: 8, offset: 5422}, - label: "op", - expr: &ruleRefExpr{ - pos: position{line: 256, col: 11, offset: 5425}, - name: "UnaryOperator", - }, - }, - &ruleRefExpr{ - pos: position{line: 256, col: 25, offset: 5439}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 256, col: 28, offset: 5442}, - label: "argument", - expr: &ruleRefExpr{ - pos: position{line: 256, col: 37, offset: 5451}, - name: "Primary", - }, - }, - &ruleRefExpr{ - pos: position{line: 256, col: 45, offset: 5459}, - name: "__", - }, - }, - }, - }, - &ruleRefExpr{ - pos: position{line: 259, col: 5, offset: 5532}, - name: "Primary", - }, - }, - }, - }, - { - name: "Primary", - pos: position{line: 261, col: 1, offset: 5541}, - expr: &choiceExpr{ - pos: position{line: 262, col: 5, offset: 5553}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 262, col: 5, offset: 5553}, - name: "PipeExpression", - }, - &ruleRefExpr{ - pos: position{line: 263, col: 5, offset: 5572}, - name: "Array", - }, - &ruleRefExpr{ - pos: position{line: 264, col: 5, offset: 5582}, - name: "Literal", - }, - &ruleRefExpr{ - pos: position{line: 265, col: 5, offset: 5594}, - name: "CallExpression", - }, - &ruleRefExpr{ - pos: position{line: 266, col: 5, offset: 5613}, - name: "MemberExpressions", - }, - &ruleRefExpr{ - pos: position{line: 267, col: 5, offset: 5635}, - name: "Identifier", - }, - &ruleRefExpr{ - pos: position{line: 268, col: 5, offset: 5650}, - name: "ObjectExpression", - }, - &ruleRefExpr{ - pos: position{line: 269, col: 5, offset: 5671}, - name: "ArrowFunctionExpression", - }, - &ruleRefExpr{ - pos: position{line: 270, col: 5, offset: 5699}, - name: "Parens", - }, - }, - }, - }, - { - name: "Literal", - pos: position{line: 272, col: 1, offset: 5707}, - expr: &choiceExpr{ - pos: position{line: 273, col: 5, offset: 5719}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 273, col: 5, offset: 5719}, - name: "StringLiteral", - }, - &ruleRefExpr{ - pos: position{line: 274, col: 5, offset: 5737}, - name: "BooleanLiteral", - }, - &ruleRefExpr{ - pos: position{line: 275, col: 5, offset: 5756}, - name: "RegexpLiteral", - }, - &ruleRefExpr{ - pos: position{line: 276, col: 5, offset: 5774}, - name: "PipeLiteral", - }, - &ruleRefExpr{ - pos: position{line: 277, col: 5, offset: 5790}, - name: "DurationLiteral", - }, - &ruleRefExpr{ - pos: position{line: 278, col: 5, offset: 5810}, - name: "DateTimeLiteral", - }, - &ruleRefExpr{ - pos: position{line: 279, col: 5, offset: 5830}, - name: "NumberLiteral", - }, - &ruleRefExpr{ - pos: position{line: 280, col: 5, offset: 5848}, - name: "IntegerLiteral", - }, - }, - }, - }, - { - name: "Parens", - pos: position{line: 282, col: 1, offset: 5864}, - expr: &actionExpr{ - pos: position{line: 283, col: 5, offset: 5875}, - run: (*parser).callonParens1, - expr: &seqExpr{ - pos: position{line: 283, col: 5, offset: 5875}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 283, col: 5, offset: 5875}, - val: "(", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 283, col: 9, offset: 5879}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 283, col: 12, offset: 5882}, - label: "expr", - expr: &ruleRefExpr{ - pos: position{line: 283, col: 17, offset: 5887}, - name: "Expr", - }, - }, - &ruleRefExpr{ - pos: position{line: 283, col: 22, offset: 5892}, - name: "__", - }, - &litMatcher{ - pos: position{line: 283, col: 25, offset: 5895}, - val: ")", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "Array", - pos: position{line: 287, col: 1, offset: 5931}, - expr: &actionExpr{ - pos: position{line: 288, col: 5, offset: 5941}, - run: (*parser).callonArray1, - expr: &seqExpr{ - pos: position{line: 288, col: 5, offset: 5941}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 288, col: 5, offset: 5941}, - val: "[", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 288, col: 9, offset: 5945}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 288, col: 12, offset: 5948}, - label: "elements", - expr: &zeroOrOneExpr{ - pos: position{line: 288, col: 21, offset: 5957}, - expr: &ruleRefExpr{ - pos: position{line: 288, col: 21, offset: 5957}, - name: "ArrayElements", - }, - }, - }, - &ruleRefExpr{ - pos: position{line: 288, col: 36, offset: 5972}, - name: "__", - }, - &litMatcher{ - pos: position{line: 288, col: 39, offset: 5975}, - val: "]", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "ArrayElements", - pos: position{line: 295, col: 1, offset: 6097}, - expr: &actionExpr{ - pos: position{line: 296, col: 5, offset: 6115}, - run: (*parser).callonArrayElements1, - expr: &seqExpr{ - pos: position{line: 296, col: 5, offset: 6115}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 296, col: 5, offset: 6115}, - label: "first", - expr: &ruleRefExpr{ - pos: position{line: 296, col: 11, offset: 6121}, - name: "Primary", - }, - }, - &ruleRefExpr{ - pos: position{line: 296, col: 19, offset: 6129}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 296, col: 22, offset: 6132}, - label: "rest", - expr: &zeroOrMoreExpr{ - pos: position{line: 296, col: 27, offset: 6137}, - expr: &ruleRefExpr{ - pos: position{line: 296, col: 27, offset: 6137}, - name: "ArrayRest", - }, - }, - }, - }, - }, - }, - }, - { - name: "ArrayRest", - pos: position{line: 300, col: 1, offset: 6209}, - expr: &actionExpr{ - pos: position{line: 301, col: 5, offset: 6223}, - run: (*parser).callonArrayRest1, - expr: &seqExpr{ - pos: position{line: 301, col: 5, offset: 6223}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 301, col: 5, offset: 6223}, - val: ",", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 301, col: 9, offset: 6227}, - name: "__", - }, - &labeledExpr{ - pos: position{line: 301, col: 12, offset: 6230}, - label: "element", - expr: &ruleRefExpr{ - pos: position{line: 301, col: 20, offset: 6238}, - name: "Primary", - }, - }, - }, - }, - }, - }, - { - name: "DateFullYear", - pos: position{line: 305, col: 1, offset: 6281}, - expr: &seqExpr{ - pos: position{line: 306, col: 5, offset: 6298}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 306, col: 5, offset: 6298}, - name: "Digit", - }, - &ruleRefExpr{ - pos: position{line: 306, col: 11, offset: 6304}, - name: "Digit", - }, - &ruleRefExpr{ - pos: position{line: 306, col: 17, offset: 6310}, - name: "Digit", - }, - &ruleRefExpr{ - pos: position{line: 306, col: 23, offset: 6316}, - name: "Digit", - }, - }, - }, - }, - { - name: "DateMonth", - pos: position{line: 308, col: 1, offset: 6323}, - expr: &seqExpr{ - pos: position{line: 310, col: 5, offset: 6348}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 310, col: 5, offset: 6348}, - name: "Digit", - }, - &ruleRefExpr{ - pos: position{line: 310, col: 11, offset: 6354}, - name: "Digit", - }, - }, - }, - }, - { - name: "DateMDay", - pos: position{line: 312, col: 1, offset: 6361}, - expr: &seqExpr{ - pos: position{line: 315, col: 5, offset: 6431}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 315, col: 5, offset: 6431}, - name: "Digit", - }, - &ruleRefExpr{ - pos: position{line: 315, col: 11, offset: 6437}, - name: "Digit", - }, - }, - }, - }, - { - name: "TimeHour", - pos: position{line: 317, col: 1, offset: 6444}, - expr: &seqExpr{ - pos: position{line: 319, col: 5, offset: 6468}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 319, col: 5, offset: 6468}, - name: "Digit", - }, - &ruleRefExpr{ - pos: position{line: 319, col: 11, offset: 6474}, - name: "Digit", - }, - }, - }, - }, - { - name: "TimeMinute", - pos: position{line: 321, col: 1, offset: 6481}, - expr: &seqExpr{ - pos: position{line: 323, col: 5, offset: 6507}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 323, col: 5, offset: 6507}, - name: "Digit", - }, - &ruleRefExpr{ - pos: position{line: 323, col: 11, offset: 6513}, - name: "Digit", - }, - }, - }, - }, - { - name: "TimeSecond", - pos: position{line: 325, col: 1, offset: 6520}, - expr: &seqExpr{ - pos: position{line: 328, col: 5, offset: 6592}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 328, col: 5, offset: 6592}, - name: "Digit", - }, - &ruleRefExpr{ - pos: position{line: 328, col: 11, offset: 6598}, - name: "Digit", - }, - }, - }, - }, - { - name: "TimeSecFrac", - pos: position{line: 330, col: 1, offset: 6605}, - expr: &seqExpr{ - pos: position{line: 331, col: 5, offset: 6621}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 331, col: 5, offset: 6621}, - val: ".", - ignoreCase: false, - }, - &oneOrMoreExpr{ - pos: position{line: 331, col: 9, offset: 6625}, - expr: &ruleRefExpr{ - pos: position{line: 331, col: 9, offset: 6625}, - name: "Digit", - }, - }, - }, - }, - }, - { - name: "TimeNumOffset", - pos: position{line: 333, col: 1, offset: 6633}, - expr: &seqExpr{ - pos: position{line: 334, col: 5, offset: 6651}, - exprs: []interface{}{ - &choiceExpr{ - pos: position{line: 334, col: 6, offset: 6652}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 334, col: 6, offset: 6652}, - val: "+", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 334, col: 12, offset: 6658}, - val: "-", - ignoreCase: false, - }, - }, - }, - &ruleRefExpr{ - pos: position{line: 334, col: 17, offset: 6663}, - name: "TimeHour", - }, - &litMatcher{ - pos: position{line: 334, col: 26, offset: 6672}, - val: ":", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 334, col: 30, offset: 6676}, - name: "TimeMinute", - }, - }, - }, - }, - { - name: "TimeOffset", - pos: position{line: 336, col: 1, offset: 6688}, - expr: &choiceExpr{ - pos: position{line: 337, col: 6, offset: 6704}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 337, col: 6, offset: 6704}, - val: "Z", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 337, col: 12, offset: 6710}, - name: "TimeNumOffset", - }, - }, - }, - }, - { - name: "PartialTime", - pos: position{line: 339, col: 1, offset: 6726}, - expr: &seqExpr{ - pos: position{line: 340, col: 5, offset: 6742}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 340, col: 5, offset: 6742}, - name: "TimeHour", - }, - &litMatcher{ - pos: position{line: 340, col: 14, offset: 6751}, - val: ":", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 340, col: 18, offset: 6755}, - name: "TimeMinute", - }, - &litMatcher{ - pos: position{line: 340, col: 29, offset: 6766}, - val: ":", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 340, col: 33, offset: 6770}, - name: "TimeSecond", - }, - &zeroOrOneExpr{ - pos: position{line: 340, col: 44, offset: 6781}, - expr: &ruleRefExpr{ - pos: position{line: 340, col: 44, offset: 6781}, - name: "TimeSecFrac", - }, - }, - }, - }, - }, - { - name: "FullDate", - pos: position{line: 342, col: 1, offset: 6795}, - expr: &seqExpr{ - pos: position{line: 343, col: 5, offset: 6808}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 343, col: 5, offset: 6808}, - name: "DateFullYear", - }, - &litMatcher{ - pos: position{line: 343, col: 18, offset: 6821}, - val: "-", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 343, col: 22, offset: 6825}, - name: "DateMonth", - }, - &litMatcher{ - pos: position{line: 343, col: 32, offset: 6835}, - val: "-", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 343, col: 36, offset: 6839}, - name: "DateMDay", - }, - }, - }, - }, - { - name: "FullTime", - pos: position{line: 345, col: 1, offset: 6849}, - expr: &seqExpr{ - pos: position{line: 346, col: 5, offset: 6862}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 346, col: 5, offset: 6862}, - name: "PartialTime", - }, - &ruleRefExpr{ - pos: position{line: 346, col: 17, offset: 6874}, - name: "TimeOffset", - }, - }, - }, - }, - { - name: "DateTimeLiteral", - pos: position{line: 348, col: 1, offset: 6886}, - expr: &actionExpr{ - pos: position{line: 349, col: 5, offset: 6906}, - run: (*parser).callonDateTimeLiteral1, - expr: &seqExpr{ - pos: position{line: 349, col: 5, offset: 6906}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 349, col: 5, offset: 6906}, - name: "FullDate", - }, - &litMatcher{ - pos: position{line: 349, col: 14, offset: 6915}, - val: "T", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 349, col: 18, offset: 6919}, - name: "FullTime", - }, - }, - }, - }, - }, - { - name: "DurationLiteral", - pos: position{line: 356, col: 1, offset: 7181}, - expr: &actionExpr{ - pos: position{line: 357, col: 5, offset: 7201}, - run: (*parser).callonDurationLiteral1, - expr: &labeledExpr{ - pos: position{line: 357, col: 5, offset: 7201}, - label: "durations", - expr: &choiceExpr{ - pos: position{line: 358, col: 9, offset: 7221}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 358, col: 9, offset: 7221}, - name: "DayDuration", - }, - &ruleRefExpr{ - pos: position{line: 359, col: 9, offset: 7241}, - name: "HourDuration", - }, - &ruleRefExpr{ - pos: position{line: 360, col: 9, offset: 7262}, - name: "MicroSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 361, col: 9, offset: 7290}, - name: "MilliSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 362, col: 9, offset: 7318}, - name: "MonthDuration", - }, - &ruleRefExpr{ - pos: position{line: 363, col: 9, offset: 7340}, - name: "MinuteDuration", - }, - &ruleRefExpr{ - pos: position{line: 364, col: 9, offset: 7363}, - name: "NanoSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 365, col: 9, offset: 7390}, - name: "SecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 366, col: 9, offset: 7413}, - name: "WeekDuration", - }, - &ruleRefExpr{ - pos: position{line: 367, col: 9, offset: 7434}, - name: "YearDuration", - }, - }, - }, - }, - }, - }, - { - name: "YearDuration", - pos: position{line: 372, col: 1, offset: 7517}, - expr: &actionExpr{ - pos: position{line: 373, col: 5, offset: 7534}, - run: (*parser).callonYearDuration1, - expr: &seqExpr{ - pos: position{line: 373, col: 5, offset: 7534}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 373, col: 5, offset: 7534}, - label: "mag", - expr: &ruleRefExpr{ - pos: position{line: 373, col: 9, offset: 7538}, - name: "IntegerLiteral", - }, - }, - &labeledExpr{ - pos: position{line: 373, col: 24, offset: 7553}, - label: "unit", - expr: &ruleRefExpr{ - pos: position{line: 373, col: 29, offset: 7558}, - name: "YearUnits", - }, - }, - &labeledExpr{ - pos: position{line: 373, col: 39, offset: 7568}, - label: "otherParts", - expr: &zeroOrOneExpr{ - pos: position{line: 373, col: 50, offset: 7579}, - expr: &choiceExpr{ - pos: position{line: 374, col: 9, offset: 7589}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 374, col: 9, offset: 7589}, - name: "DayDuration", - }, - &ruleRefExpr{ - pos: position{line: 375, col: 9, offset: 7609}, - name: "HourDuration", - }, - &ruleRefExpr{ - pos: position{line: 376, col: 9, offset: 7630}, - name: "MicroSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 377, col: 9, offset: 7658}, - name: "MilliSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 378, col: 9, offset: 7686}, - name: "MonthDuration", - }, - &ruleRefExpr{ - pos: position{line: 379, col: 9, offset: 7708}, - name: "MinuteDuration", - }, - &ruleRefExpr{ - pos: position{line: 380, col: 9, offset: 7731}, - name: "NanoSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 381, col: 9, offset: 7758}, - name: "SecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 382, col: 9, offset: 7781}, - name: "WeekDuration", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "MonthDuration", - pos: position{line: 387, col: 1, offset: 7883}, - expr: &actionExpr{ - pos: position{line: 388, col: 5, offset: 7901}, - run: (*parser).callonMonthDuration1, - expr: &seqExpr{ - pos: position{line: 388, col: 5, offset: 7901}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 388, col: 5, offset: 7901}, - label: "mag", - expr: &ruleRefExpr{ - pos: position{line: 388, col: 9, offset: 7905}, - name: "IntegerLiteral", - }, - }, - &labeledExpr{ - pos: position{line: 388, col: 24, offset: 7920}, - label: "unit", - expr: &ruleRefExpr{ - pos: position{line: 388, col: 29, offset: 7925}, - name: "MonthUnits", - }, - }, - &labeledExpr{ - pos: position{line: 388, col: 40, offset: 7936}, - label: "otherParts", - expr: &zeroOrOneExpr{ - pos: position{line: 388, col: 51, offset: 7947}, - expr: &choiceExpr{ - pos: position{line: 389, col: 9, offset: 7957}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 389, col: 9, offset: 7957}, - name: "DayDuration", - }, - &ruleRefExpr{ - pos: position{line: 390, col: 9, offset: 7977}, - name: "HourDuration", - }, - &ruleRefExpr{ - pos: position{line: 391, col: 9, offset: 7998}, - name: "MicroSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 392, col: 9, offset: 8026}, - name: "MilliSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 393, col: 9, offset: 8054}, - name: "MinuteDuration", - }, - &ruleRefExpr{ - pos: position{line: 394, col: 9, offset: 8077}, - name: "NanoSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 395, col: 9, offset: 8104}, - name: "SecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 396, col: 9, offset: 8127}, - name: "WeekDuration", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "WeekDuration", - pos: position{line: 401, col: 1, offset: 8230}, - expr: &actionExpr{ - pos: position{line: 402, col: 5, offset: 8247}, - run: (*parser).callonWeekDuration1, - expr: &seqExpr{ - pos: position{line: 402, col: 5, offset: 8247}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 402, col: 5, offset: 8247}, - label: "mag", - expr: &ruleRefExpr{ - pos: position{line: 402, col: 9, offset: 8251}, - name: "IntegerLiteral", - }, - }, - &labeledExpr{ - pos: position{line: 402, col: 24, offset: 8266}, - label: "unit", - expr: &ruleRefExpr{ - pos: position{line: 402, col: 29, offset: 8271}, - name: "WeekUnits", - }, - }, - &labeledExpr{ - pos: position{line: 402, col: 39, offset: 8281}, - label: "otherParts", - expr: &zeroOrOneExpr{ - pos: position{line: 402, col: 50, offset: 8292}, - expr: &choiceExpr{ - pos: position{line: 403, col: 9, offset: 8302}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 403, col: 9, offset: 8302}, - name: "DayDuration", - }, - &ruleRefExpr{ - pos: position{line: 404, col: 9, offset: 8322}, - name: "HourDuration", - }, - &ruleRefExpr{ - pos: position{line: 405, col: 9, offset: 8343}, - name: "MicroSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 406, col: 9, offset: 8371}, - name: "MilliSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 407, col: 9, offset: 8399}, - name: "MinuteDuration", - }, - &ruleRefExpr{ - pos: position{line: 408, col: 9, offset: 8422}, - name: "NanoSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 409, col: 9, offset: 8449}, - name: "SecondDuration", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "DayDuration", - pos: position{line: 414, col: 1, offset: 8553}, - expr: &actionExpr{ - pos: position{line: 415, col: 5, offset: 8569}, - run: (*parser).callonDayDuration1, - expr: &seqExpr{ - pos: position{line: 415, col: 5, offset: 8569}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 415, col: 5, offset: 8569}, - label: "mag", - expr: &ruleRefExpr{ - pos: position{line: 415, col: 9, offset: 8573}, - name: "IntegerLiteral", - }, - }, - &labeledExpr{ - pos: position{line: 415, col: 24, offset: 8588}, - label: "unit", - expr: &ruleRefExpr{ - pos: position{line: 415, col: 29, offset: 8593}, - name: "DayUnits", - }, - }, - &labeledExpr{ - pos: position{line: 415, col: 38, offset: 8602}, - label: "otherParts", - expr: &zeroOrOneExpr{ - pos: position{line: 415, col: 49, offset: 8613}, - expr: &choiceExpr{ - pos: position{line: 416, col: 9, offset: 8623}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 416, col: 9, offset: 8623}, - name: "HourDuration", - }, - &ruleRefExpr{ - pos: position{line: 417, col: 9, offset: 8644}, - name: "MicroSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 418, col: 9, offset: 8672}, - name: "MilliSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 419, col: 9, offset: 8700}, - name: "MinuteDuration", - }, - &ruleRefExpr{ - pos: position{line: 420, col: 9, offset: 8723}, - name: "NanoSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 421, col: 9, offset: 8750}, - name: "SecondDuration", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "HourDuration", - pos: position{line: 426, col: 1, offset: 8854}, - expr: &actionExpr{ - pos: position{line: 427, col: 5, offset: 8871}, - run: (*parser).callonHourDuration1, - expr: &seqExpr{ - pos: position{line: 427, col: 5, offset: 8871}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 427, col: 5, offset: 8871}, - label: "mag", - expr: &ruleRefExpr{ - pos: position{line: 427, col: 9, offset: 8875}, - name: "IntegerLiteral", - }, - }, - &labeledExpr{ - pos: position{line: 427, col: 24, offset: 8890}, - label: "unit", - expr: &ruleRefExpr{ - pos: position{line: 427, col: 29, offset: 8895}, - name: "HourUnits", - }, - }, - &labeledExpr{ - pos: position{line: 427, col: 39, offset: 8905}, - label: "otherParts", - expr: &zeroOrOneExpr{ - pos: position{line: 427, col: 50, offset: 8916}, - expr: &choiceExpr{ - pos: position{line: 428, col: 9, offset: 8926}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 428, col: 9, offset: 8926}, - name: "MicroSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 429, col: 9, offset: 8954}, - name: "MilliSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 430, col: 9, offset: 8982}, - name: "MinuteDuration", - }, - &ruleRefExpr{ - pos: position{line: 431, col: 9, offset: 9005}, - name: "NanoSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 432, col: 9, offset: 9032}, - name: "SecondDuration", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "MinuteDuration", - pos: position{line: 437, col: 1, offset: 9136}, - expr: &actionExpr{ - pos: position{line: 438, col: 5, offset: 9155}, - run: (*parser).callonMinuteDuration1, - expr: &seqExpr{ - pos: position{line: 438, col: 5, offset: 9155}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 438, col: 5, offset: 9155}, - label: "mag", - expr: &ruleRefExpr{ - pos: position{line: 438, col: 9, offset: 9159}, - name: "IntegerLiteral", - }, - }, - &labeledExpr{ - pos: position{line: 438, col: 24, offset: 9174}, - label: "unit", - expr: &ruleRefExpr{ - pos: position{line: 438, col: 29, offset: 9179}, - name: "MinuteUnits", - }, - }, - &labeledExpr{ - pos: position{line: 438, col: 41, offset: 9191}, - label: "otherParts", - expr: &zeroOrOneExpr{ - pos: position{line: 438, col: 52, offset: 9202}, - expr: &choiceExpr{ - pos: position{line: 439, col: 9, offset: 9212}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 439, col: 9, offset: 9212}, - name: "MicroSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 440, col: 9, offset: 9240}, - name: "MilliSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 441, col: 9, offset: 9268}, - name: "NanoSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 442, col: 9, offset: 9295}, - name: "SecondDuration", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "SecondDuration", - pos: position{line: 447, col: 1, offset: 9399}, - expr: &actionExpr{ - pos: position{line: 448, col: 5, offset: 9418}, - run: (*parser).callonSecondDuration1, - expr: &seqExpr{ - pos: position{line: 448, col: 5, offset: 9418}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 448, col: 5, offset: 9418}, - label: "mag", - expr: &ruleRefExpr{ - pos: position{line: 448, col: 9, offset: 9422}, - name: "IntegerLiteral", - }, - }, - &labeledExpr{ - pos: position{line: 448, col: 24, offset: 9437}, - label: "unit", - expr: &ruleRefExpr{ - pos: position{line: 448, col: 29, offset: 9442}, - name: "SecondUnits", - }, - }, - &labeledExpr{ - pos: position{line: 448, col: 41, offset: 9454}, - label: "otherParts", - expr: &zeroOrOneExpr{ - pos: position{line: 448, col: 52, offset: 9465}, - expr: &choiceExpr{ - pos: position{line: 449, col: 9, offset: 9475}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 449, col: 9, offset: 9475}, - name: "MicroSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 450, col: 9, offset: 9503}, - name: "MilliSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 451, col: 9, offset: 9531}, - name: "NanoSecondDuration", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "MilliSecondDuration", - pos: position{line: 456, col: 1, offset: 9639}, - expr: &actionExpr{ - pos: position{line: 457, col: 5, offset: 9663}, - run: (*parser).callonMilliSecondDuration1, - expr: &seqExpr{ - pos: position{line: 457, col: 5, offset: 9663}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 457, col: 5, offset: 9663}, - label: "mag", - expr: &ruleRefExpr{ - pos: position{line: 457, col: 9, offset: 9667}, - name: "IntegerLiteral", - }, - }, - &labeledExpr{ - pos: position{line: 457, col: 24, offset: 9682}, - label: "unit", - expr: &ruleRefExpr{ - pos: position{line: 457, col: 29, offset: 9687}, - name: "MilliSecondUnits", - }, - }, - &labeledExpr{ - pos: position{line: 457, col: 46, offset: 9704}, - label: "otherParts", - expr: &zeroOrOneExpr{ - pos: position{line: 457, col: 57, offset: 9715}, - expr: &choiceExpr{ - pos: position{line: 458, col: 9, offset: 9725}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 458, col: 9, offset: 9725}, - name: "MicroSecondDuration", - }, - &ruleRefExpr{ - pos: position{line: 459, col: 9, offset: 9753}, - name: "NanoSecondDuration", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "MicroSecondDuration", - pos: position{line: 464, col: 1, offset: 9861}, - expr: &actionExpr{ - pos: position{line: 465, col: 5, offset: 9885}, - run: (*parser).callonMicroSecondDuration1, - expr: &seqExpr{ - pos: position{line: 465, col: 5, offset: 9885}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 465, col: 5, offset: 9885}, - label: "mag", - expr: &ruleRefExpr{ - pos: position{line: 465, col: 9, offset: 9889}, - name: "IntegerLiteral", - }, - }, - &labeledExpr{ - pos: position{line: 465, col: 24, offset: 9904}, - label: "unit", - expr: &ruleRefExpr{ - pos: position{line: 465, col: 29, offset: 9909}, - name: "MicroSecondUnits", - }, - }, - &labeledExpr{ - pos: position{line: 465, col: 46, offset: 9926}, - label: "otherParts", - expr: &zeroOrOneExpr{ - pos: position{line: 465, col: 57, offset: 9937}, - expr: &ruleRefExpr{ - pos: position{line: 466, col: 7, offset: 9945}, - name: "NanoSecondDuration", - }, - }, - }, - }, - }, - }, - }, - { - name: "NanoSecondDuration", - pos: position{line: 471, col: 1, offset: 10053}, - expr: &actionExpr{ - pos: position{line: 472, col: 5, offset: 10076}, - run: (*parser).callonNanoSecondDuration1, - expr: &seqExpr{ - pos: position{line: 472, col: 5, offset: 10076}, - exprs: []interface{}{ - &labeledExpr{ - pos: position{line: 472, col: 5, offset: 10076}, - label: "mag", - expr: &ruleRefExpr{ - pos: position{line: 472, col: 9, offset: 10080}, - name: "IntegerLiteral", - }, - }, - &labeledExpr{ - pos: position{line: 472, col: 24, offset: 10095}, - label: "unit", - expr: &ruleRefExpr{ - pos: position{line: 472, col: 29, offset: 10100}, - name: "NanoSecondUnits", - }, - }, - }, - }, - }, - }, - { - name: "NanoSecondUnits", - pos: position{line: 476, col: 1, offset: 10191}, - expr: &litMatcher{ - pos: position{line: 477, col: 5, offset: 10211}, - val: "ns", - ignoreCase: false, - }, - }, - { - name: "MicroSecondUnits", - pos: position{line: 479, col: 1, offset: 10217}, - expr: &actionExpr{ - pos: position{line: 480, col: 5, offset: 10238}, - run: (*parser).callonMicroSecondUnits1, - expr: &choiceExpr{ - pos: position{line: 480, col: 6, offset: 10239}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 480, col: 6, offset: 10239}, - val: "us", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 480, col: 13, offset: 10246}, - val: "µs", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 480, col: 20, offset: 10254}, - val: "μs", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "MilliSecondUnits", - pos: position{line: 484, col: 1, offset: 10301}, - expr: &litMatcher{ - pos: position{line: 485, col: 5, offset: 10322}, - val: "ms", - ignoreCase: false, - }, - }, - { - name: "SecondUnits", - pos: position{line: 487, col: 1, offset: 10328}, - expr: &litMatcher{ - pos: position{line: 488, col: 5, offset: 10344}, - val: "s", - ignoreCase: false, - }, - }, - { - name: "MinuteUnits", - pos: position{line: 490, col: 1, offset: 10349}, - expr: &litMatcher{ - pos: position{line: 491, col: 5, offset: 10365}, - val: "m", - ignoreCase: false, - }, - }, - { - name: "HourUnits", - pos: position{line: 493, col: 1, offset: 10370}, - expr: &litMatcher{ - pos: position{line: 494, col: 5, offset: 10384}, - val: "h", - ignoreCase: false, - }, - }, - { - name: "DayUnits", - pos: position{line: 496, col: 1, offset: 10389}, - expr: &litMatcher{ - pos: position{line: 497, col: 5, offset: 10402}, - val: "d", - ignoreCase: false, - }, - }, - { - name: "WeekUnits", - pos: position{line: 499, col: 1, offset: 10407}, - expr: &litMatcher{ - pos: position{line: 500, col: 5, offset: 10421}, - val: "w", - ignoreCase: false, - }, - }, - { - name: "MonthUnits", - pos: position{line: 502, col: 1, offset: 10426}, - expr: &litMatcher{ - pos: position{line: 503, col: 5, offset: 10441}, - val: "mo", - ignoreCase: false, - }, - }, - { - name: "YearUnits", - pos: position{line: 505, col: 1, offset: 10447}, - expr: &litMatcher{ - pos: position{line: 506, col: 5, offset: 10461}, - val: "y", - ignoreCase: false, - }, - }, - { - name: "StringLiteral", - pos: position{line: 508, col: 1, offset: 10466}, - expr: &choiceExpr{ - pos: position{line: 509, col: 5, offset: 10484}, - alternatives: []interface{}{ - &actionExpr{ - pos: position{line: 509, col: 5, offset: 10484}, - run: (*parser).callonStringLiteral2, - expr: &seqExpr{ - pos: position{line: 509, col: 7, offset: 10486}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 509, col: 7, offset: 10486}, - val: "\"", - ignoreCase: false, - }, - &zeroOrMoreExpr{ - pos: position{line: 509, col: 11, offset: 10490}, - expr: &ruleRefExpr{ - pos: position{line: 509, col: 11, offset: 10490}, - name: "DoubleStringChar", - }, - }, - &litMatcher{ - pos: position{line: 509, col: 29, offset: 10508}, - val: "\"", - ignoreCase: false, - }, - }, - }, - }, - &actionExpr{ - pos: position{line: 512, col: 5, offset: 10568}, - run: (*parser).callonStringLiteral8, - expr: &seqExpr{ - pos: position{line: 512, col: 7, offset: 10570}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 512, col: 7, offset: 10570}, - val: "\"", - ignoreCase: false, - }, - &zeroOrMoreExpr{ - pos: position{line: 512, col: 11, offset: 10574}, - expr: &ruleRefExpr{ - pos: position{line: 512, col: 11, offset: 10574}, - name: "DoubleStringChar", - }, - }, - &choiceExpr{ - pos: position{line: 512, col: 31, offset: 10594}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 512, col: 31, offset: 10594}, - name: "EOL", - }, - &ruleRefExpr{ - pos: position{line: 512, col: 37, offset: 10600}, - name: "EOF", - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "DoubleStringChar", - pos: position{line: 516, col: 1, offset: 10678}, - expr: &choiceExpr{ - pos: position{line: 517, col: 5, offset: 10699}, - alternatives: []interface{}{ - &seqExpr{ - pos: position{line: 517, col: 5, offset: 10699}, - exprs: []interface{}{ - ¬Expr{ - pos: position{line: 517, col: 5, offset: 10699}, - expr: &choiceExpr{ - pos: position{line: 517, col: 8, offset: 10702}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 517, col: 8, offset: 10702}, - val: "\"", - ignoreCase: false, - }, - &litMatcher{ - pos: position{line: 517, col: 14, offset: 10708}, - val: "\\", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 517, col: 21, offset: 10715}, - name: "EOL", - }, - }, - }, - }, - &ruleRefExpr{ - pos: position{line: 517, col: 27, offset: 10721}, - name: "SourceChar", - }, - }, - }, - &seqExpr{ - pos: position{line: 518, col: 5, offset: 10736}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 518, col: 5, offset: 10736}, - val: "\\", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 518, col: 10, offset: 10741}, - name: "DoubleStringEscape", - }, - }, - }, - }, - }, - }, - { - name: "DoubleStringEscape", - pos: position{line: 520, col: 1, offset: 10761}, - expr: &choiceExpr{ - pos: position{line: 521, col: 5, offset: 10784}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 521, col: 5, offset: 10784}, - val: "\"", - ignoreCase: false, - }, - &actionExpr{ - pos: position{line: 522, col: 5, offset: 10792}, - run: (*parser).callonDoubleStringEscape3, - expr: &choiceExpr{ - pos: position{line: 522, col: 7, offset: 10794}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 522, col: 7, offset: 10794}, - name: "SourceChar", - }, - &ruleRefExpr{ - pos: position{line: 522, col: 20, offset: 10807}, - name: "EOL", - }, - &ruleRefExpr{ - pos: position{line: 522, col: 26, offset: 10813}, - name: "EOF", - }, - }, - }, - }, - }, - }, - }, - { - name: "RegexpLiteral", - pos: position{line: 527, col: 1, offset: 10886}, - expr: &actionExpr{ - pos: position{line: 528, col: 5, offset: 10904}, - run: (*parser).callonRegexpLiteral1, - expr: &seqExpr{ - pos: position{line: 528, col: 5, offset: 10904}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 528, col: 5, offset: 10904}, - val: "/", - ignoreCase: false, - }, - &labeledExpr{ - pos: position{line: 528, col: 9, offset: 10908}, - label: "pattern", - expr: &ruleRefExpr{ - pos: position{line: 528, col: 17, offset: 10916}, - name: "RegexpBody", - }, - }, - &litMatcher{ - pos: position{line: 528, col: 28, offset: 10927}, - val: "/", - ignoreCase: false, - }, - }, - }, - }, - }, - { - name: "RegexpBody", - pos: position{line: 532, col: 1, offset: 10970}, - expr: &actionExpr{ - pos: position{line: 533, col: 5, offset: 10985}, - run: (*parser).callonRegexpBody1, - expr: &labeledExpr{ - pos: position{line: 533, col: 5, offset: 10985}, - label: "chars", - expr: &oneOrMoreExpr{ - pos: position{line: 533, col: 11, offset: 10991}, - expr: &ruleRefExpr{ - pos: position{line: 533, col: 11, offset: 10991}, - name: "RegexpChar", - }, - }, - }, - }, - }, - { - name: "RegexpChar", - pos: position{line: 537, col: 1, offset: 11060}, - expr: &choiceExpr{ - pos: position{line: 538, col: 5, offset: 11075}, - alternatives: []interface{}{ - &actionExpr{ - pos: position{line: 538, col: 5, offset: 11075}, - run: (*parser).callonRegexpChar2, - expr: &seqExpr{ - pos: position{line: 538, col: 5, offset: 11075}, - exprs: []interface{}{ - ¬Expr{ - pos: position{line: 538, col: 5, offset: 11075}, - expr: &charClassMatcher{ - pos: position{line: 538, col: 6, offset: 11076}, - val: "[\\\\/]", - chars: []rune{'\\', '/'}, - ignoreCase: false, - inverted: false, - }, - }, - &labeledExpr{ - pos: position{line: 538, col: 12, offset: 11082}, - label: "re", - expr: &ruleRefExpr{ - pos: position{line: 538, col: 15, offset: 11085}, - name: "RegexpNonTerminator", - }, - }, - }, - }, - }, - &ruleRefExpr{ - pos: position{line: 541, col: 5, offset: 11138}, - name: "RegexpBackslashSequence", - }, - }, - }, - }, - { - name: "RegexpBackslashSequence", - pos: position{line: 543, col: 1, offset: 11163}, - expr: &choiceExpr{ - pos: position{line: 544, col: 5, offset: 11191}, - alternatives: []interface{}{ - &actionExpr{ - pos: position{line: 544, col: 5, offset: 11191}, - run: (*parser).callonRegexpBackslashSequence2, - expr: &litMatcher{ - pos: position{line: 544, col: 5, offset: 11191}, - val: "\\/", - ignoreCase: false, - }, - }, - &actionExpr{ - pos: position{line: 547, col: 5, offset: 11239}, - run: (*parser).callonRegexpBackslashSequence4, - expr: &seqExpr{ - pos: position{line: 547, col: 5, offset: 11239}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 547, col: 5, offset: 11239}, - val: "\\", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 547, col: 10, offset: 11244}, - name: "RegexpNonTerminator", - }, - }, - }, - }, - }, - }, - }, - { - name: "RegexpNonTerminator", - pos: position{line: 551, col: 1, offset: 11298}, - expr: &actionExpr{ - pos: position{line: 552, col: 5, offset: 11322}, - run: (*parser).callonRegexpNonTerminator1, - expr: &seqExpr{ - pos: position{line: 552, col: 5, offset: 11322}, - exprs: []interface{}{ - ¬Expr{ - pos: position{line: 552, col: 5, offset: 11322}, - expr: &ruleRefExpr{ - pos: position{line: 552, col: 6, offset: 11323}, - name: "LineTerminator", - }, - }, - &ruleRefExpr{ - pos: position{line: 552, col: 21, offset: 11338}, - name: "SourceChar", - }, - }, - }, - }, - }, - { - name: "BooleanLiteral", - pos: position{line: 556, col: 1, offset: 11383}, - expr: &choiceExpr{ - pos: position{line: 557, col: 5, offset: 11402}, - alternatives: []interface{}{ - &actionExpr{ - pos: position{line: 557, col: 5, offset: 11402}, - run: (*parser).callonBooleanLiteral2, - expr: &seqExpr{ - pos: position{line: 557, col: 5, offset: 11402}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 557, col: 5, offset: 11402}, - name: "__", - }, - &litMatcher{ - pos: position{line: 557, col: 8, offset: 11405}, - val: "true", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 557, col: 15, offset: 11412}, - name: "__", - }, - }, - }, - }, - &actionExpr{ - pos: position{line: 560, col: 5, offset: 11476}, - run: (*parser).callonBooleanLiteral7, - expr: &seqExpr{ - pos: position{line: 560, col: 5, offset: 11476}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 560, col: 5, offset: 11476}, - name: "__", - }, - &litMatcher{ - pos: position{line: 560, col: 8, offset: 11479}, - val: "false", - ignoreCase: false, - }, - &ruleRefExpr{ - pos: position{line: 560, col: 16, offset: 11487}, - name: "__", - }, - }, - }, - }, - }, - }, - }, - { - name: "NumberLiteral", - pos: position{line: 564, col: 1, offset: 11549}, - expr: &actionExpr{ - pos: position{line: 565, col: 5, offset: 11567}, - run: (*parser).callonNumberLiteral1, - expr: &seqExpr{ - pos: position{line: 565, col: 5, offset: 11567}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 565, col: 5, offset: 11567}, - name: "Integer", - }, - &litMatcher{ - pos: position{line: 565, col: 13, offset: 11575}, - val: ".", - ignoreCase: false, - }, - &oneOrMoreExpr{ - pos: position{line: 565, col: 17, offset: 11579}, - expr: &ruleRefExpr{ - pos: position{line: 565, col: 17, offset: 11579}, - name: "Digit", - }, - }, - }, - }, - }, - }, - { - name: "Integer", - pos: position{line: 569, col: 1, offset: 11636}, - expr: &choiceExpr{ - pos: position{line: 570, col: 6, offset: 11649}, - alternatives: []interface{}{ - &litMatcher{ - pos: position{line: 570, col: 6, offset: 11649}, - val: "0", - ignoreCase: false, - }, - &seqExpr{ - pos: position{line: 570, col: 12, offset: 11655}, - exprs: []interface{}{ - &ruleRefExpr{ - pos: position{line: 570, col: 12, offset: 11655}, - name: "NonZeroDigit", - }, - &zeroOrMoreExpr{ - pos: position{line: 570, col: 25, offset: 11668}, - expr: &ruleRefExpr{ - pos: position{line: 570, col: 25, offset: 11668}, - name: "Digit", - }, - }, - }, - }, - }, - }, - }, - { - name: "IntegerLiteral", - pos: position{line: 572, col: 1, offset: 11677}, - expr: &actionExpr{ - pos: position{line: 573, col: 5, offset: 11696}, - run: (*parser).callonIntegerLiteral1, - expr: &ruleRefExpr{ - pos: position{line: 573, col: 5, offset: 11696}, - name: "Integer", - }, - }, - }, - { - name: "NonZeroDigit", - pos: position{line: 577, col: 1, offset: 11756}, - expr: &charClassMatcher{ - pos: position{line: 578, col: 5, offset: 11773}, - val: "[1-9]", - ranges: []rune{'1', '9'}, - ignoreCase: false, - inverted: false, - }, - }, - { - name: "Digit", - pos: position{line: 580, col: 1, offset: 11780}, - expr: &charClassMatcher{ - pos: position{line: 581, col: 5, offset: 11790}, - val: "[0-9]", - ranges: []rune{'0', '9'}, - ignoreCase: false, - inverted: false, - }, - }, - { - name: "PipeLiteral", - pos: position{line: 583, col: 1, offset: 11797}, - expr: &actionExpr{ - pos: position{line: 584, col: 5, offset: 11813}, - run: (*parser).callonPipeLiteral1, - expr: &litMatcher{ - pos: position{line: 584, col: 5, offset: 11813}, - val: "<-", - ignoreCase: false, - }, - }, - }, - { - name: "Identifier", - pos: position{line: 589, col: 1, offset: 11877}, - expr: &actionExpr{ - pos: position{line: 591, col: 5, offset: 11999}, - run: (*parser).callonIdentifier1, - expr: &seqExpr{ - pos: position{line: 591, col: 5, offset: 11999}, - exprs: []interface{}{ - &charClassMatcher{ - pos: position{line: 591, col: 5, offset: 11999}, - val: "[_\\pL]", - chars: []rune{'_'}, - classes: []*unicode.RangeTable{rangeTable("L")}, - ignoreCase: false, - inverted: false, - }, - &zeroOrMoreExpr{ - pos: position{line: 591, col: 11, offset: 12005}, - expr: &charClassMatcher{ - pos: position{line: 591, col: 11, offset: 12005}, - val: "[_0-9\\pL]", - chars: []rune{'_'}, - ranges: []rune{'0', '9'}, - classes: []*unicode.RangeTable{rangeTable("L")}, - ignoreCase: false, - inverted: false, - }, - }, - }, - }, - }, - }, - { - name: "SourceChar", - pos: position{line: 596, col: 1, offset: 12065}, - expr: &anyMatcher{ - line: 597, col: 5, offset: 12080, - }, - }, - { - name: "__", - pos: position{line: 598, col: 1, offset: 12082}, - expr: &zeroOrMoreExpr{ - pos: position{line: 599, col: 5, offset: 12089}, - expr: &choiceExpr{ - pos: position{line: 599, col: 7, offset: 12091}, - alternatives: []interface{}{ - &ruleRefExpr{ - pos: position{line: 599, col: 7, offset: 12091}, - name: "ws", - }, - &ruleRefExpr{ - pos: position{line: 599, col: 12, offset: 12096}, - name: "EOL", - }, - &ruleRefExpr{ - pos: position{line: 599, col: 18, offset: 12102}, - name: "Comment", - }, - }, - }, - }, - }, - { - name: "Comment", - pos: position{line: 601, col: 1, offset: 12114}, - expr: &seqExpr{ - pos: position{line: 602, col: 5, offset: 12126}, - exprs: []interface{}{ - &litMatcher{ - pos: position{line: 602, col: 5, offset: 12126}, - val: "//", - ignoreCase: false, - }, - &zeroOrMoreExpr{ - pos: position{line: 602, col: 10, offset: 12131}, - expr: &charClassMatcher{ - pos: position{line: 602, col: 10, offset: 12131}, - val: "[^\\r\\n]", - chars: []rune{'\r', '\n'}, - ignoreCase: false, - inverted: true, - }, - }, - &ruleRefExpr{ - pos: position{line: 602, col: 19, offset: 12140}, - name: "EOL", - }, - }, - }, - }, - { - name: "ws", - pos: position{line: 604, col: 1, offset: 12145}, - expr: &charClassMatcher{ - pos: position{line: 605, col: 5, offset: 12152}, - val: "[ \\t\\r\\n]", - chars: []rune{' ', '\t', '\r', '\n'}, - ignoreCase: false, - inverted: false, - }, - }, - { - name: "LineTerminator", - pos: position{line: 607, col: 1, offset: 12163}, - expr: &charClassMatcher{ - pos: position{line: 608, col: 5, offset: 12182}, - val: "[\\n\\r]", - chars: []rune{'\n', '\r'}, - ignoreCase: false, - inverted: false, - }, - }, - { - name: "EOL", - pos: position{line: 610, col: 1, offset: 12190}, - expr: &litMatcher{ - pos: position{line: 611, col: 5, offset: 12198}, - val: "\n", - ignoreCase: false, - }, - }, - { - name: "EOF", - pos: position{line: 613, col: 1, offset: 12204}, - expr: ¬Expr{ - pos: position{line: 614, col: 5, offset: 12212}, - expr: &anyMatcher{ - line: 614, col: 6, offset: 12213, - }, - }, - }, - }, -} - -func (c *current) onStart1(program interface{}) (interface{}, error) { - return program, nil - -} - -func (p *parser) callonStart1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onStart1(stack["program"]) -} - -func (c *current) onProgram1(body interface{}) (interface{}, error) { - return program(body, c.text, c.pos) - -} - -func (p *parser) callonProgram1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onProgram1(stack["body"]) -} - -func (c *current) onSourceElements1(head, tail interface{}) (interface{}, error) { - return srcElems(head, tail) - -} - -func (p *parser) callonSourceElements1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onSourceElements1(stack["head"], stack["tail"]) -} - -func (c *current) onOptionStatement1(id, expr interface{}) (interface{}, error) { - return optionstmt(id, expr, c.text, c.pos) - -} - -func (p *parser) callonOptionStatement1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onOptionStatement1(stack["id"], stack["expr"]) -} - -func (c *current) onVariableStatement1(declaration interface{}) (interface{}, error) { - return varstmt(declaration, c.text, c.pos) - -} - -func (p *parser) callonVariableStatement1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onVariableStatement1(stack["declaration"]) -} - -func (c *current) onReturnStatement1(argument interface{}) (interface{}, error) { - return returnstmt(argument, c.text, c.pos) - -} - -func (p *parser) callonReturnStatement1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onReturnStatement1(stack["argument"]) -} - -func (c *current) onExpressionStatement1(expr interface{}) (interface{}, error) { - return exprstmt(expr, c.text, c.pos) - -} - -func (p *parser) callonExpressionStatement1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onExpressionStatement1(stack["expr"]) -} - -func (c *current) onBlockStatement1(body interface{}) (interface{}, error) { - return blockstmt(body, c.text, c.pos) - -} - -func (p *parser) callonBlockStatement1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onBlockStatement1(stack["body"]) -} - -func (c *current) onVariableDeclaration1(id, init interface{}) (interface{}, error) { - return vardecl(id, init, c.text, c.pos) - -} - -func (p *parser) callonVariableDeclaration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onVariableDeclaration1(stack["id"], stack["init"]) -} - -func (c *current) onMemberExpressions7(property interface{}) (interface{}, error) { - return property, nil - -} - -func (p *parser) callonMemberExpressions7() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMemberExpressions7(stack["property"]) -} - -func (c *current) onMemberExpressions1(head, tail interface{}) (interface{}, error) { - return memberexprs(head, tail, c.text, c.pos) - -} - -func (p *parser) callonMemberExpressions1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMemberExpressions1(stack["head"], stack["tail"]) -} - -func (c *current) onMemberExpressionProperty2(property interface{}) (interface{}, error) { - return memberExprFromIdentifier(property) - -} - -func (p *parser) callonMemberExpressionProperty2() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMemberExpressionProperty2(stack["property"]) -} - -func (c *current) onMemberExpressionProperty7(property interface{}) (interface{}, error) { - return memberExprFromStringLiteral(property) - -} - -func (p *parser) callonMemberExpressionProperty7() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMemberExpressionProperty7(stack["property"]) -} - -func (c *current) onMemberExpressionProperty15(property interface{}) (interface{}, error) { - return indexExpr(property) - -} - -func (p *parser) callonMemberExpressionProperty15() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMemberExpressionProperty15(stack["property"]) -} - -func (c *current) onCallExpression4(callee, args interface{}) (interface{}, error) { - return callexpr(callee, args, c.text, c.pos) - -} - -func (p *parser) callonCallExpression4() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onCallExpression4(stack["callee"], stack["args"]) -} - -func (c *current) onCallExpression14(args interface{}) (interface{}, error) { - return callexpr(nil, args, c.text, c.pos) - -} - -func (p *parser) callonCallExpression14() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onCallExpression14(stack["args"]) -} - -func (c *current) onCallExpression19(property interface{}) (interface{}, error) { - return property, nil - -} - -func (p *parser) callonCallExpression19() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onCallExpression19(stack["property"]) -} - -func (c *current) onCallExpression1(head, tail interface{}) (interface{}, error) { - return callexprs(head, tail, c.text, c.pos) - -} - -func (p *parser) callonCallExpression1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onCallExpression1(stack["head"], stack["tail"]) -} - -func (c *current) onPipeExpression1(head, tail interface{}) (interface{}, error) { - return pipeExprs(head, tail, c.text, c.pos) - -} - -func (p *parser) callonPipeExpression1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onPipeExpression1(stack["head"], stack["tail"]) -} - -func (c *current) onPipeExpressionPipe1(call interface{}) (interface{}, error) { - return incompletePipeExpr(call, c.text, c.pos) - -} - -func (p *parser) callonPipeExpressionPipe1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onPipeExpressionPipe1(stack["call"]) -} - -func (c *current) onArguments1(args interface{}) (interface{}, error) { - return args, nil - -} - -func (p *parser) callonArguments1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArguments1(stack["args"]) -} - -func (c *current) onArrowFunctionExpression1(params, body interface{}) (interface{}, error) { - return arrowfunc(params, body, c.text, c.pos), nil - -} - -func (p *parser) callonArrowFunctionExpression1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArrowFunctionExpression1(stack["params"], stack["body"]) -} - -func (c *current) onArrowFunctionParams1(first, rest interface{}) (interface{}, error) { - return append([]interface{}{first}, toIfaceSlice(rest)...), nil - -} - -func (p *parser) callonArrowFunctionParams1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArrowFunctionParams1(stack["first"], stack["rest"]) -} - -func (c *current) onArrowFunctionParamsRest1(arg interface{}) (interface{}, error) { - return arg, nil - -} - -func (p *parser) callonArrowFunctionParamsRest1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArrowFunctionParamsRest1(stack["arg"]) -} - -func (c *current) onArrowFunctionParam2(key, value interface{}) (interface{}, error) { - return property(key, value, c.text, c.pos) - -} - -func (p *parser) callonArrowFunctionParam2() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArrowFunctionParam2(stack["key"], stack["value"]) -} - -func (c *current) onArrowFunctionParam12(key interface{}) (interface{}, error) { - return property(key, nil, c.text, c.pos) - -} - -func (p *parser) callonArrowFunctionParam12() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArrowFunctionParam12(stack["key"]) -} - -func (c *current) onArrowFunctionBody2(body interface{}) (interface{}, error) { - return body, nil - -} - -func (p *parser) callonArrowFunctionBody2() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArrowFunctionBody2(stack["body"]) -} - -func (c *current) onArrowFunctionBody5(body interface{}) (interface{}, error) { - return body, nil - -} - -func (p *parser) callonArrowFunctionBody5() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArrowFunctionBody5(stack["body"]) -} - -func (c *current) onObjectExpression1(object interface{}) (interface{}, error) { - return object, nil - -} - -func (p *parser) callonObjectExpression1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onObjectExpression1(stack["object"]) -} - -func (c *current) onObjectProperties1(first, rest interface{}) (interface{}, error) { - return objectexpr(first, rest, c.text, c.pos) - -} - -func (p *parser) callonObjectProperties1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onObjectProperties1(stack["first"], stack["rest"]) -} - -func (c *current) onPropertiesRest1(arg interface{}) (interface{}, error) { - return arg, nil - -} - -func (p *parser) callonPropertiesRest1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onPropertiesRest1(stack["arg"]) -} - -func (c *current) onProperty1(key, value interface{}) (interface{}, error) { - return property(key, value, c.text, c.pos) - -} - -func (p *parser) callonProperty1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onProperty1(stack["key"], stack["value"]) -} - -func (c *current) onLogicalOperators1() (interface{}, error) { - return logicalOp(c.text) - -} - -func (p *parser) callonLogicalOperators1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onLogicalOperators1() -} - -func (c *current) onLogicalExpression1(head, tail interface{}) (interface{}, error) { - return logicalExpression(head, tail, c.text, c.pos) - -} - -func (p *parser) callonLogicalExpression1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onLogicalExpression1(stack["head"], stack["tail"]) -} - -func (c *current) onEqualityOperators1() (interface{}, error) { - return operator(c.text) - -} - -func (p *parser) callonEqualityOperators1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onEqualityOperators1() -} - -func (c *current) onEquality1(head, tail interface{}) (interface{}, error) { - return binaryExpression(head, tail, c.text, c.pos) - -} - -func (p *parser) callonEquality1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onEquality1(stack["head"], stack["tail"]) -} - -func (c *current) onRelationalOperators1() (interface{}, error) { - return operator(c.text) - -} - -func (p *parser) callonRelationalOperators1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onRelationalOperators1() -} - -func (c *current) onRelational1(head, tail interface{}) (interface{}, error) { - return binaryExpression(head, tail, c.text, c.pos) - -} - -func (p *parser) callonRelational1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onRelational1(stack["head"], stack["tail"]) -} - -func (c *current) onAdditiveOperator1() (interface{}, error) { - return operator(c.text) - -} - -func (p *parser) callonAdditiveOperator1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onAdditiveOperator1() -} - -func (c *current) onAdditive1(head, tail interface{}) (interface{}, error) { - return binaryExpression(head, tail, c.text, c.pos) - -} - -func (p *parser) callonAdditive1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onAdditive1(stack["head"], stack["tail"]) -} - -func (c *current) onMultiplicativeOperator1() (interface{}, error) { - return operator(c.text) - -} - -func (p *parser) callonMultiplicativeOperator1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMultiplicativeOperator1() -} - -func (c *current) onMultiplicative1(head, tail interface{}) (interface{}, error) { - return binaryExpression(head, tail, c.text, c.pos) - -} - -func (p *parser) callonMultiplicative1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMultiplicative1(stack["head"], stack["tail"]) -} - -func (c *current) onUnaryOperator1() (interface{}, error) { - return operator(c.text) - -} - -func (p *parser) callonUnaryOperator1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onUnaryOperator1() -} - -func (c *current) onUnaryExpression2(op, argument interface{}) (interface{}, error) { - return unaryExpression(op, argument, c.text, c.pos) - -} - -func (p *parser) callonUnaryExpression2() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onUnaryExpression2(stack["op"], stack["argument"]) -} - -func (c *current) onParens1(expr interface{}) (interface{}, error) { - return expr, nil - -} - -func (p *parser) callonParens1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onParens1(stack["expr"]) -} - -func (c *current) onArray1(elements interface{}) (interface{}, error) { - if elements == nil { - elements = emptyArray(c.text, c.pos) - } - return elements, nil - -} - -func (p *parser) callonArray1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArray1(stack["elements"]) -} - -func (c *current) onArrayElements1(first, rest interface{}) (interface{}, error) { - return array(first, rest, c.text, c.pos), nil - -} - -func (p *parser) callonArrayElements1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArrayElements1(stack["first"], stack["rest"]) -} - -func (c *current) onArrayRest1(element interface{}) (interface{}, error) { - return element, nil - -} - -func (p *parser) callonArrayRest1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onArrayRest1(stack["element"]) -} - -func (c *current) onDateTimeLiteral1() (interface{}, error) { - return datetime(c.text, c.pos) - -} - -func (p *parser) callonDateTimeLiteral1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onDateTimeLiteral1() -} - -func (c *current) onDurationLiteral1(durations interface{}) (interface{}, error) { - return durationLiteral(durations, c.text, c.pos) - -} - -func (p *parser) callonDurationLiteral1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onDurationLiteral1(stack["durations"]) -} - -func (c *current) onYearDuration1(mag, unit, otherParts interface{}) (interface{}, error) { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - -} - -func (p *parser) callonYearDuration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onYearDuration1(stack["mag"], stack["unit"], stack["otherParts"]) -} - -func (c *current) onMonthDuration1(mag, unit, otherParts interface{}) (interface{}, error) { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - -} - -func (p *parser) callonMonthDuration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMonthDuration1(stack["mag"], stack["unit"], stack["otherParts"]) -} - -func (c *current) onWeekDuration1(mag, unit, otherParts interface{}) (interface{}, error) { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - -} - -func (p *parser) callonWeekDuration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onWeekDuration1(stack["mag"], stack["unit"], stack["otherParts"]) -} - -func (c *current) onDayDuration1(mag, unit, otherParts interface{}) (interface{}, error) { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - -} - -func (p *parser) callonDayDuration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onDayDuration1(stack["mag"], stack["unit"], stack["otherParts"]) -} - -func (c *current) onHourDuration1(mag, unit, otherParts interface{}) (interface{}, error) { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - -} - -func (p *parser) callonHourDuration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onHourDuration1(stack["mag"], stack["unit"], stack["otherParts"]) -} - -func (c *current) onMinuteDuration1(mag, unit, otherParts interface{}) (interface{}, error) { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - -} - -func (p *parser) callonMinuteDuration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMinuteDuration1(stack["mag"], stack["unit"], stack["otherParts"]) -} - -func (c *current) onSecondDuration1(mag, unit, otherParts interface{}) (interface{}, error) { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - -} - -func (p *parser) callonSecondDuration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onSecondDuration1(stack["mag"], stack["unit"], stack["otherParts"]) -} - -func (c *current) onMilliSecondDuration1(mag, unit, otherParts interface{}) (interface{}, error) { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - -} - -func (p *parser) callonMilliSecondDuration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMilliSecondDuration1(stack["mag"], stack["unit"], stack["otherParts"]) -} - -func (c *current) onMicroSecondDuration1(mag, unit, otherParts interface{}) (interface{}, error) { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - -} - -func (p *parser) callonMicroSecondDuration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMicroSecondDuration1(stack["mag"], stack["unit"], stack["otherParts"]) -} - -func (c *current) onNanoSecondDuration1(mag, unit interface{}) (interface{}, error) { - return appendSingleDurations(mag, unit, nil, c.text, c.pos) - -} - -func (p *parser) callonNanoSecondDuration1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onNanoSecondDuration1(stack["mag"], stack["unit"]) -} - -func (c *current) onMicroSecondUnits1() (interface{}, error) { - return []byte("us"), nil - -} - -func (p *parser) callonMicroSecondUnits1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onMicroSecondUnits1() -} - -func (c *current) onStringLiteral2() (interface{}, error) { - return stringLiteral(c.text, c.pos) - -} - -func (p *parser) callonStringLiteral2() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onStringLiteral2() -} - -func (c *current) onStringLiteral8() (interface{}, error) { - return "", errors.New("string literal not terminated") - -} - -func (p *parser) callonStringLiteral8() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onStringLiteral8() -} - -func (c *current) onDoubleStringEscape3() (interface{}, error) { - return nil, errors.New("invalid escape character") - -} - -func (p *parser) callonDoubleStringEscape3() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onDoubleStringEscape3() -} - -func (c *current) onRegexpLiteral1(pattern interface{}) (interface{}, error) { - return pattern, nil - -} - -func (p *parser) callonRegexpLiteral1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onRegexpLiteral1(stack["pattern"]) -} - -func (c *current) onRegexpBody1(chars interface{}) (interface{}, error) { - return regexLiteral(chars, c.text, c.pos) - -} - -func (p *parser) callonRegexpBody1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onRegexpBody1(stack["chars"]) -} - -func (c *current) onRegexpChar2(re interface{}) (interface{}, error) { - return re, nil - -} - -func (p *parser) callonRegexpChar2() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onRegexpChar2(stack["re"]) -} - -func (c *current) onRegexpBackslashSequence2() (interface{}, error) { - return []byte{'/'}, nil - -} - -func (p *parser) callonRegexpBackslashSequence2() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onRegexpBackslashSequence2() -} - -func (c *current) onRegexpBackslashSequence4() (interface{}, error) { - return c.text, nil - -} - -func (p *parser) callonRegexpBackslashSequence4() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onRegexpBackslashSequence4() -} - -func (c *current) onRegexpNonTerminator1() (interface{}, error) { - return c.text, nil - -} - -func (p *parser) callonRegexpNonTerminator1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onRegexpNonTerminator1() -} - -func (c *current) onBooleanLiteral2() (interface{}, error) { - return booleanLiteral(true, c.text, c.pos) - -} - -func (p *parser) callonBooleanLiteral2() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onBooleanLiteral2() -} - -func (c *current) onBooleanLiteral7() (interface{}, error) { - return booleanLiteral(false, c.text, c.pos) - -} - -func (p *parser) callonBooleanLiteral7() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onBooleanLiteral7() -} - -func (c *current) onNumberLiteral1() (interface{}, error) { - return numberLiteral(c.text, c.pos) - -} - -func (p *parser) callonNumberLiteral1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onNumberLiteral1() -} - -func (c *current) onIntegerLiteral1() (interface{}, error) { - return integerLiteral(c.text, c.pos) - -} - -func (p *parser) callonIntegerLiteral1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onIntegerLiteral1() -} - -func (c *current) onPipeLiteral1() (interface{}, error) { - return pipeLiteral(c.text, c.pos), nil - -} - -func (p *parser) callonPipeLiteral1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onPipeLiteral1() -} - -func (c *current) onIdentifier1() (interface{}, error) { - return identifier(c.text, c.pos) - -} - -func (p *parser) callonIdentifier1() (interface{}, error) { - stack := p.vstack[len(p.vstack)-1] - _ = stack - return p.cur.onIdentifier1() -} - -var ( - // errNoRule is returned when the grammar to parse has no rule. - errNoRule = errors.New("grammar has no rule") - - // errInvalidEntrypoint is returned when the specified entrypoint rule - // does not exit. - errInvalidEntrypoint = errors.New("invalid entrypoint") - - // errInvalidEncoding is returned when the source is not properly - // utf8-encoded. - errInvalidEncoding = errors.New("invalid encoding") - - // errMaxExprCnt is used to signal that the maximum number of - // expressions have been parsed. - errMaxExprCnt = errors.New("max number of expresssions parsed") -) - -// Option is a function that can set an option on the parser. It returns -// the previous setting as an Option. -type Option func(*parser) Option - -// MaxExpressions creates an Option to stop parsing after the provided -// number of expressions have been parsed, if the value is 0 then the parser will -// parse for as many steps as needed (possibly an infinite number). -// -// The default for maxExprCnt is 0. -func MaxExpressions(maxExprCnt uint64) Option { - return func(p *parser) Option { - oldMaxExprCnt := p.maxExprCnt - p.maxExprCnt = maxExprCnt - return MaxExpressions(oldMaxExprCnt) - } -} - -// Entrypoint creates an Option to set the rule name to use as entrypoint. -// The rule name must have been specified in the -alternate-entrypoints -// if generating the parser with the -optimize-grammar flag, otherwise -// it may have been optimized out. Passing an empty string sets the -// entrypoint to the first rule in the grammar. -// -// The default is to start parsing at the first rule in the grammar. -func Entrypoint(ruleName string) Option { - return func(p *parser) Option { - oldEntrypoint := p.entrypoint - p.entrypoint = ruleName - if ruleName == "" { - p.entrypoint = g.rules[0].name - } - return Entrypoint(oldEntrypoint) - } -} - -// AllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes. -// Every invalid UTF-8 byte is treated as a utf8.RuneError (U+FFFD) -// by character class matchers and is matched by the any matcher. -// The returned matched value, c.text and c.offset are NOT affected. -// -// The default is false. -func AllowInvalidUTF8(b bool) Option { - return func(p *parser) Option { - old := p.allowInvalidUTF8 - p.allowInvalidUTF8 = b - return AllowInvalidUTF8(old) - } -} - -// Recover creates an Option to set the recover flag to b. When set to -// true, this causes the parser to recover from panics and convert it -// to an error. Setting it to false can be useful while debugging to -// access the full stack trace. -// -// The default is true. -func Recover(b bool) Option { - return func(p *parser) Option { - old := p.recover - p.recover = b - return Recover(old) - } -} - -// GlobalStore creates an Option to set a key to a certain value in -// the globalStore. -func GlobalStore(key string, value interface{}) Option { - return func(p *parser) Option { - old := p.cur.globalStore[key] - p.cur.globalStore[key] = value - return GlobalStore(key, old) - } -} - -// ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { - f, err := os.Open(filename) - if err != nil { - return nil, err - } - defer func() { - if closeErr := f.Close(); closeErr != nil { - err = closeErr - } - }() - return ParseReader(filename, f, opts...) -} - -// ParseReader parses the data from r using filename as information in the -// error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { - b, err := ioutil.ReadAll(r) - if err != nil { - return nil, err - } - - return Parse(filename, b, opts...) -} - -// Parse parses the data from b using filename as information in the -// error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { - return newParser(filename, b, opts...).parse(g) -} - -// position records a position in the text. -type position struct { - line, col, offset int -} - -func (p position) String() string { - return fmt.Sprintf("%d:%d [%d]", p.line, p.col, p.offset) -} - -// savepoint stores all state required to go back to this point in the -// parser. -type savepoint struct { - position - rn rune - w int -} - -type current struct { - pos position // start position of the match - text []byte // raw text of the match - - // globalStore is a general store for the user to store arbitrary key-value - // pairs that they need to manage and that they do not want tied to the - // backtracking of the parser. This is only modified by the user and never - // rolled back by the parser. It is always up to the user to keep this in a - // consistent state. - globalStore storeDict -} - -type storeDict map[string]interface{} - -// the AST types... - -type grammar struct { - pos position - rules []*rule -} - -type rule struct { - pos position - name string - displayName string - expr interface{} -} - -type choiceExpr struct { - pos position - alternatives []interface{} -} - -type actionExpr struct { - pos position - expr interface{} - run func(*parser) (interface{}, error) -} - -type recoveryExpr struct { - pos position - expr interface{} - recoverExpr interface{} - failureLabel []string -} - -type seqExpr struct { - pos position - exprs []interface{} -} - -type throwExpr struct { - pos position - label string -} - -type labeledExpr struct { - pos position - label string - expr interface{} -} - -type expr struct { - pos position - expr interface{} -} - -type andExpr expr -type notExpr expr -type zeroOrOneExpr expr -type zeroOrMoreExpr expr -type oneOrMoreExpr expr - -type ruleRefExpr struct { - pos position - name string -} - -type andCodeExpr struct { - pos position - run func(*parser) (bool, error) -} - -type notCodeExpr struct { - pos position - run func(*parser) (bool, error) -} - -type litMatcher struct { - pos position - val string - ignoreCase bool -} - -type charClassMatcher struct { - pos position - val string - basicLatinChars [128]bool - chars []rune - ranges []rune - classes []*unicode.RangeTable - ignoreCase bool - inverted bool -} - -type anyMatcher position - -// errList cumulates the errors found by the parser. -type errList []error - -func (e *errList) add(err error) { - *e = append(*e, err) -} - -func (e errList) err() error { - if len(e) == 0 { - return nil - } - e.dedupe() - return e -} - -func (e *errList) dedupe() { - var cleaned []error - set := make(map[string]bool) - for _, err := range *e { - if msg := err.Error(); !set[msg] { - set[msg] = true - cleaned = append(cleaned, err) - } - } - *e = cleaned -} - -func (e errList) Error() string { - switch len(e) { - case 0: - return "" - case 1: - return e[0].Error() - default: - var buf bytes.Buffer - - for i, err := range e { - if i > 0 { - buf.WriteRune('\n') - } - buf.WriteString(err.Error()) - } - return buf.String() - } -} - -// parserError wraps an error with a prefix indicating the rule in which -// the error occurred. The original error is stored in the Inner field. -type parserError struct { - Inner error - pos position - prefix string - expected []string -} - -// Error returns the error message. -func (p *parserError) Error() string { - return p.prefix + ": " + p.Inner.Error() -} - -// newParser creates a parser with the specified input source and options. -func newParser(filename string, b []byte, opts ...Option) *parser { - stats := Stats{ - ChoiceAltCnt: make(map[string]map[string]int), - } - - p := &parser{ - filename: filename, - errs: new(errList), - data: b, - pt: savepoint{position: position{line: 1}}, - recover: true, - cur: current{ - globalStore: make(storeDict), - }, - maxFailPos: position{col: 1, line: 1}, - maxFailExpected: make([]string, 0, 20), - Stats: &stats, - // start rule is rule [0] unless an alternate entrypoint is specified - entrypoint: g.rules[0].name, - } - p.setOptions(opts) - - if p.maxExprCnt == 0 { - p.maxExprCnt = math.MaxUint64 - } - - return p -} - -// setOptions applies the options to the parser. -func (p *parser) setOptions(opts []Option) { - for _, opt := range opts { - opt(p) - } -} - -type resultTuple struct { - v interface{} - b bool - end savepoint -} - -const choiceNoMatch = -1 - -// Stats stores some statistics, gathered during parsing -type Stats struct { - // ExprCnt counts the number of expressions processed during parsing - // This value is compared to the maximum number of expressions allowed - // (set by the MaxExpressions option). - ExprCnt uint64 - - // ChoiceAltCnt is used to count for each ordered choice expression, - // which alternative is used how may times. - // These numbers allow to optimize the order of the ordered choice expression - // to increase the performance of the parser - // - // The outer key of ChoiceAltCnt is composed of the name of the rule as well - // as the line and the column of the ordered choice. - // The inner key of ChoiceAltCnt is the number (one-based) of the matching alternative. - // For each alternative the number of matches are counted. If an ordered choice does not - // match, a special counter is incremented. The name of this counter is set with - // the parser option Statistics. - // For an alternative to be included in ChoiceAltCnt, it has to match at least once. - ChoiceAltCnt map[string]map[string]int -} - -type parser struct { - filename string - pt savepoint - cur current - - data []byte - errs *errList - - depth int - recover bool - - // rules table, maps the rule identifier to the rule node - rules map[string]*rule - // variables stack, map of label to value - vstack []map[string]interface{} - // rule stack, allows identification of the current rule in errors - rstack []*rule - - // parse fail - maxFailPos position - maxFailExpected []string - maxFailInvertExpected bool - - // max number of expressions to be parsed - maxExprCnt uint64 - // entrypoint for the parser - entrypoint string - - allowInvalidUTF8 bool - - *Stats - - choiceNoMatch string - // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} -} - -// push a variable set on the vstack. -func (p *parser) pushV() { - if cap(p.vstack) == len(p.vstack) { - // create new empty slot in the stack - p.vstack = append(p.vstack, nil) - } else { - // slice to 1 more - p.vstack = p.vstack[:len(p.vstack)+1] - } - - // get the last args set - m := p.vstack[len(p.vstack)-1] - if m != nil && len(m) == 0 { - // empty map, all good - return - } - - m = make(map[string]interface{}) - p.vstack[len(p.vstack)-1] = m -} - -// pop a variable set from the vstack. -func (p *parser) popV() { - // if the map is not empty, clear it - m := p.vstack[len(p.vstack)-1] - if len(m) > 0 { - // GC that map - p.vstack[len(p.vstack)-1] = nil - } - p.vstack = p.vstack[:len(p.vstack)-1] -} - -// push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { - if cap(p.recoveryStack) == len(p.recoveryStack) { - // create new empty slot in the stack - p.recoveryStack = append(p.recoveryStack, nil) - } else { - // slice to 1 more - p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] - } - - m := make(map[string]interface{}, len(labels)) - for _, fl := range labels { - m[fl] = expr - } - p.recoveryStack[len(p.recoveryStack)-1] = m -} - -// pop a recovery expression from the recoveryStack -func (p *parser) popRecovery() { - // GC that map - p.recoveryStack[len(p.recoveryStack)-1] = nil - - p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)-1] -} - -func (p *parser) addErr(err error) { - p.addErrAt(err, p.pt.position, []string{}) -} - -func (p *parser) addErrAt(err error, pos position, expected []string) { - var buf bytes.Buffer - if p.filename != "" { - buf.WriteString(p.filename) - } - if buf.Len() > 0 { - buf.WriteString(":") - } - buf.WriteString(fmt.Sprintf("%d:%d (%d)", pos.line, pos.col, pos.offset)) - if len(p.rstack) > 0 { - if buf.Len() > 0 { - buf.WriteString(": ") - } - rule := p.rstack[len(p.rstack)-1] - if rule.displayName != "" { - buf.WriteString("rule " + rule.displayName) - } else { - buf.WriteString("rule " + rule.name) - } - } - pe := &parserError{Inner: err, pos: pos, prefix: buf.String(), expected: expected} - p.errs.add(pe) -} - -func (p *parser) failAt(fail bool, pos position, want string) { - // process fail if parsing fails and not inverted or parsing succeeds and invert is set - if fail == p.maxFailInvertExpected { - if pos.offset < p.maxFailPos.offset { - return - } - - if pos.offset > p.maxFailPos.offset { - p.maxFailPos = pos - p.maxFailExpected = p.maxFailExpected[:0] - } - - if p.maxFailInvertExpected { - want = "!" + want - } - p.maxFailExpected = append(p.maxFailExpected, want) - } -} - -// read advances the parser to the next rune. -func (p *parser) read() { - p.pt.offset += p.pt.w - rn, n := utf8.DecodeRune(p.data[p.pt.offset:]) - p.pt.rn = rn - p.pt.w = n - p.pt.col++ - if rn == '\n' { - p.pt.line++ - p.pt.col = 0 - } - - if rn == utf8.RuneError && n == 1 { // see utf8.DecodeRune - if !p.allowInvalidUTF8 { - p.addErr(errInvalidEncoding) - } - } -} - -// restore parser position to the savepoint pt. -func (p *parser) restore(pt savepoint) { - if pt.offset == p.pt.offset { - return - } - p.pt = pt -} - -// get the slice of bytes from the savepoint start to the current position. -func (p *parser) sliceFrom(start savepoint) []byte { - return p.data[start.position.offset:p.pt.position.offset] -} - -func (p *parser) buildRulesTable(g *grammar) { - p.rules = make(map[string]*rule, len(g.rules)) - for _, r := range g.rules { - p.rules[r.name] = r - } -} - -func (p *parser) parse(g *grammar) (val interface{}, err error) { - if len(g.rules) == 0 { - p.addErr(errNoRule) - return nil, p.errs.err() - } - - // TODO : not super critical but this could be generated - p.buildRulesTable(g) - - if p.recover { - // panic can be used in action code to stop parsing immediately - // and return the panic as an error. - defer func() { - if e := recover(); e != nil { - val = nil - switch e := e.(type) { - case error: - p.addErr(e) - default: - p.addErr(fmt.Errorf("%v", e)) - } - err = p.errs.err() - } - }() - } - - startRule, ok := p.rules[p.entrypoint] - if !ok { - p.addErr(errInvalidEntrypoint) - return nil, p.errs.err() - } - - p.read() // advance to first rune - val, ok = p.parseRule(startRule) - if !ok { - if len(*p.errs) == 0 { - // If parsing fails, but no errors have been recorded, the expected values - // for the farthest parser position are returned as error. - maxFailExpectedMap := make(map[string]struct{}, len(p.maxFailExpected)) - for _, v := range p.maxFailExpected { - maxFailExpectedMap[v] = struct{}{} - } - expected := make([]string, 0, len(maxFailExpectedMap)) - eof := false - if _, ok := maxFailExpectedMap["!."]; ok { - delete(maxFailExpectedMap, "!.") - eof = true - } - for k := range maxFailExpectedMap { - expected = append(expected, k) - } - sort.Strings(expected) - if eof { - expected = append(expected, "EOF") - } - p.addErrAt(errors.New("no match found, expected: "+listJoin(expected, ", ", "or")), p.maxFailPos, expected) - } - - return nil, p.errs.err() - } - return val, p.errs.err() -} - -func listJoin(list []string, sep string, lastSep string) string { - switch len(list) { - case 0: - return "" - case 1: - return list[0] - default: - return fmt.Sprintf("%s %s %s", strings.Join(list[:len(list)-1], sep), lastSep, list[len(list)-1]) - } -} - -func (p *parser) parseRule(rule *rule) (interface{}, bool) { - p.rstack = append(p.rstack, rule) - p.pushV() - val, ok := p.parseExpr(rule.expr) - p.popV() - p.rstack = p.rstack[:len(p.rstack)-1] - return val, ok -} - -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { - - p.ExprCnt++ - if p.ExprCnt > p.maxExprCnt { - panic(errMaxExprCnt) - } - - var val interface{} - var ok bool - switch expr := expr.(type) { - case *actionExpr: - val, ok = p.parseActionExpr(expr) - case *andCodeExpr: - val, ok = p.parseAndCodeExpr(expr) - case *andExpr: - val, ok = p.parseAndExpr(expr) - case *anyMatcher: - val, ok = p.parseAnyMatcher(expr) - case *charClassMatcher: - val, ok = p.parseCharClassMatcher(expr) - case *choiceExpr: - val, ok = p.parseChoiceExpr(expr) - case *labeledExpr: - val, ok = p.parseLabeledExpr(expr) - case *litMatcher: - val, ok = p.parseLitMatcher(expr) - case *notCodeExpr: - val, ok = p.parseNotCodeExpr(expr) - case *notExpr: - val, ok = p.parseNotExpr(expr) - case *oneOrMoreExpr: - val, ok = p.parseOneOrMoreExpr(expr) - case *recoveryExpr: - val, ok = p.parseRecoveryExpr(expr) - case *ruleRefExpr: - val, ok = p.parseRuleRefExpr(expr) - case *seqExpr: - val, ok = p.parseSeqExpr(expr) - case *throwExpr: - val, ok = p.parseThrowExpr(expr) - case *zeroOrMoreExpr: - val, ok = p.parseZeroOrMoreExpr(expr) - case *zeroOrOneExpr: - val, ok = p.parseZeroOrOneExpr(expr) - default: - panic(fmt.Sprintf("unknown expression type %T", expr)) - } - return val, ok -} - -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { - start := p.pt - val, ok := p.parseExpr(act.expr) - if ok { - p.cur.pos = start.position - p.cur.text = p.sliceFrom(start) - actVal, err := act.run(p) - if err != nil { - p.addErrAt(err, start.position, []string{}) - } - - val = actVal - } - return val, ok -} - -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { - - ok, err := and.run(p) - if err != nil { - p.addErr(err) - } - - return nil, ok -} - -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { - pt := p.pt - p.pushV() - _, ok := p.parseExpr(and.expr) - p.popV() - p.restore(pt) - - return nil, ok -} - -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { - if p.pt.rn == utf8.RuneError && p.pt.w == 0 { - // EOF - see utf8.DecodeRune - p.failAt(false, p.pt.position, ".") - return nil, false - } - start := p.pt - p.read() - p.failAt(true, start.position, ".") - return p.sliceFrom(start), true -} - -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { - cur := p.pt.rn - start := p.pt - - // can't match EOF - if cur == utf8.RuneError && p.pt.w == 0 { // see utf8.DecodeRune - p.failAt(false, start.position, chr.val) - return nil, false - } - - if chr.ignoreCase { - cur = unicode.ToLower(cur) - } - - // try to match in the list of available chars - for _, rn := range chr.chars { - if rn == cur { - if chr.inverted { - p.failAt(false, start.position, chr.val) - return nil, false - } - p.read() - p.failAt(true, start.position, chr.val) - return p.sliceFrom(start), true - } - } - - // try to match in the list of ranges - for i := 0; i < len(chr.ranges); i += 2 { - if cur >= chr.ranges[i] && cur <= chr.ranges[i+1] { - if chr.inverted { - p.failAt(false, start.position, chr.val) - return nil, false - } - p.read() - p.failAt(true, start.position, chr.val) - return p.sliceFrom(start), true - } - } - - // try to match in the list of Unicode classes - for _, cl := range chr.classes { - if unicode.Is(cl, cur) { - if chr.inverted { - p.failAt(false, start.position, chr.val) - return nil, false - } - p.read() - p.failAt(true, start.position, chr.val) - return p.sliceFrom(start), true - } - } - - if chr.inverted { - p.read() - p.failAt(true, start.position, chr.val) - return p.sliceFrom(start), true - } - p.failAt(false, start.position, chr.val) - return nil, false -} - -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { - for altI, alt := range ch.alternatives { - // dummy assignment to prevent compile error if optimized - _ = altI - - p.pushV() - val, ok := p.parseExpr(alt) - p.popV() - if ok { - return val, ok - } - } - return nil, false -} - -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { - p.pushV() - val, ok := p.parseExpr(lab.expr) - p.popV() - if ok && lab.label != "" { - m := p.vstack[len(p.vstack)-1] - m[lab.label] = val - } - return val, ok -} - -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { - ignoreCase := "" - if lit.ignoreCase { - ignoreCase = "i" - } - val := fmt.Sprintf("%q%s", lit.val, ignoreCase) - start := p.pt - for _, want := range lit.val { - cur := p.pt.rn - if lit.ignoreCase { - cur = unicode.ToLower(cur) - } - if cur != want { - p.failAt(false, start.position, val) - p.restore(start) - return nil, false - } - p.read() - } - p.failAt(true, start.position, val) - return p.sliceFrom(start), true -} - -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { - ok, err := not.run(p) - if err != nil { - p.addErr(err) - } - - return nil, !ok -} - -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { - pt := p.pt - p.pushV() - p.maxFailInvertExpected = !p.maxFailInvertExpected - _, ok := p.parseExpr(not.expr) - p.maxFailInvertExpected = !p.maxFailInvertExpected - p.popV() - p.restore(pt) - - return nil, !ok -} - -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { - var vals []interface{} - - for { - p.pushV() - val, ok := p.parseExpr(expr.expr) - p.popV() - if !ok { - if len(vals) == 0 { - // did not match once, no match - return nil, false - } - return vals, true - } - vals = append(vals, val) - } -} - -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { - - p.pushRecovery(recover.failureLabel, recover.recoverExpr) - val, ok := p.parseExpr(recover.expr) - p.popRecovery() - - return val, ok -} - -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { - if ref.name == "" { - panic(fmt.Sprintf("%s: invalid rule: missing name", ref.pos)) - } - - rule := p.rules[ref.name] - if rule == nil { - p.addErr(fmt.Errorf("undefined rule: %s", ref.name)) - return nil, false - } - return p.parseRule(rule) -} - -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { - vals := make([]interface{}, 0, len(seq.exprs)) - - pt := p.pt - for _, expr := range seq.exprs { - val, ok := p.parseExpr(expr) - if !ok { - p.restore(pt) - return nil, false - } - vals = append(vals, val) - } - return vals, true -} - -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { - - for i := len(p.recoveryStack) - 1; i >= 0; i-- { - if recoverExpr, ok := p.recoveryStack[i][expr.label]; ok { - if val, ok := p.parseExpr(recoverExpr); ok { - return val, ok - } - } - } - - return nil, false -} - -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { - var vals []interface{} - - for { - p.pushV() - val, ok := p.parseExpr(expr.expr) - p.popV() - if !ok { - return vals, true - } - vals = append(vals, val) - } -} - -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { - p.pushV() - val, _ := p.parseExpr(expr.expr) - p.popV() - // whether it matched or not, consider it a match - return val, true -} - -func rangeTable(class string) *unicode.RangeTable { - if rt, ok := unicode.Categories[class]; ok { - return rt - } - if rt, ok := unicode.Properties[class]; ok { - return rt - } - if rt, ok := unicode.Scripts[class]; ok { - return rt - } - - // cannot happen - panic(fmt.Sprintf("invalid Unicode class: %s", class)) -} diff --git a/parser/flux.peg b/parser/flux.peg deleted file mode 100644 index bfca3b726a..0000000000 --- a/parser/flux.peg +++ /dev/null @@ -1,614 +0,0 @@ -{ -package parser - -// DO NOT EDIT: This file is auto generated by the pigeon PEG parser generator. - -} - -Start - = __ program:Program __ EOF { - return program, nil - } - -Program - = body:SourceElements { - return program(body, c.text, c.pos) - } - -SourceElements - = head:SourceElement tail:(__ SourceElement __)* { - return srcElems(head, tail) - } - -SourceElement - = Statement - -Statement - = VariableStatement - / OptionStatement - / ReturnStatement - / ExpressionStatement - / BlockStatement - - -OptionStatement - = "option" __ id:Identifier __ "=" __ expr:Expr { - return optionstmt(id, expr, c.text, c.pos) - } - -VariableStatement - = declaration:VariableDeclaration { - return varstmt(declaration, c.text, c.pos) - } - -ReturnStatement - = "return" __ argument:Expr { - return returnstmt(argument, c.text, c.pos) - } - -ExpressionStatement - = expr:Expr { - return exprstmt(expr, c.text, c.pos) - } - -BlockStatement - = "{" __ body:( __ Statement __ )* __ "}" { - return blockstmt(body, c.text, c.pos) - } - -VariableDeclaration - = id:Identifier __ "=" __ init:Expr { - return vardecl(id, init, c.text, c.pos) - } - - -MemberExpressions - = head:Identifier // TODO: should be primary - tail:( - __ property:MemberExpressionProperty { - return property, nil - } - )* - { - return memberexprs(head, tail, c.text, c.pos) - } - -MemberExpressionProperty - = "." property:Identifier { - return memberExprFromIdentifier(property) - } - / "[" __ property:StringLiteral __ "]" { - return memberExprFromStringLiteral(property) - } - / "[" __ property:Primary __ "]" { - return indexExpr(property) - } - -CallExpression - = head:( - callee:MemberExpressions __ args:Arguments { - return callexpr(callee, args, c.text, c.pos) - } - ) - tail:( - __ args:Arguments { - return callexpr(nil, args, c.text, c.pos) - } - / __ property:MemberExpressionProperty { - return property, nil - } - )* - { - return callexprs(head, tail, c.text, c.pos) - } - -PipeExpression - = head:PipeExpressionHead __ tail:(__ PipeExpressionPipe __)+ { - return pipeExprs(head, tail, c.text, c.pos) - } - -PipeExpressionHead - = CallExpression // TODO(nathanielc): Allow for more expressions as pipe heads. Cannot use Expr because it causes infinite left recursion. - / Literal - / Array - / MemberExpressions - / Identifier - / ObjectExpression - / ArrowFunctionExpression - / Parens - -PipeExpressionPipe - = "|>" __ call:CallExpression { - return incompletePipeExpr(call, c.text, c.pos) - } - -Arguments - = "(" __ args:(ObjectProperties)? __ ")" { - return args, nil - } - -ArrowFunctionExpression - = "(" __ params:ArrowFunctionParams? __ ")" __ "=>" __ body:ArrowFunctionBody __ { - return arrowfunc(params, body, c.text, c.pos), nil - } - -ArrowFunctionParams - = first:ArrowFunctionParam __ rest:ArrowFunctionParamsRest* ","? { - return append([]interface{}{first}, toIfaceSlice(rest)...), nil - } - -ArrowFunctionParamsRest - = "," __ arg:ArrowFunctionParam __ { - return arg, nil - } - -ArrowFunctionParam - = key:Identifier __ "=" __ value:Primary __ { - return property(key, value, c.text, c.pos) - } - / key:Identifier __ { - return property(key, nil, c.text, c.pos) - } - - -ArrowFunctionBody - = body:Expr { - return body, nil - } - / body:BlockStatement { - return body, nil - } - -ObjectExpression - = "{" __ object:(ObjectProperties)? __ "}" { - return object, nil - } - -ObjectProperties - = first:Property __ rest:PropertiesRest* __ ","? { - return objectexpr(first, rest, c.text, c.pos) - } - -PropertiesRest - = "," __ arg:Property { - return arg, nil - } - -Property - = key:Identifier __ ":" __ value:Expr { - return property(key, value, c.text, c.pos) - } - -// + - -// <= < >= > startsWith IN NOT EMPTY EMPTY -// == != -// and or -// Lowest to Highest Priority. -// Highest Priority includes the valid primary -// primary contains the Lowest Priority -Expr - = LogicalExpression - -LogicalOperators - = ("or"i / "and"i) { - return logicalOp(c.text) - } - -LogicalExpression - = head:Equality tail:( __ LogicalOperators __ Equality )* { - return logicalExpression(head, tail, c.text, c.pos) - } - -EqualityOperators - = ("==" / "!=" / "=~" / "!~") { - return operator(c.text) - } - -Equality - = head:Relational tail:( __ EqualityOperators __ Relational )* { - return binaryExpression(head, tail, c.text, c.pos) - } - -RelationalOperators - = ( "<=" - / "<" - / ">=" - / ">" - / "startswith"i - / "in"i - / "not empty"i - / "empty"i - ) { - return operator(c.text) - } - -Relational - = head:Additive tail:( __ RelationalOperators __ Additive )* { - return binaryExpression(head, tail, c.text, c.pos) - } - -AdditiveOperator - = ("+" / "-") { - return operator(c.text) - } - -Additive - = head:Multiplicative tail:( __ AdditiveOperator __ Multiplicative )* { - return binaryExpression(head, tail, c.text, c.pos) - } - -MultiplicativeOperator - = ("*" / "/") { - return operator(c.text) - } - -Multiplicative - = head:UnaryExpression tail:( __ MultiplicativeOperator __ UnaryExpression )* { - return binaryExpression(head, tail, c.text, c.pos) - } - -UnaryOperator - = ("-" / "not") { - return operator(c.text) - } - -UnaryExpression - = __ op:UnaryOperator __ argument:Primary __ { - return unaryExpression(op, argument, c.text, c.pos) - } - / Primary - -Primary - = PipeExpression - / Array - / Literal - / CallExpression - / MemberExpressions - / Identifier - / ObjectExpression - / ArrowFunctionExpression - / Parens - -Literal - = StringLiteral - / BooleanLiteral - / RegexpLiteral - / PipeLiteral - / DurationLiteral - / DateTimeLiteral - / NumberLiteral - / IntegerLiteral - -Parens - = "(" __ expr:Expr __ ")" { - return expr, nil - } - -Array - = "[" __ elements:ArrayElements? __ "]" { - if elements == nil { - elements = emptyArray(c.text, c.pos) - } - return elements, nil - } - -ArrayElements - = first:Primary __ rest:ArrayRest* { - return array(first, rest, c.text, c.pos), nil - } - -ArrayRest - = "," __ element:Primary { - return element, nil - } - -DateFullYear - = Digit Digit Digit Digit - -DateMonth - // 01-12 - = Digit Digit - -DateMDay - // 01-28, 01-29, 01-30, 01-31 based on - // month/year - = Digit Digit - -TimeHour - // 00-23 - = Digit Digit - -TimeMinute - // 00-59 - = Digit Digit - -TimeSecond - // 00-58, 00-59, 00-60 based on leap second - // rules - = Digit Digit - -TimeSecFrac - = "." Digit+ - -TimeNumOffset - = ("+" / "-") TimeHour ":" TimeMinute - -TimeOffset - = ("Z" / TimeNumOffset) - -PartialTime - = TimeHour ":" TimeMinute ":" TimeSecond TimeSecFrac? - -FullDate - = DateFullYear "-" DateMonth "-" DateMDay - -FullTime - = PartialTime TimeOffset - -DateTimeLiteral - = FullDate "T" FullTime { - return datetime(c.text, c.pos) - } - -// The order of the choices in this rule and those below matters. -// Minutes (m) must appear before milliseconds (ms) and months (mo), -// otherwise "10ms" will be parsed as 10 minutes and an extraneous "s". -DurationLiteral - = durations:( - DayDuration - / HourDuration - / MicroSecondDuration - / MilliSecondDuration - / MonthDuration - / MinuteDuration - / NanoSecondDuration - / SecondDuration - / WeekDuration - / YearDuration - ) { - return durationLiteral(durations, c.text, c.pos) - } - -YearDuration - = mag:IntegerLiteral unit:YearUnits otherParts:( - DayDuration - / HourDuration - / MicroSecondDuration - / MilliSecondDuration - / MonthDuration - / MinuteDuration - / NanoSecondDuration - / SecondDuration - / WeekDuration - )? { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - } - -MonthDuration - = mag:IntegerLiteral unit:MonthUnits otherParts:( - DayDuration - / HourDuration - / MicroSecondDuration - / MilliSecondDuration - / MinuteDuration - / NanoSecondDuration - / SecondDuration - / WeekDuration - )? { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - } - -WeekDuration - = mag:IntegerLiteral unit:WeekUnits otherParts:( - DayDuration - / HourDuration - / MicroSecondDuration - / MilliSecondDuration - / MinuteDuration - / NanoSecondDuration - / SecondDuration - )? { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - } - -DayDuration - = mag:IntegerLiteral unit:DayUnits otherParts:( - HourDuration - / MicroSecondDuration - / MilliSecondDuration - / MinuteDuration - / NanoSecondDuration - / SecondDuration - )? { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - } - -HourDuration - = mag:IntegerLiteral unit:HourUnits otherParts:( - MicroSecondDuration - / MilliSecondDuration - / MinuteDuration - / NanoSecondDuration - / SecondDuration - )? { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - } - -MinuteDuration - = mag:IntegerLiteral unit:MinuteUnits otherParts:( - MicroSecondDuration - / MilliSecondDuration - / NanoSecondDuration - / SecondDuration - )? { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - } - -SecondDuration - = mag:IntegerLiteral unit:SecondUnits otherParts:( - MicroSecondDuration - / MilliSecondDuration - / NanoSecondDuration - )? { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - } - -MilliSecondDuration - = mag:IntegerLiteral unit:MilliSecondUnits otherParts:( - MicroSecondDuration - / NanoSecondDuration - )? { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - } - -MicroSecondDuration - = mag:IntegerLiteral unit:MicroSecondUnits otherParts:( - NanoSecondDuration - )? { - return appendSingleDurations(mag, unit, otherParts, c.text, c.pos) - } - -NanoSecondDuration - = mag:IntegerLiteral unit:NanoSecondUnits { - return appendSingleDurations(mag, unit, nil, c.text, c.pos) - } - -NanoSecondUnits - = "ns" - -MicroSecondUnits - = ("us" / "µs" / "μs") { - return []byte("us"), nil - } - -MilliSecondUnits - = "ms" - -SecondUnits - = "s" - -MinuteUnits - = "m" - -HourUnits - = "h" - -DayUnits - = "d" - -WeekUnits - = "w" - -MonthUnits - = "mo" - -YearUnits - = "y" - -StringLiteral - = ( '"' DoubleStringChar* '"' ) { - return stringLiteral(c.text, c.pos) - } - / ( '"' DoubleStringChar* ( EOL / EOF ) ) { - return "", errors.New("string literal not terminated") - } - -DoubleStringChar - = !( '"' / "\\" / EOL ) SourceChar - / "\\" DoubleStringEscape - -DoubleStringEscape - = '"' - / ( SourceChar / EOL / EOF ) { - return nil, errors.New("invalid escape character") - } - - -RegexpLiteral - = "/" pattern:RegexpBody "/" { - return pattern, nil - } - -RegexpBody - = chars:RegexpChar+ { - return regexLiteral(chars, c.text, c.pos) - } - -RegexpChar - = ![\\/] re:RegexpNonTerminator { - return re, nil - } - / RegexpBackslashSequence - -RegexpBackslashSequence - = "\\/" { - return []byte{'/'}, nil - } - / "\\" RegexpNonTerminator { - return c.text, nil - } - -RegexpNonTerminator - = !LineTerminator SourceChar { - return c.text, nil - } - -BooleanLiteral - = __ "true" __ { - return booleanLiteral(true, c.text, c.pos) - } - / __ "false" __ { - return booleanLiteral(false, c.text, c.pos) - } - -NumberLiteral - = Integer "." Digit+ { - return numberLiteral(c.text, c.pos) - } - -Integer - = ("0" / NonZeroDigit Digit*) - -IntegerLiteral - = Integer { - return integerLiteral(c.text, c.pos) - } - -NonZeroDigit - = [1-9] - -Digit - = [0-9] - -PipeLiteral - = "<-" { - return pipeLiteral(c.text, c.pos), nil - } - - -Identifier - // Allow any unicode letter possibly followed by any number of unicode letters, underscores and numbers. - = [_\pL][_0-9\pL]* { - return identifier(c.text, c.pos) - } - - -SourceChar - = . -__ - = ( ws / EOL / Comment )* - -Comment - = "//" [^\r\n]* EOL - -ws - = [ \t\r\n] - -LineTerminator - = [\n\r] - -EOL - = "\n" - -EOF - = !. diff --git a/parser/parser.go b/parser/parser.go index 13115844b9..594a08f502 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -1,18 +1,16 @@ -// +build !parser_debug - package parser -//go:generate pigeon -optimize-parser -o flux.go flux.peg - import ( "github.com/influxdata/flux/ast" + fastparser "github.com/influxdata/flux/internal/parser" + "github.com/influxdata/flux/internal/scanner" + "github.com/influxdata/flux/internal/token" ) // NewAST parses Flux query and produces an ast.Program -func NewAST(flux string, opts ...Option) (*ast.Program, error) { - f, err := Parse("", []byte(flux), opts...) - if err != nil { - return nil, err - } - return f.(*ast.Program), nil +func NewAST(flux string) (*ast.Program, error) { + fset := token.NewFileSet() + f := fset.AddFile("", -1, len(flux)) + s := scanner.New(f, []byte(flux)) + return fastparser.NewAST(s), nil } diff --git a/parser/parser_debug.go b/parser/parser_debug.go deleted file mode 100644 index fd3de28658..0000000000 --- a/parser/parser_debug.go +++ /dev/null @@ -1,21 +0,0 @@ -// +build parser_debug - -package parser - -//go:generate pigeon -optimize-grammar -o flux.go flux.peg - -import ( - "github.com/influxdata/flux/ast" -) - -// NewAST parses Flux query and produces an ast.Program -func NewAST(flux string, opts ...Option) (*ast.Program, error) { - // Turn on Debugging - opts = append(opts, Debug(true)) - - f, err := Parse("", []byte(flux), opts...) - if err != nil { - return nil, err - } - return f.(*ast.Program), nil -} diff --git a/parser/parser_test.go b/parser/parser_test.go deleted file mode 100644 index bf684d34c6..0000000000 --- a/parser/parser_test.go +++ /dev/null @@ -1,1994 +0,0 @@ -package parser_test - -import ( - "regexp" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/influxdata/flux/ast" - "github.com/influxdata/flux/ast/asttest" - "github.com/influxdata/flux/parser" -) - -func TestParser(t *testing.T) { - testParser(func(name string, fn func(t testing.TB)) { - t.Run(name, func(t *testing.T) { - fn(t) - }) - }) -} - -func BenchmarkParser(b *testing.B) { - testParser(func(name string, fn func(t testing.TB)) { - b.Run(name, func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - fn(b) - } - }) - }) -} - -func testParser(runFn func(name string, fn func(t testing.TB))) { - tests := []struct { - name string - raw string - want *ast.Program - wantErr bool - }{ - { - name: "optional query metadata", - raw: `option task = { - name: "foo", - every: 1h, - delay: 10m, - cron: "0 2 * * *", - retry: 5, - }`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.OptionStatement{ - Declaration: &ast.VariableDeclarator{ - ID: &ast.Identifier{Name: "task"}, - Init: &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "name"}, - Value: &ast.StringLiteral{Value: "foo"}, - }, - { - Key: &ast.Identifier{Name: "every"}, - Value: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 1, - Unit: "h", - }, - }, - }, - }, - { - Key: &ast.Identifier{Name: "delay"}, - Value: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 10, - Unit: "m", - }, - }, - }, - }, - { - Key: &ast.Identifier{Name: "cron"}, - Value: &ast.StringLiteral{Value: "0 2 * * *"}, - }, - { - Key: &ast.Identifier{Name: "retry"}, - Value: &ast.IntegerLiteral{Value: 5}, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "optional query metadata preceding query text", - raw: `option task = { - name: "foo", // Name of task - every: 1h, // Execution frequency of task - } - - // Task will execute the following query - from() |> count()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.OptionStatement{ - Declaration: &ast.VariableDeclarator{ - ID: &ast.Identifier{Name: "task"}, - Init: &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "name"}, - Value: &ast.StringLiteral{Value: "foo"}, - }, - { - Key: &ast.Identifier{Name: "every"}, - Value: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 1, - Unit: "h", - }, - }, - }, - }, - }, - }, - }, - }, - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - Arguments: nil, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "count"}, - Arguments: nil, - }, - }, - }, - }, - }, - }, - { - name: "from", - raw: `from()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "from", - }, - }, - }, - }, - }, - }, - { - name: "comment", - raw: `// Comment - from()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "from", - }, - }, - }, - }, - }, - }, - { - name: "identifier with number", - raw: `tan2()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "tan2", - }, - }, - }, - }, - }, - }, - { - name: "regex literal", - raw: `/.*/`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.RegexpLiteral{ - Value: regexp.MustCompile(".*"), - }, - }, - }, - }, - }, - { - name: "regex literal with escape sequence", - raw: `/a\/b\\c\d/`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.RegexpLiteral{ - Value: regexp.MustCompile(`a/b\\c\d`), - }, - }, - }, - }, - }, - { - name: "regex match operators", - raw: `"a" =~ /.*/ and "b" !~ /c$/`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.LogicalExpression{ - Operator: ast.AndOperator, - Left: &ast.BinaryExpression{ - Operator: ast.RegexpMatchOperator, - Left: &ast.StringLiteral{Value: "a"}, - Right: &ast.RegexpLiteral{Value: regexp.MustCompile(".*")}, - }, - Right: &ast.BinaryExpression{ - Operator: ast.NotRegexpMatchOperator, - Left: &ast.StringLiteral{Value: "b"}, - Right: &ast.RegexpLiteral{Value: regexp.MustCompile("c$")}, - }, - }, - }, - }, - }, - }, - { - name: "declare variable as an int", - raw: `howdy = 1`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{Name: "howdy"}, - Init: &ast.IntegerLiteral{Value: 1}, - }}, - }, - }, - }, - }, - { - name: "declare variable as a float", - raw: `howdy = 1.1`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{Name: "howdy"}, - Init: &ast.FloatLiteral{Value: 1.1}, - }}, - }, - }, - }, - }, - { - name: "declare variable as an array", - raw: `howdy = [1, 2, 3, 4]`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{Name: "howdy"}, - Init: &ast.ArrayExpression{ - Elements: []ast.Expression{ - &ast.IntegerLiteral{Value: 1}, - &ast.IntegerLiteral{Value: 2}, - &ast.IntegerLiteral{Value: 3}, - &ast.IntegerLiteral{Value: 4}, - }, - }, - }}, - }, - }, - }, - }, - { - name: "declare variable as an empty array", - raw: `howdy = []`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{Name: "howdy"}, - Init: &ast.ArrayExpression{}, - }}, - }, - }, - }, - }, - { - name: "use variable to declare something", - raw: `howdy = 1 - from()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{Name: "howdy"}, - Init: &ast.IntegerLiteral{Value: 1}, - }}, - }, - &ast.ExpressionStatement{ - Expression: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "from", - }, - }, - }, - }, - }, - }, - { - name: "variable is from statement", - raw: `howdy = from() - howdy.count()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "howdy", - }, - Init: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "from", - }, - }, - }}, - }, - &ast.ExpressionStatement{ - Expression: &ast.CallExpression{ - Callee: &ast.MemberExpression{ - Object: &ast.Identifier{ - Name: "howdy", - }, - Property: &ast.Identifier{ - Name: "count", - }, - }, - }, - }, - }, - }, - }, - { - name: "pipe expression", - raw: `from() |> count()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - Arguments: nil, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "count"}, - Arguments: nil, - }, - }, - }, - }, - }, - }, - { - name: "literal pipe expression", - raw: `5 |> pow2()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.IntegerLiteral{Value: 5}, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "pow2"}, - Arguments: nil, - }, - }, - }, - }, - }, - }, - { - name: "member expression pipe expression", - raw: `foo.bar |> baz()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "foo"}, - Property: &ast.Identifier{Name: "bar"}, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "baz"}, - Arguments: nil, - }, - }, - }, - }, - }, - }, - { - name: "multiple pipe expressions", - raw: `from() |> range() |> filter() |> count()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.PipeExpression{ - Argument: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "range"}, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "filter"}, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "count"}, - }, - }, - }, - }, - }, - }, - { - name: "two variables for two froms", - raw: `howdy = from() - doody = from() - howdy|>count() - doody|>sum()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "howdy", - }, - Init: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "from", - }, - }, - }}, - }, - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "doody", - }, - Init: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "from", - }, - }, - }}, - }, - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.Identifier{Name: "howdy"}, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "count", - }, - }, - }, - }, - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.Identifier{Name: "doody"}, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "sum", - }, - }, - }, - }, - }, - }, - }, - { - name: "from with database", - raw: `from(bucket:"telegraf/autogen")`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "from", - }, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{ - Name: "bucket", - }, - Value: &ast.StringLiteral{ - Value: "telegraf/autogen", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "map member expressions", - raw: `m = {key1: 1, key2:"value2"} - m.key1 - m["key2"] - `, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "m", - }, - Init: &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "key1"}, - Value: &ast.IntegerLiteral{Value: 1}, - }, - { - Key: &ast.Identifier{Name: "key2"}, - Value: &ast.StringLiteral{Value: "value2"}, - }, - }, - }, - }}, - }, - &ast.ExpressionStatement{ - Expression: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "m"}, - Property: &ast.Identifier{Name: "key1"}, - }, - }, - &ast.ExpressionStatement{ - Expression: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "m"}, - Property: &ast.StringLiteral{Value: "key2"}, - }, - }, - }, - }, - }, - { - name: "index expression", - raw: `a[3]`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.IndexExpression{ - Array: &ast.Identifier{Name: "a"}, - Index: &ast.IntegerLiteral{Value: 3}, - }, - }, - }, - }, - }, - { - name: "nested index expression", - raw: `a[3][5]`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.IndexExpression{ - Array: &ast.IndexExpression{ - Array: &ast.Identifier{Name: "a"}, - Index: &ast.IntegerLiteral{Value: 3}, - }, - Index: &ast.IntegerLiteral{Value: 5}, - }, - }, - }, - }, - }, - { - name: "access indexed object returned from function call", - raw: `f()[3]`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.IndexExpression{ - Array: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "f"}, - }, - Index: &ast.IntegerLiteral{Value: 3}, - }, - }, - }, - }, - }, - { - name: "index with member expressions", - raw: `a.b["c"]`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.MemberExpression{ - Object: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "a"}, - Property: &ast.Identifier{Name: "b"}, - }, - Property: &ast.StringLiteral{Value: "c"}, - }, - }, - }, - }, - }, - { - name: "index with member with call expression", - raw: `a.b()["c"]`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.MemberExpression{ - Object: &ast.CallExpression{ - Callee: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "a"}, - Property: &ast.Identifier{Name: "b"}, - }, - }, - Property: &ast.StringLiteral{Value: "c"}, - }, - }, - }, - }, - }, - { - name: "var as binary expression of other vars", - raw: `a = 1 - b = 2 - c = a + b - d = a`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "a", - }, - Init: &ast.IntegerLiteral{Value: 1}, - }}, - }, - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "b", - }, - Init: &ast.IntegerLiteral{Value: 2}, - }}, - }, - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "c", - }, - Init: &ast.BinaryExpression{ - Operator: ast.AdditionOperator, - Left: &ast.Identifier{Name: "a"}, - Right: &ast.Identifier{Name: "b"}, - }, - }}, - }, - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "d", - }, - Init: &ast.Identifier{Name: "a"}, - }}, - }, - }, - }, - }, - { - name: "var as unary expression of other vars", - raw: `a = 5 - c = -a`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "a", - }, - Init: &ast.IntegerLiteral{Value: 5}, - }}, - }, - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "c", - }, - Init: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.Identifier{Name: "a"}, - }, - }}, - }, - }, - }, - }, - { - name: "var as both binary and unary expressions", - raw: `a = 5 - c = 10 * -a`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "a", - }, - Init: &ast.IntegerLiteral{Value: 5}, - }}, - }, - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "c", - }, - Init: &ast.BinaryExpression{ - Operator: ast.MultiplicationOperator, - Left: &ast.IntegerLiteral{Value: 10}, - Right: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.Identifier{Name: "a"}, - }, - }, - }}, - }, - }, - }, - }, - { - name: "unary expressions within logical expression", - raw: `a = 5.0 - 10.0 * -a == -0.5 or a == 6.0`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "a", - }, - Init: &ast.FloatLiteral{Value: 5}, - }}, - }, - &ast.ExpressionStatement{ - Expression: &ast.LogicalExpression{ - Operator: ast.OrOperator, - Left: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.BinaryExpression{ - Operator: ast.MultiplicationOperator, - Left: &ast.FloatLiteral{Value: 10}, - Right: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.Identifier{Name: "a"}, - }, - }, - Right: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.FloatLiteral{Value: 0.5}, - }, - }, - Right: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.Identifier{Name: "a"}, - Right: &ast.FloatLiteral{Value: 6}, - }, - }, - }, - }, - }, - }, - { - name: "unary expressions with too many comments", - raw: `// define a -a = 5.0 -// eval this -10.0 * -a == -0.5 - // or this - or a == 6.0`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "a", - }, - Init: &ast.FloatLiteral{Value: 5}, - }}, - }, - &ast.ExpressionStatement{ - Expression: &ast.LogicalExpression{ - Operator: ast.OrOperator, - Left: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.BinaryExpression{ - Operator: ast.MultiplicationOperator, - Left: &ast.FloatLiteral{Value: 10}, - Right: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.Identifier{Name: "a"}, - }, - }, - Right: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.FloatLiteral{Value: 0.5}, - }, - }, - Right: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.Identifier{Name: "a"}, - Right: &ast.FloatLiteral{Value: 6}, - }, - }, - }, - }, - }, - }, - { - name: "expressions with function calls", - raw: `a = foo() == 10`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "a", - }, - Init: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "foo"}, - }, - Right: &ast.IntegerLiteral{Value: 10}, - }, - }}, - }, - }, - }, - }, - { - name: "mix unary logical and binary expressions", - raw: ` - not (f() == 6.0 * x) or fail()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.LogicalExpression{ - Operator: ast.OrOperator, - Left: &ast.UnaryExpression{ - Operator: ast.NotOperator, - Argument: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "f"}, - }, - Right: &ast.BinaryExpression{ - Operator: ast.MultiplicationOperator, - Left: &ast.FloatLiteral{Value: 6}, - Right: &ast.Identifier{Name: "x"}, - }, - }, - }, - Right: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "fail"}, - }, - }, - }, - }, - }, - }, - { - name: "mix unary logical and binary expressions with extra parens", - raw: ` - (not (f() == 6.0 * x) or fail())`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.LogicalExpression{ - Operator: ast.OrOperator, - Left: &ast.UnaryExpression{ - Operator: ast.NotOperator, - Argument: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "f"}, - }, - Right: &ast.BinaryExpression{ - Operator: ast.MultiplicationOperator, - Left: &ast.FloatLiteral{Value: 6}, - Right: &ast.Identifier{Name: "x"}, - }, - }, - }, - Right: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "fail"}, - }, - }, - }, - }, - }, - }, - { - name: "arrow function called", - raw: `plusOne = (r) => r + 1 - plusOne(r:5) - `, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "plusOne", - }, - Init: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{{Key: &ast.Identifier{Name: "r"}}}, - Body: &ast.BinaryExpression{ - Operator: ast.AdditionOperator, - Left: &ast.Identifier{Name: "r"}, - Right: &ast.IntegerLiteral{Value: 1}, - }, - }, - }}, - }, - &ast.ExpressionStatement{ - Expression: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "plusOne"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{ - Name: "r", - }, - Value: &ast.IntegerLiteral{ - Value: 5, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "arrow function return map", - raw: `toMap = (r) =>({r:r})`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "toMap", - }, - Init: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{{Key: &ast.Identifier{Name: "r"}}}, - Body: &ast.ObjectExpression{ - Properties: []*ast.Property{{ - Key: &ast.Identifier{Name: "r"}, - Value: &ast.Identifier{Name: "r"}, - }}, - }, - }, - }}, - }, - }, - }, - }, - { - name: "arrow function with default arg", - raw: `addN = (r, n=5) => r + n`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "addN", - }, - Init: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{ - {Key: &ast.Identifier{Name: "r"}}, - {Key: &ast.Identifier{Name: "n"}, Value: &ast.IntegerLiteral{Value: 5}}, - }, - Body: &ast.BinaryExpression{ - Operator: ast.AdditionOperator, - Left: &ast.Identifier{Name: "r"}, - Right: &ast.Identifier{Name: "n"}, - }, - }, - }}, - }, - }, - }, - }, - { - name: "arrow function called in binary expression", - raw: ` - plusOne = (r) => r + 1 - plusOne(r:5) == 6 or die() - `, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "plusOne", - }, - Init: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{{Key: &ast.Identifier{Name: "r"}}}, - Body: &ast.BinaryExpression{ - Operator: ast.AdditionOperator, - Left: &ast.Identifier{Name: "r"}, - Right: &ast.IntegerLiteral{Value: 1}, - }, - }, - }}, - }, - &ast.ExpressionStatement{ - Expression: &ast.LogicalExpression{ - Operator: ast.OrOperator, - Left: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "plusOne"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{ - Name: "r", - }, - Value: &ast.IntegerLiteral{ - Value: 5, - }, - }, - }, - }, - }, - }, - Right: &ast.IntegerLiteral{Value: 6}, - }, - Right: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "die"}, - }, - }, - }, - }, - }, - }, - { - name: "arrow function as single expression", - raw: `f = (r) => r["_measurement"] == "cpu"`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "f", - }, - Init: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{{Key: &ast.Identifier{Name: "r"}}}, - Body: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "r"}, - Property: &ast.StringLiteral{Value: "_measurement"}, - }, - Right: &ast.StringLiteral{Value: "cpu"}, - }, - }, - }}, - }, - }, - }, - }, - { - name: "arrow function as block", - raw: `f = (r) => { - m = r["_measurement"] - return m == "cpu" - }`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "f", - }, - Init: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{{Key: &ast.Identifier{Name: "r"}}}, - Body: &ast.BlockStatement{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "m", - }, - Init: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "r"}, - Property: &ast.StringLiteral{Value: "_measurement"}, - }, - }}, - }, - &ast.ReturnStatement{ - Argument: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.Identifier{Name: "m"}, - Right: &ast.StringLiteral{Value: "cpu"}, - }, - }, - }, - }, - }, - }}, - }, - }, - }, - }, - { - name: "from with filter with no parens", - raw: `from(bucket:"telegraf/autogen").filter(fn: (r) => r["other"]=="mem" and r["this"]=="that" or r["these"]!="those")`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.CallExpression{ - Callee: &ast.MemberExpression{ - Property: &ast.Identifier{Name: "filter"}, - Object: &ast.CallExpression{ - Callee: &ast.Identifier{ - Name: "from", - }, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "bucket"}, - Value: &ast.StringLiteral{Value: "telegraf/autogen"}, - }, - }, - }, - }, - }, - }, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "fn"}, - Value: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{{Key: &ast.Identifier{Name: "r"}}}, - Body: &ast.LogicalExpression{ - Operator: ast.OrOperator, - Left: &ast.LogicalExpression{ - Operator: ast.AndOperator, - Left: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "r"}, - Property: &ast.StringLiteral{Value: "other"}, - }, - Right: &ast.StringLiteral{Value: "mem"}, - }, - Right: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "r"}, - Property: &ast.StringLiteral{Value: "this"}, - }, - Right: &ast.StringLiteral{Value: "that"}, - }, - }, - Right: &ast.BinaryExpression{ - Operator: ast.NotEqualOperator, - Left: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "r"}, - Property: &ast.StringLiteral{Value: "these"}, - }, - Right: &ast.StringLiteral{Value: "those"}, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "from with range", - raw: `from(bucket:"telegraf/autogen")|>range(start:-1h, end:10m)`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "bucket"}, - Value: &ast.StringLiteral{Value: "telegraf/autogen"}, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "range"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "start"}, - Value: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 1, - Unit: "h", - }, - }, - }, - }, - }, - { - Key: &ast.Identifier{Name: "end"}, - Value: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 10, - Unit: "m", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "from with limit", - raw: `from(bucket:"telegraf/autogen")|>limit(limit:100, offset:10)`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "bucket"}, - Value: &ast.StringLiteral{Value: "telegraf/autogen"}, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "limit"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "limit"}, - Value: &ast.IntegerLiteral{Value: 100}, - }, - { - Key: &ast.Identifier{Name: "offset"}, - Value: &ast.IntegerLiteral{Value: 10}, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "from with range and count", - raw: `from(bucket:"mydb/autogen") - |> range(start:-4h, stop:-2h) - |> count()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "bucket"}, - Value: &ast.StringLiteral{Value: "mydb/autogen"}, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "range"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "start"}, - Value: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 4, - Unit: "h", - }, - }, - }, - }, - }, - { - Key: &ast.Identifier{Name: "stop"}, - Value: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 2, - Unit: "h", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "count"}, - }, - }, - }, - }, - }, - }, - { - name: "from with range, limit and count", - raw: `from(bucket:"mydb/autogen") - |> range(start:-4h, stop:-2h) - |> limit(n:10) - |> count()`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.ExpressionStatement{ - Expression: &ast.PipeExpression{ - Argument: &ast.PipeExpression{ - Argument: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "bucket"}, - Value: &ast.StringLiteral{Value: "mydb/autogen"}, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "range"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "start"}, - Value: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 4, - Unit: "h", - }, - }, - }, - }, - }, - { - Key: &ast.Identifier{Name: "stop"}, - Value: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 2, - Unit: "h", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "limit"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{{ - Key: &ast.Identifier{Name: "n"}, - Value: &ast.IntegerLiteral{Value: 10}, - }}, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "count"}, - }, - }, - }, - }, - }, - }, - { - name: "from with join", - raw: ` -a = from(bucket:"dbA/autogen") |> range(start:-1h) -b = from(bucket:"dbB/autogen") |> range(start:-1h) -join(tables:[a,b], on:["host"], fn: (a,b) => a["_field"] + b["_field"])`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "a", - }, - Init: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "bucket"}, - Value: &ast.StringLiteral{Value: "dbA/autogen"}, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "range"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "start"}, - Value: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 1, - Unit: "h", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }}, - }, - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "b", - }, - Init: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "bucket"}, - Value: &ast.StringLiteral{Value: "dbB/autogen"}, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "range"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "start"}, - Value: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 1, - Unit: "h", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }}, - }, - &ast.ExpressionStatement{ - Expression: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "join"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "tables"}, - Value: &ast.ArrayExpression{ - Elements: []ast.Expression{ - &ast.Identifier{Name: "a"}, - &ast.Identifier{Name: "b"}, - }, - }, - }, - { - Key: &ast.Identifier{Name: "on"}, - Value: &ast.ArrayExpression{ - Elements: []ast.Expression{&ast.StringLiteral{Value: "host"}}, - }, - }, - { - Key: &ast.Identifier{Name: "fn"}, - Value: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{ - {Key: &ast.Identifier{Name: "a"}}, - {Key: &ast.Identifier{Name: "b"}}, - }, - Body: &ast.BinaryExpression{ - Operator: ast.AdditionOperator, - Left: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "a"}, - Property: &ast.StringLiteral{Value: "_field"}, - }, - Right: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "b"}, - Property: &ast.StringLiteral{Value: "_field"}, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "from with join with complex expression", - raw: ` -a = from(bucket:"Flux/autogen") - |> filter(fn: (r) => r["_measurement"] == "a") - |> range(start:-1h) - -b = from(bucket:"Flux/autogen") - |> filter(fn: (r) => r["_measurement"] == "b") - |> range(start:-1h) - -join(tables:[a,b], on:["t1"], fn: (a,b) => (a["_field"] - b["_field"]) / b["_field"]) -`, - want: &ast.Program{ - Body: []ast.Statement{ - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "a", - }, - Init: &ast.PipeExpression{ - Argument: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "bucket"}, - Value: &ast.StringLiteral{Value: "Flux/autogen"}, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "filter"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "fn"}, - Value: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{{Key: &ast.Identifier{Name: "r"}}}, - Body: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "r"}, - Property: &ast.StringLiteral{Value: "_measurement"}, - }, - Right: &ast.StringLiteral{Value: "a"}, - }, - }, - }, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "range"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "start"}, - Value: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 1, - Unit: "h", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }}, - }, - &ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{ - Name: "b", - }, - Init: &ast.PipeExpression{ - Argument: &ast.PipeExpression{ - Argument: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "from"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "bucket"}, - Value: &ast.StringLiteral{Value: "Flux/autogen"}, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "filter"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "fn"}, - Value: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{{Key: &ast.Identifier{Name: "r"}}}, - Body: &ast.BinaryExpression{ - Operator: ast.EqualOperator, - Left: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "r"}, - Property: &ast.StringLiteral{Value: "_measurement"}, - }, - Right: &ast.StringLiteral{Value: "b"}, - }, - }, - }, - }, - }, - }, - }, - }, - Call: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "range"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "start"}, - Value: &ast.UnaryExpression{ - Operator: ast.SubtractionOperator, - Argument: &ast.DurationLiteral{ - Values: []ast.Duration{ - { - Magnitude: 1, - Unit: "h", - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }}, - }, - &ast.ExpressionStatement{ - Expression: &ast.CallExpression{ - Callee: &ast.Identifier{Name: "join"}, - Arguments: []ast.Expression{ - &ast.ObjectExpression{ - Properties: []*ast.Property{ - { - Key: &ast.Identifier{Name: "tables"}, - Value: &ast.ArrayExpression{ - Elements: []ast.Expression{ - &ast.Identifier{Name: "a"}, - &ast.Identifier{Name: "b"}, - }, - }, - }, - { - Key: &ast.Identifier{Name: "on"}, - Value: &ast.ArrayExpression{ - Elements: []ast.Expression{ - &ast.StringLiteral{ - Value: "t1", - }, - }, - }, - }, - { - Key: &ast.Identifier{Name: "fn"}, - Value: &ast.ArrowFunctionExpression{ - Params: []*ast.Property{ - {Key: &ast.Identifier{Name: "a"}}, - {Key: &ast.Identifier{Name: "b"}}, - }, - Body: &ast.BinaryExpression{ - Operator: ast.DivisionOperator, - Left: &ast.BinaryExpression{ - Operator: ast.SubtractionOperator, - Left: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "a"}, - Property: &ast.StringLiteral{Value: "_field"}, - }, - Right: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "b"}, - Property: &ast.StringLiteral{Value: "_field"}, - }, - }, - Right: &ast.MemberExpression{ - Object: &ast.Identifier{Name: "b"}, - Property: &ast.StringLiteral{Value: "_field"}, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - { - name: "duration literal, all units", - raw: `dur = 1y3mo2w1d4h1m30s1ms2µs70ns`, - want: &ast.Program{ - Body: []ast.Statement{&ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{Name: "dur"}, - Init: &ast.DurationLiteral{ - Values: []ast.Duration{ - {Magnitude: 1, Unit: "y"}, - {Magnitude: 3, Unit: "mo"}, - {Magnitude: 2, Unit: "w"}, - {Magnitude: 1, Unit: "d"}, - {Magnitude: 4, Unit: "h"}, - {Magnitude: 1, Unit: "m"}, - {Magnitude: 30, Unit: "s"}, - {Magnitude: 1, Unit: "ms"}, - {Magnitude: 2, Unit: "us"}, - {Magnitude: 70, Unit: "ns"}, - }, - }, - }}, - }}, - }, - }, - { - name: "duration literal, months", - raw: `dur = 6mo`, - want: &ast.Program{ - Body: []ast.Statement{&ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{Name: "dur"}, - Init: &ast.DurationLiteral{ - Values: []ast.Duration{ - {Magnitude: 6, Unit: "mo"}, - }, - }, - }}, - }}, - }, - }, - { - name: "duration literal, milliseconds", - raw: `dur = 500ms`, - want: &ast.Program{ - Body: []ast.Statement{&ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{Name: "dur"}, - Init: &ast.DurationLiteral{ - Values: []ast.Duration{ - {Magnitude: 500, Unit: "ms"}, - }, - }, - }}, - }}, - }, - }, - { - name: "duration literal, months, minutes, milliseconds", - raw: `dur = 6mo30m500ms`, - want: &ast.Program{ - Body: []ast.Statement{&ast.VariableDeclaration{ - Declarations: []*ast.VariableDeclarator{{ - ID: &ast.Identifier{Name: "dur"}, - Init: &ast.DurationLiteral{ - Values: []ast.Duration{ - {Magnitude: 6, Unit: "mo"}, - {Magnitude: 30, Unit: "m"}, - {Magnitude: 500, Unit: "ms"}, - }, - }, - }}, - }}, - }, - }, - { - name: "parse error extra gibberish", - raw: `from(bucket:"Flux/autogen") &^*&H#IUJBN`, - wantErr: true, - }, - { - name: "parse error extra gibberish and valid content", - raw: `from(bucket:"Flux/autogen") &^*&H#IUJBN from(bucket:"other/autogen")`, - wantErr: true, - }, - { - name: "parse error from duration literal with repeated units", - raw: `from(bucket:"my_bucket") |> range(start: -1d3h2h1m)`, - wantErr: true, - }, - { - name: "parser error from duration literal with smaller unit before larger one", - raw: `from(bucket:"my_bucket") |> range(start: -1s5m)`, - wantErr: true, - }, - { - name: "parser error from duration literal with invalid unit", - raw: `from(bucket:"my_bucket") |> range(start: -1s5v)`, - wantErr: true, - }, - { - name: "member expression with integer property", - raw: `obj.5`, - wantErr: true, - }, - } - for _, tt := range tests { - runFn(tt.name, func(tb testing.TB) { - // Set the env var`GO_TAGS=parser_debug` in order - // to turn on parser debugging as it is turned off by default. - got, err := parser.NewAST(tt.raw) - if (err != nil) != tt.wantErr { - tb.Errorf("parser.NewAST() error = %v, wantErr %v", err, tt.wantErr) - return - } - if tt.wantErr { - return - } - if !cmp.Equal(tt.want, got, asttest.CompareOptions...) { - tb.Errorf("parser.NewAST() = -want/+got %s", cmp.Diff(tt.want, got, asttest.CompareOptions...)) - } - }) - } -} - -var benchmarkQuery = []byte(` -start = -10s - -do = (cpu) => - from(bucket:"telegraf/autogen") - .filter(fn: (r) => - r["_measurement"] == "cpu" - and - r["cpu"] == cpu) - .range(start:start) - -cpu0 = do(cpu:"cpu0") -cpu1 = do(cpu:"cpu1") - -join( - tables:[cpu0, cpu1], - on:["_measurement","_field","host"], - fn: (a,b) => a["_value"] - b["_value"], -) -`) - -var benchmarkProgram interface{} - -func BenchmarkParseQuery(b *testing.B) { - b.ReportAllocs() - var err error - for n := 0; n < b.N; n++ { - benchmarkProgram, err = parser.Parse("", benchmarkQuery) - if err != nil { - b.Fatal(err) - } - } -} diff --git a/parser/types.go b/parser/types.go deleted file mode 100644 index 70cbcf7f13..0000000000 --- a/parser/types.go +++ /dev/null @@ -1,431 +0,0 @@ -package parser - -import ( - "bytes" - "regexp" - "strconv" - "strings" - "time" - - "github.com/influxdata/flux/ast" -) - -func toIfaceSlice(v interface{}) []interface{} { - if v == nil { - return nil - } - return v.([]interface{}) -} - -func toDurationSlice(durations []*singleDurationLiteral) []ast.Duration { - durs := make([]ast.Duration, len(durations)) - for i, d := range durations { - durs[i] = ast.Duration{ - Magnitude: d.magnitude.Value, - Unit: d.unit, - } - } - return durs -} - -func program(body interface{}, text []byte, pos position) (*ast.Program, error) { - return &ast.Program{ - BaseNode: base(text, pos), - Body: body.([]ast.Statement), - }, nil -} - -func srcElems(head, tails interface{}) ([]ast.Statement, error) { - elems := []ast.Statement{head.(ast.Statement)} - for _, tail := range toIfaceSlice(tails) { - elem := toIfaceSlice(tail)[1] // Skip whitespace - elems = append(elems, elem.(ast.Statement)) - } - return elems, nil -} - -func blockstmt(body interface{}, text []byte, pos position) (*ast.BlockStatement, error) { - bodySlice := toIfaceSlice(body) - statements := make([]ast.Statement, len(bodySlice)) - for i, s := range bodySlice { - stmt := toIfaceSlice(s)[1] // Skip whitespace - statements[i] = stmt.(ast.Statement) - } - return &ast.BlockStatement{ - BaseNode: base(text, pos), - Body: statements, - }, nil -} - -func optionstmt(id, expr interface{}, text []byte, pos position) (*ast.OptionStatement, error) { - return &ast.OptionStatement{ - BaseNode: base(text, pos), - Declaration: &ast.VariableDeclarator{ - BaseNode: base(text, pos), - ID: id.(*ast.Identifier), - Init: expr.(ast.Expression), - }, - }, nil -} - -func varstmt(declaration interface{}, text []byte, pos position) (*ast.VariableDeclaration, error) { - return &ast.VariableDeclaration{ - BaseNode: base(text, pos), - Declarations: []*ast.VariableDeclarator{declaration.(*ast.VariableDeclarator)}, - }, nil -} - -func vardecl(id, initializer interface{}, text []byte, pos position) (*ast.VariableDeclarator, error) { - return &ast.VariableDeclarator{ - BaseNode: base(text, pos), - ID: id.(*ast.Identifier), - Init: initializer.(ast.Expression), - }, nil -} - -func exprstmt(expr interface{}, text []byte, pos position) (*ast.ExpressionStatement, error) { - return &ast.ExpressionStatement{ - Expression: expr.(ast.Expression), - BaseNode: base(text, pos), - }, nil -} - -func returnstmt(argument interface{}, text []byte, pos position) (*ast.ReturnStatement, error) { - return &ast.ReturnStatement{ - BaseNode: base(text, pos), - Argument: argument.(ast.Expression), - }, nil -} - -func pipeExprs(head, tail interface{}, text []byte, pos position) (*ast.PipeExpression, error) { - var arg ast.Expression = head.(ast.Expression) - - var pe *ast.PipeExpression - for _, t := range toIfaceSlice(tail) { - pe = toIfaceSlice(t)[1].(*ast.PipeExpression) - pe.Argument = arg - arg = pe - } - return pe, nil -} - -func incompletePipeExpr(call interface{}, text []byte, pos position) (*ast.PipeExpression, error) { - return &ast.PipeExpression{ - Call: call.(*ast.CallExpression), - BaseNode: base(text, pos), - }, nil -} - -func memberexprs(head, tail interface{}, text []byte, pos position) (ast.Expression, error) { - res := head.(ast.Expression) - for _, prop := range toIfaceSlice(tail) { - switch expr := prop.(type) { - case *ast.MemberExpression: - expr.BaseNode = base(text, pos) - expr.Object = res - res = expr - case *ast.IndexExpression: - expr.BaseNode = base(text, pos) - expr.Array = res - res = expr - } - } - return res, nil -} - -func memberExprFromIdentifier(p interface{}) (*ast.MemberExpression, error) { - return &ast.MemberExpression{Property: p.(*ast.Identifier)}, nil -} - -func memberExprFromStringLiteral(p interface{}) (*ast.MemberExpression, error) { - return &ast.MemberExpression{Property: p.(*ast.StringLiteral)}, nil -} - -func indexExpr(p interface{}) (*ast.IndexExpression, error) { - return &ast.IndexExpression{Index: p.(ast.Expression)}, nil -} - -func callexpr(callee, args interface{}, text []byte, pos position) (*ast.CallExpression, error) { - c := &ast.CallExpression{ - BaseNode: base(text, pos), - } - - if callee != nil { - c.Callee = callee.(ast.Expression) - } - - if args != nil { - c.Arguments = []ast.Expression{args.(*ast.ObjectExpression)} - } - return c, nil -} - -func callexprs(head, tail interface{}, text []byte, pos position) (ast.Expression, error) { - expr := head.(ast.Expression) - for _, i := range toIfaceSlice(tail) { - switch elem := i.(type) { - case *ast.CallExpression: - elem.Callee = expr - expr = elem - case *ast.MemberExpression: - elem.BaseNode = base(text, pos) - elem.Object = expr - expr = elem - case *ast.IndexExpression: - elem.BaseNode = base(text, pos) - elem.Array = expr - expr = elem - } - } - return expr, nil -} - -func arrowfunc(params interface{}, body interface{}, text []byte, pos position) *ast.ArrowFunctionExpression { - paramsSlice := toIfaceSlice(params) - paramsList := make([]*ast.Property, len(paramsSlice)) - for i, p := range paramsSlice { - paramsList[i] = p.(*ast.Property) - } - return &ast.ArrowFunctionExpression{ - BaseNode: base(text, pos), - Params: paramsList, - Body: body.(ast.Node), - } -} - -func objectexpr(first, rest interface{}, text []byte, pos position) (*ast.ObjectExpression, error) { - props := []*ast.Property{first.(*ast.Property)} - if rest != nil { - for _, prop := range toIfaceSlice(rest) { - props = append(props, prop.(*ast.Property)) - } - } - - return &ast.ObjectExpression{ - Properties: props, - BaseNode: base(text, pos), - }, nil -} - -func property(key, value interface{}, text []byte, pos position) (*ast.Property, error) { - var v ast.Expression - if value != nil { - v = value.(ast.Expression) - } - return &ast.Property{ - Key: key.(*ast.Identifier), - Value: v, - BaseNode: base(text, pos), - }, nil -} - -func identifier(text []byte, pos position) (*ast.Identifier, error) { - return &ast.Identifier{ - Name: string(text), - BaseNode: base(text, pos), - }, nil -} - -func array(first, rest interface{}, text []byte, pos position) *ast.ArrayExpression { - var elements []ast.Expression - if first != nil { - elements = append(elements, first.(ast.Expression)) - } - if rest != nil { - for _, el := range rest.([]interface{}) { - elements = append(elements, el.(ast.Expression)) - } - } - return &ast.ArrayExpression{ - Elements: elements, - BaseNode: base(text, pos), - } -} - -func emptyArray(text []byte, pos position) *ast.ArrayExpression { - return &ast.ArrayExpression{BaseNode: base(text, pos)} -} - -func logicalExpression(head, tails interface{}, text []byte, pos position) (ast.Expression, error) { - res := head.(ast.Expression) - for _, tail := range toIfaceSlice(tails) { - right := toIfaceSlice(tail) - res = &ast.LogicalExpression{ - Left: res, - Right: right[3].(ast.Expression), - Operator: right[1].(ast.LogicalOperatorKind), - BaseNode: base(text, pos), - } - } - return res, nil -} - -func logicalOp(text []byte) (ast.LogicalOperatorKind, error) { - return ast.LogicalOperatorLookup(strings.ToLower(string(text))), nil -} - -func binaryExpression(head, tails interface{}, text []byte, pos position) (ast.Expression, error) { - res := head.(ast.Expression) - for _, tail := range toIfaceSlice(tails) { - right := toIfaceSlice(tail) - res = &ast.BinaryExpression{ - Left: res, - Right: right[3].(ast.Expression), - Operator: right[1].(ast.OperatorKind), - BaseNode: base(text, pos), - } - } - return res, nil -} - -func unaryExpression(op, argument interface{}, text []byte, pos position) (*ast.UnaryExpression, error) { - return &ast.UnaryExpression{ - Operator: op.(ast.OperatorKind), - Argument: argument.(ast.Expression), - BaseNode: base(text, pos), - }, nil -} - -func operator(text []byte) (ast.OperatorKind, error) { - return ast.OperatorLookup(strings.ToLower(string(text))), nil -} - -func stringLiteral(text []byte, pos position) (*ast.StringLiteral, error) { - s, err := strconv.Unquote(string(text)) - if err != nil { - return nil, err - } - return &ast.StringLiteral{ - BaseNode: base(text, pos), - Value: s, - }, nil -} - -func pipeLiteral(text []byte, pos position) *ast.PipeLiteral { - return &ast.PipeLiteral{ - BaseNode: base(text, pos), - } -} - -func booleanLiteral(b bool, text []byte, pos position) (*ast.BooleanLiteral, error) { - return &ast.BooleanLiteral{ - BaseNode: base(text, pos), - Value: b, - }, nil -} - -func integerLiteral(text []byte, pos position) (*ast.IntegerLiteral, error) { - n, err := strconv.ParseInt(string(text), 10, 64) - if err != nil { - return nil, err - } - return &ast.IntegerLiteral{ - BaseNode: base(text, pos), - Value: n, - }, nil -} - -func numberLiteral(text []byte, pos position) (*ast.FloatLiteral, error) { - n, err := strconv.ParseFloat(string(text), 64) - if err != nil { - return nil, err - } - return &ast.FloatLiteral{ - BaseNode: base(text, pos), - Value: n, - }, nil -} - -func regexLiteral(chars interface{}, text []byte, pos position) (*ast.RegexpLiteral, error) { - b := new(strings.Builder) - for _, char := range toIfaceSlice(chars) { - b.Write(char.([]byte)) - } - - r, err := regexp.Compile(b.String()) - if err != nil { - return nil, err - } - return &ast.RegexpLiteral{ - BaseNode: base(text, pos), - Value: r, - }, nil -} - -func durationLiteral(durations interface{}, text []byte, pos position) (*ast.DurationLiteral, error) { - literals := durations.([]*singleDurationLiteral) - // The slice built by the parser goes from smallest units to largest (opposite of syntax), - // reverse it for the AST produced. - for i := 0; i < len(literals)/2; i++ { - j := len(literals) - i - 1 - literals[i], literals[j] = literals[j], literals[i] - } - - return &ast.DurationLiteral{ - BaseNode: base(text, pos), - Values: toDurationSlice(literals), - }, nil -} - -type singleDurationLiteral struct { - magnitude *ast.IntegerLiteral - unit string -} - -func appendSingleDurations(mag, unit, otherParts interface{}, text []byte, pos position) ([]*singleDurationLiteral, error) { - sdl := &singleDurationLiteral{ - magnitude: mag.(*ast.IntegerLiteral), - unit: string(unit.([]byte)), - } - - if otherParts == nil { - slice := make([]*singleDurationLiteral, 1, 10) - slice[0] = sdl - return slice, nil - } - - others := otherParts.([]*singleDurationLiteral) - return append(others, sdl), nil -} - -func datetime(text []byte, pos position) (*ast.DateTimeLiteral, error) { - t, err := time.Parse(time.RFC3339Nano, string(text)) - if err != nil { - return nil, err - } - return &ast.DateTimeLiteral{ - BaseNode: base(text, pos), - Value: t, - }, nil -} - -func base(text []byte, pos position) ast.BaseNode { - lines, idx := countLines(text) - col := pos.col - if lines > 0 { - col = 0 - } - return ast.BaseNode{ - Loc: &ast.SourceLocation{ - Start: ast.Position{ - Line: pos.line, - Column: pos.col, - }, - End: ast.Position{ - Line: pos.line + lines, - Column: col + len(text) - idx, - }, - Source: string(text), - }, - } -} - -func countLines(text []byte) (int, int) { - count := 0 - idx := 0 - for i := bytes.IndexRune(text, '\n'); i >= 0; i = bytes.IndexRune(text[idx:], '\n') { - count++ - idx += i + 1 - } - return count, idx -} diff --git a/semantic/inference_test.go b/semantic/inference_test.go index 10ed04aa12..d2a0e409c1 100644 --- a/semantic/inference_test.go +++ b/semantic/inference_test.go @@ -332,10 +332,10 @@ identity(x:identity)(x:2) }) switch n := node.(type) { case *semantic.CallExpression: - switch n.Location().Start.Column { - case 1: - return outF + switch n.Location().End.Column { case 21: + return outF + case 26: return outInt } case *semantic.IdentifierExpression: @@ -1308,9 +1308,9 @@ foo(r:{a:1.1,b:42.0}) return fooOut case *semantic.ObjectExpression: switch l, c := n.Location().Start.Line, n.Location().Start.Column; { - case l == 2: + case l == 2 && c == 8: return semantic.NewEmptyObjectPolyType() - case l == 3: + case l == 2 && c == 15: return fooOut case l == 7 && c == 5: return semantic.NewObjectPolyType( @@ -1318,7 +1318,7 @@ foo(r:{a:1.1,b:42.0}) nil, requiredR, ) - case l == 7 && c == 8: + case l == 7 && c == 7: return obj1 case l == 8 && c == 5: return semantic.NewObjectPolyType( @@ -1326,7 +1326,7 @@ foo(r:{a:1.1,b:42.0}) nil, requiredR, ) - case l == 8 && c == 8: + case l == 8 && c == 7: return obj2 } case *semantic.Property: @@ -1455,6 +1455,24 @@ plus1(r:{_value: 2.0}) } tc.node = node } + + // Add the true and false identifiers. + tc.node = &semantic.Extern{ + Declarations: []*semantic.ExternalVariableDeclaration{ + { + Identifier: &semantic.Identifier{Name: "true"}, + ExternType: semantic.Bool, + }, + { + Identifier: &semantic.Identifier{Name: "false"}, + ExternType: semantic.Bool, + }, + }, + Block: &semantic.ExternBlock{ + Node: tc.node, + }, + } + var wantSolution SolutionMap if tc.solution != nil { semantic.Walk(tc.solution, tc.node) diff --git a/tools.go b/tools.go deleted file mode 100644 index c85a565873..0000000000 --- a/tools.go +++ /dev/null @@ -1,7 +0,0 @@ -//+build tools - -package flux - -import ( - _ "github.com/mna/pigeon" -)