From 2ae625e68ae74bda1f23d63f20deba6d991e5996 Mon Sep 17 00:00:00 2001 From: Sidhant Aggarwal <10743214+sidhant92@users.noreply.github.com> Date: Tue, 7 Nov 2023 18:02:41 +0530 Subject: [PATCH 1/4] support for array types --- go.mod | 7 +- go.sum | 12 +- .../containerdatatype/container_data_type.go | 11 + .../container_data_type_factory.go | 19 + .../list_container_data_type.go | 31 + .../primitive_container_data_type.go | 25 + internal/datatype/boolean_data_type.go | 12 +- internal/datatype/data_type.go | 2 +- internal/datatype/data_type_factory.go | 5 + internal/datatype/decimal_data_type.go | 12 +- internal/datatype/int_data_type.go | 12 +- internal/datatype/long_data_type.go | 12 +- internal/datatype/string_data_type.go | 12 +- internal/datatype/version_data_type.go | 12 +- internal/operator/abstract_operator.go | 6 +- internal/operator/contains_all_operator.go | 49 + internal/operator/contains_any_operator.go | 49 + internal/operator/equals_operator.go | 16 +- .../operator/greater_than_equal_operator.go | 16 +- internal/operator/greater_than_operator.go | 12 +- internal/operator/in_operator.go | 12 +- internal/operator/less_than_equal_operator.go | 16 +- internal/operator/less_than_operator.go | 16 +- internal/operator/not_equals_operator.go | 12 +- internal/operator/operator_factory.go | 2 + internal/parser/antlr/antlr_parser.go | 14 +- internal/parser/antlr/antlr_parser_test.go | 18 + internal/parser/antlr/boolean_expression.g4 | 11 +- .../antlr/lib/booleanexpression_lexer.go | 287 ++-- .../antlr/lib/booleanexpression_listener.go | 16 +- .../antlr/lib/booleanexpression_parser.go | 1228 +++++++++++------ internal/parser/antlr/listener.go | 52 +- internal/service/operator_service.go | 26 +- internal/util/helper_functions.go | 17 + .../boolean_expression_evaluator.go | 27 +- .../boolean_expression_evaluator_test.go | 45 + pkg/constant/container_data_type.go | 8 + pkg/constant/node_type.go | 5 +- pkg/constant/operator.go | 3 +- pkg/domain/array_node.go | 13 + pkg/error/errors.go | 2 + 41 files changed, 1541 insertions(+), 621 deletions(-) create mode 100644 internal/containerdatatype/container_data_type.go create mode 100644 internal/containerdatatype/container_data_type_factory.go create mode 100644 internal/containerdatatype/list_container_data_type.go create mode 100644 internal/containerdatatype/primitive_container_data_type.go create mode 100644 internal/operator/contains_all_operator.go create mode 100644 internal/operator/contains_any_operator.go create mode 100644 pkg/constant/container_data_type.go create mode 100644 pkg/domain/array_node.go diff --git a/go.mod b/go.mod index 12e050c..911ca13 100644 --- a/go.mod +++ b/go.mod @@ -3,15 +3,16 @@ module github.com/sidhant92/bool-parser-go go 1.20 require ( - github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12 + github.com/antlr4-go/antlr v0.0.0-20230518091524-98b52378c522 + github.com/antlr4-go/antlr/v4 v4.13.0 github.com/hashicorp/go-version v1.6.0 + github.com/hashicorp/golang-lru/v2 v2.0.1 github.com/stretchr/testify v1.8.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/hashicorp/golang-lru/v2 v2.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect + golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 72b4ead..a19c2bb 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ -github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12 h1:npHgfD4Tl2WJS3AJaMUi5ynGDPUBfkg3U3fCzDyXZ+4= -github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM= +github.com/antlr4-go/antlr v0.0.0-20230518091524-98b52378c522 h1:o+W7GDFUwWtVkN28CW/nhh/aCmHn6OJddUs3+8vMMjs= +github.com/antlr4-go/antlr v0.0.0-20230518091524-98b52378c522/go.mod h1:srLVvW4JLxy+tCG9Nn2l8al77mUIMCwAOLQocfLDU2w= +github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= +github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -16,8 +18,10 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= -golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= +golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU= +golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/containerdatatype/container_data_type.go b/internal/containerdatatype/container_data_type.go new file mode 100644 index 0000000..be8143f --- /dev/null +++ b/internal/containerdatatype/container_data_type.go @@ -0,0 +1,11 @@ +package containerdatatype + +import ( + "github.com/sidhant92/bool-parser-go/pkg/constant" +) + +type ContainerDataType interface { + IsValid(dataType constant.DataType, value interface{}) bool + + GetContainerDataType() constant.ContainerDataType +} diff --git a/internal/containerdatatype/container_data_type_factory.go b/internal/containerdatatype/container_data_type_factory.go new file mode 100644 index 0000000..b9bb501 --- /dev/null +++ b/internal/containerdatatype/container_data_type_factory.go @@ -0,0 +1,19 @@ +package containerdatatype + +import ( + "github.com/sidhant92/bool-parser-go/pkg/constant" + "golang.org/x/exp/maps" +) + +var containerDataTypeMap = map[constant.ContainerDataType]ContainerDataType{ + constant.PRIMITIVE: NewPrimitiveContainerDataType(), + constant.LIST: NewListContainerDataType(), +} + +func GetContainerDataType(containerDataType constant.ContainerDataType) ContainerDataType { + return containerDataTypeMap[containerDataType] +} + +func GetAllDataTypes() []ContainerDataType { + return maps.Values(containerDataTypeMap) +} diff --git a/internal/containerdatatype/list_container_data_type.go b/internal/containerdatatype/list_container_data_type.go new file mode 100644 index 0000000..1dfdd42 --- /dev/null +++ b/internal/containerdatatype/list_container_data_type.go @@ -0,0 +1,31 @@ +package containerdatatype + +import ( + "github.com/sidhant92/bool-parser-go/internal/datatype" + "github.com/sidhant92/bool-parser-go/internal/util" + "github.com/sidhant92/bool-parser-go/pkg/constant" +) + +type ListContainerDataType struct { +} + +func (s *ListContainerDataType) GetContainerDataType() constant.ContainerDataType { + return constant.LIST +} + +func (s *ListContainerDataType) IsValid(dataType constant.DataType, value interface{}) bool { + if !util.IsSlice(value) { + return false + } + var slice = util.GetSliceFromInterface(value) + for _, value := range slice { + if !datatype.GetDataType(dataType).IsValid(value) { + return false + } + } + return true +} + +func NewListContainerDataType() ContainerDataType { + return &ListContainerDataType{} +} diff --git a/internal/containerdatatype/primitive_container_data_type.go b/internal/containerdatatype/primitive_container_data_type.go new file mode 100644 index 0000000..6f59d3f --- /dev/null +++ b/internal/containerdatatype/primitive_container_data_type.go @@ -0,0 +1,25 @@ +package containerdatatype + +import ( + "github.com/sidhant92/bool-parser-go/internal/datatype" + "github.com/sidhant92/bool-parser-go/internal/util" + "github.com/sidhant92/bool-parser-go/pkg/constant" +) + +type PrimitiveContainerDataType struct { +} + +func (s *PrimitiveContainerDataType) GetContainerDataType() constant.ContainerDataType { + return constant.PRIMITIVE +} + +func (s *PrimitiveContainerDataType) IsValid(dataType constant.DataType, value interface{}) bool { + if util.IsSlice(value) { + return false + } + return datatype.GetDataType(dataType).IsValid(value) +} + +func NewPrimitiveContainerDataType() ContainerDataType { + return &PrimitiveContainerDataType{} +} diff --git a/internal/datatype/boolean_data_type.go b/internal/datatype/boolean_data_type.go index 5c90f62..47ffdda 100644 --- a/internal/datatype/boolean_data_type.go +++ b/internal/datatype/boolean_data_type.go @@ -39,11 +39,13 @@ func (s *BooleanDataType) GetValue(value interface{}) interface{} { return res } -func (s *BooleanDataType) Compare(left interface{}, right interface{}) (int, error) { - leftValid := s.IsValid(left) - rightValid := s.IsValid(right) - if !leftValid || !rightValid { - return 0, errors.INVALID_DATA_TYPE +func (s *BooleanDataType) Compare(left interface{}, right interface{}, validated bool) (int, error) { + if !validated { + leftValid := s.IsValid(left) + rightValid := s.IsValid(right) + if !leftValid || !rightValid { + return 0, errors.INVALID_DATA_TYPE + } } leftValue := s.GetValue(left).(bool) rightValue := s.GetValue(right).(bool) diff --git a/internal/datatype/data_type.go b/internal/datatype/data_type.go index 3bac21c..17adb78 100644 --- a/internal/datatype/data_type.go +++ b/internal/datatype/data_type.go @@ -9,5 +9,5 @@ type DataType interface { GetValue(value interface{}) any - Compare(left interface{}, right interface{}) (int, error) + Compare(left interface{}, right interface{}, validated bool) (int, error) } diff --git a/internal/datatype/data_type_factory.go b/internal/datatype/data_type_factory.go index 5a5fa6a..71fe9dc 100644 --- a/internal/datatype/data_type_factory.go +++ b/internal/datatype/data_type_factory.go @@ -2,6 +2,7 @@ package datatype import ( "github.com/sidhant92/bool-parser-go/pkg/constant" + "golang.org/x/exp/maps" ) var dataTypeMap = map[constant.DataType]DataType{ @@ -16,3 +17,7 @@ var dataTypeMap = map[constant.DataType]DataType{ func GetDataType(dataType constant.DataType) DataType { return dataTypeMap[dataType] } + +func GetAllDataTypes() []DataType { + return maps.Values(dataTypeMap) +} diff --git a/internal/datatype/decimal_data_type.go b/internal/datatype/decimal_data_type.go index 912321b..302b0cb 100644 --- a/internal/datatype/decimal_data_type.go +++ b/internal/datatype/decimal_data_type.go @@ -39,11 +39,13 @@ func (s *DecimalDataType) GetValue(value interface{}) interface{} { return res } -func (s *DecimalDataType) Compare(left interface{}, right interface{}) (int, error) { - leftValid := s.IsValid(left) - rightValid := s.IsValid(right) - if !leftValid || !rightValid { - return 0, errors.INVALID_DATA_TYPE +func (s *DecimalDataType) Compare(left interface{}, right interface{}, validated bool) (int, error) { + if !validated { + leftValid := s.IsValid(left) + rightValid := s.IsValid(right) + if !leftValid || !rightValid { + return 0, errors.INVALID_DATA_TYPE + } } leftValue := s.GetValue(left).(float64) rightValue := s.GetValue(right).(float64) diff --git a/internal/datatype/int_data_type.go b/internal/datatype/int_data_type.go index 7ce08fb..4b7d75b 100644 --- a/internal/datatype/int_data_type.go +++ b/internal/datatype/int_data_type.go @@ -39,11 +39,13 @@ func (s *IntDataType) GetValue(value interface{}) interface{} { return res } -func (s *IntDataType) Compare(left interface{}, right interface{}) (int, error) { - leftValid := s.IsValid(left) - rightValid := s.IsValid(right) - if !leftValid || !rightValid { - return 0, errors.INVALID_DATA_TYPE +func (s *IntDataType) Compare(left interface{}, right interface{}, validated bool) (int, error) { + if !validated { + leftValid := s.IsValid(left) + rightValid := s.IsValid(right) + if !leftValid || !rightValid { + return 0, errors.INVALID_DATA_TYPE + } } leftValue := s.GetValue(left).(int) rightValue := s.GetValue(right).(int) diff --git a/internal/datatype/long_data_type.go b/internal/datatype/long_data_type.go index ff01099..113cda7 100644 --- a/internal/datatype/long_data_type.go +++ b/internal/datatype/long_data_type.go @@ -39,11 +39,13 @@ func (s *LongDataType) GetValue(value interface{}) interface{} { return res } -func (s *LongDataType) Compare(left interface{}, right interface{}) (int, error) { - leftValid := s.IsValid(left) - rightValid := s.IsValid(right) - if !leftValid || !rightValid { - return 0, errors.INVALID_DATA_TYPE +func (s *LongDataType) Compare(left interface{}, right interface{}, validated bool) (int, error) { + if !validated { + leftValid := s.IsValid(left) + rightValid := s.IsValid(right) + if !leftValid || !rightValid { + return 0, errors.INVALID_DATA_TYPE + } } leftValue := s.GetValue(left).(int64) rightValue := s.GetValue(right).(int64) diff --git a/internal/datatype/string_data_type.go b/internal/datatype/string_data_type.go index c5a904d..5d4dda7 100644 --- a/internal/datatype/string_data_type.go +++ b/internal/datatype/string_data_type.go @@ -26,11 +26,13 @@ func (s *StringDataType) GetValue(value interface{}) interface{} { return fmt.Sprintf("%v",value) } -func (s *StringDataType) Compare(left interface{}, right interface{}) (int, error) { - leftValid := s.IsValid(left) - rightValid := s.IsValid(right) - if !leftValid || !rightValid { - return 0, errors.INVALID_DATA_TYPE +func (s *StringDataType) Compare(left interface{}, right interface{}, validated bool) (int, error) { + if !validated { + leftValid := s.IsValid(left) + rightValid := s.IsValid(right) + if !leftValid || !rightValid { + return 0, errors.INVALID_DATA_TYPE + } } leftValue := s.GetValue(left).(string) rightValue := s.GetValue(right).(string) diff --git a/internal/datatype/version_data_type.go b/internal/datatype/version_data_type.go index 5e837f4..bdae1a0 100644 --- a/internal/datatype/version_data_type.go +++ b/internal/datatype/version_data_type.go @@ -36,11 +36,13 @@ func (s *VersionDataType) GetValue(value interface{}) interface{} { return res } -func (s *VersionDataType) Compare(left interface{}, right interface{}) (int, error) { - leftValid := s.IsValid(left) - rightValid := s.IsValid(right) - if !leftValid || !rightValid { - return 0, errors.INVALID_DATA_TYPE +func (s *VersionDataType) Compare(left interface{}, right interface{}, validated bool) (int, error) { + if !validated { + leftValid := s.IsValid(left) + rightValid := s.IsValid(right) + if !leftValid || !rightValid { + return 0, errors.INVALID_DATA_TYPE + } } leftValue := s.GetValue(left).(*version.Version) rightValue := s.GetValue(right).(*version.Version) diff --git a/internal/operator/abstract_operator.go b/internal/operator/abstract_operator.go index 7545d17..6c9d476 100644 --- a/internal/operator/abstract_operator.go +++ b/internal/operator/abstract_operator.go @@ -3,9 +3,13 @@ package operator import "github.com/sidhant92/bool-parser-go/pkg/constant" type AbstractOperator interface { - Evaluate(dataType constant.DataType, left interface{}, right ...interface{}) (bool, error) + Evaluate(containerDataType constant.ContainerDataType, dataType constant.DataType, validated bool, left interface{}, right ...interface{}) (bool, error) GetSymbol() string GetOperator() constant.Operator + + GetAllowedContainerTypes() []constant.ContainerDataType + + GetAllowedDataTypes() []constant.DataType } diff --git a/internal/operator/contains_all_operator.go b/internal/operator/contains_all_operator.go new file mode 100644 index 0000000..c9c23dc --- /dev/null +++ b/internal/operator/contains_all_operator.go @@ -0,0 +1,49 @@ +package operator + +import ( + "github.com/sidhant92/bool-parser-go/pkg/constant" + "reflect" +) + +type ContainsAllOperator struct { +} + +func (e *ContainsAllOperator) Evaluate(containerDataType constant.ContainerDataType, dataType constant.DataType, validated bool, left interface{}, right ...interface{}) (bool, error) { + var leftArray []interface{} + rv := reflect.ValueOf(left) + if rv.Kind() == reflect.Slice { + for i := 0; i < rv.Len(); i++ { + leftArray = append(leftArray, rv.Index(i).Interface()) + } + } + for _, value := range right { + res, err := GetOperator(constant.IN).Evaluate(constant.PRIMITIVE, dataType, validated, value, leftArray...) + if err != nil { + return false, err + } + if !res { + return false, nil + } + } + return true, nil +} + +func (e *ContainsAllOperator) GetSymbol() string { + return "CONTAINS_ALL" +} + +func (e *ContainsAllOperator) GetOperator() constant.Operator { + return constant.CONTAINS_ALL +} + +func (e *ContainsAllOperator) GetAllowedContainerTypes() []constant.ContainerDataType { + return []constant.ContainerDataType{constant.LIST} +} + +func (e *ContainsAllOperator) GetAllowedDataTypes() []constant.DataType { + return []constant.DataType{constant.STRING, constant.INTEGER, constant.LONG, constant.DECIMAL, constant.BOOLEAN, constant.VERSION} +} + +func NewContainsAllOperator() AbstractOperator { + return &ContainsAllOperator{} +} diff --git a/internal/operator/contains_any_operator.go b/internal/operator/contains_any_operator.go new file mode 100644 index 0000000..f5aeb85 --- /dev/null +++ b/internal/operator/contains_any_operator.go @@ -0,0 +1,49 @@ +package operator + +import ( + "github.com/sidhant92/bool-parser-go/pkg/constant" + "reflect" +) + +type ContainsAnyOperator struct { +} + +func (e *ContainsAnyOperator) Evaluate(containerDataType constant.ContainerDataType, dataType constant.DataType, validated bool, left interface{}, right ...interface{}) (bool, error) { + var leftArray []interface{} + rv := reflect.ValueOf(left) + if rv.Kind() == reflect.Slice { + for i := 0; i < rv.Len(); i++ { + leftArray = append(leftArray, rv.Index(i).Interface()) + } + } + for _, value := range right { + res, err := GetOperator(constant.IN).Evaluate(constant.PRIMITIVE, dataType, validated, value, leftArray...) + if err != nil { + return false, err + } + if res { + return true, nil + } + } + return false, nil +} + +func (e *ContainsAnyOperator) GetSymbol() string { + return "CONTAINS_ANY" +} + +func (e *ContainsAnyOperator) GetOperator() constant.Operator { + return constant.CONTAINS_ANY +} + +func (e *ContainsAnyOperator) GetAllowedContainerTypes() []constant.ContainerDataType { + return []constant.ContainerDataType{constant.LIST} +} + +func (e *ContainsAnyOperator) GetAllowedDataTypes() []constant.DataType { + return []constant.DataType{constant.STRING, constant.INTEGER, constant.LONG, constant.DECIMAL, constant.BOOLEAN, constant.VERSION} +} + +func NewContainsAnyOperator() AbstractOperator { + return &ContainsAnyOperator{} +} diff --git a/internal/operator/equals_operator.go b/internal/operator/equals_operator.go index d3c9e9f..e026312 100644 --- a/internal/operator/equals_operator.go +++ b/internal/operator/equals_operator.go @@ -8,23 +8,31 @@ import ( type EqualsOperator struct { } -func (e *EqualsOperator) Evaluate(dataType constant.DataType, left interface{}, right ...interface{}) (bool, error) { +func (e *EqualsOperator) Evaluate(containerDataType constant.ContainerDataType, dataType constant.DataType, validated bool, left interface{}, right ...interface{}) (bool, error) { dt := datatype.GetDataType(dataType) - res, err := dt.Compare(left, right[0]) + res, err := dt.Compare(left, right[0], validated) if err != nil { return false, err } return res == 0, nil } -func (e *EqualsOperator) GetSymbol() string { +func (e *EqualsOperator) GetSymbol() string { return "=" } -func (e *EqualsOperator) GetOperator() constant.Operator { +func (e *EqualsOperator) GetOperator() constant.Operator { return constant.EQUALS } +func (e *EqualsOperator) GetAllowedContainerTypes() []constant.ContainerDataType { + return []constant.ContainerDataType{constant.PRIMITIVE} +} + +func (e *EqualsOperator) GetAllowedDataTypes() []constant.DataType { + return []constant.DataType{constant.STRING, constant.INTEGER, constant.LONG, constant.DECIMAL, constant.BOOLEAN, constant.VERSION} +} + func NewEqualsOperator() AbstractOperator { return &EqualsOperator{} } diff --git a/internal/operator/greater_than_equal_operator.go b/internal/operator/greater_than_equal_operator.go index 02e1ed1..e1bc050 100644 --- a/internal/operator/greater_than_equal_operator.go +++ b/internal/operator/greater_than_equal_operator.go @@ -8,23 +8,31 @@ import ( type GreaterThanEqualOperator struct { } -func (e *GreaterThanEqualOperator) Evaluate(dataType constant.DataType, left interface{}, right ...interface{}) (bool, error) { +func (e *GreaterThanEqualOperator) Evaluate(containerDataType constant.ContainerDataType, dataType constant.DataType, validated bool, left interface{}, right ...interface{}) (bool, error) { dt := datatype.GetDataType(dataType) - res, err := dt.Compare(left, right[0]) + res, err := dt.Compare(left, right[0], validated) if err != nil { return false, err } return res >= 0, nil } -func (e *GreaterThanEqualOperator) GetSymbol() string { +func (e *GreaterThanEqualOperator) GetSymbol() string { return ">=" } -func (e *GreaterThanEqualOperator) GetOperator() constant.Operator { +func (e *GreaterThanEqualOperator) GetOperator() constant.Operator { return constant.GREATER_THAN_EQUAL } +func (e *GreaterThanEqualOperator) GetAllowedContainerTypes() []constant.ContainerDataType { + return []constant.ContainerDataType{constant.PRIMITIVE} +} + +func (e *GreaterThanEqualOperator) GetAllowedDataTypes() []constant.DataType { + return []constant.DataType{constant.STRING, constant.INTEGER, constant.LONG, constant.DECIMAL, constant.VERSION} +} + func NewGreaterThanEqualOperator() AbstractOperator { return &GreaterThanEqualOperator{} } diff --git a/internal/operator/greater_than_operator.go b/internal/operator/greater_than_operator.go index 45f2afa..94ee46c 100644 --- a/internal/operator/greater_than_operator.go +++ b/internal/operator/greater_than_operator.go @@ -8,9 +8,9 @@ import ( type GreaterThanOperator struct { } -func (e *GreaterThanOperator) Evaluate(dataType constant.DataType, left interface{}, right ...interface{}) (bool, error) { +func (e *GreaterThanOperator) Evaluate(containerDataType constant.ContainerDataType, dataType constant.DataType, validated bool, left interface{}, right ...interface{}) (bool, error) { dt := datatype.GetDataType(dataType) - res, err := dt.Compare(left, right[0]) + res, err := dt.Compare(left, right[0], validated) if err != nil { return false, err } @@ -25,6 +25,14 @@ func (e *GreaterThanOperator) GetOperator() constant.Operator { return constant.GREATER_THAN } +func (e *GreaterThanOperator) GetAllowedContainerTypes() []constant.ContainerDataType { + return []constant.ContainerDataType{constant.PRIMITIVE} +} + +func (e *GreaterThanOperator) GetAllowedDataTypes() []constant.DataType { + return []constant.DataType{constant.STRING, constant.INTEGER, constant.LONG, constant.DECIMAL, constant.VERSION} +} + func NewGreaterThanOperator() AbstractOperator { return &GreaterThanOperator{} } diff --git a/internal/operator/in_operator.go b/internal/operator/in_operator.go index e080da6..912991e 100644 --- a/internal/operator/in_operator.go +++ b/internal/operator/in_operator.go @@ -7,9 +7,9 @@ import ( type InOperator struct { } -func (e *InOperator) Evaluate(dataType constant.DataType, left interface{}, right ...interface{}) (bool, error) { +func (e *InOperator) Evaluate(containerDataType constant.ContainerDataType, dataType constant.DataType, validated bool, left interface{}, right ...interface{}) (bool, error) { for _, value := range right { - res, err := GetOperator(constant.EQUALS).Evaluate(dataType, left, value) + res, err := GetOperator(constant.EQUALS).Evaluate(containerDataType, dataType, validated, left, value) if err != nil { return false, err } @@ -28,6 +28,14 @@ func (e *InOperator) GetOperator() constant.Operator { return constant.IN } +func (e *InOperator) GetAllowedContainerTypes() []constant.ContainerDataType { + return []constant.ContainerDataType{constant.PRIMITIVE} +} + +func (e *InOperator) GetAllowedDataTypes() []constant.DataType { + return []constant.DataType{constant.STRING, constant.INTEGER, constant.LONG, constant.DECIMAL, constant.BOOLEAN, constant.VERSION} +} + func NewInOperator() AbstractOperator { return &InOperator{} } diff --git a/internal/operator/less_than_equal_operator.go b/internal/operator/less_than_equal_operator.go index ca5b6e1..d9ce04b 100644 --- a/internal/operator/less_than_equal_operator.go +++ b/internal/operator/less_than_equal_operator.go @@ -8,23 +8,31 @@ import ( type LessThanEqualOperator struct { } -func (e *LessThanEqualOperator) Evaluate(dataType constant.DataType, left interface{}, right ...interface{}) (bool, error) { +func (e *LessThanEqualOperator) Evaluate(containerDataType constant.ContainerDataType, dataType constant.DataType, validated bool, left interface{}, right ...interface{}) (bool, error) { dt := datatype.GetDataType(dataType) - res, err := dt.Compare(left, right[0]) + res, err := dt.Compare(left, right[0], validated) if err != nil { return false, err } return res <= 0, nil } -func (e *LessThanEqualOperator) GetSymbol() string { +func (e *LessThanEqualOperator) GetSymbol() string { return "<=" } -func (e *LessThanEqualOperator) GetOperator() constant.Operator { +func (e *LessThanEqualOperator) GetOperator() constant.Operator { return constant.LESS_THAN_EQUAL } +func (e *LessThanEqualOperator) GetAllowedContainerTypes() []constant.ContainerDataType { + return []constant.ContainerDataType{constant.PRIMITIVE} +} + +func (e *LessThanEqualOperator) GetAllowedDataTypes() []constant.DataType { + return []constant.DataType{constant.STRING, constant.INTEGER, constant.LONG, constant.DECIMAL, constant.VERSION} +} + func NewLessThanEqualOperator() AbstractOperator { return &LessThanEqualOperator{} } diff --git a/internal/operator/less_than_operator.go b/internal/operator/less_than_operator.go index 87bbdea..9106478 100644 --- a/internal/operator/less_than_operator.go +++ b/internal/operator/less_than_operator.go @@ -8,23 +8,31 @@ import ( type LessThanOperator struct { } -func (e *LessThanOperator) Evaluate(dataType constant.DataType, left interface{}, right ...interface{}) (bool, error) { +func (e *LessThanOperator) Evaluate(containerDataType constant.ContainerDataType, dataType constant.DataType, validated bool, left interface{}, right ...interface{}) (bool, error) { dt := datatype.GetDataType(dataType) - res, err := dt.Compare(left, right[0]) + res, err := dt.Compare(left, right[0], validated) if err != nil { return false, err } return res < 0, nil } -func (e *LessThanOperator) GetSymbol() string { +func (e *LessThanOperator) GetSymbol() string { return "<" } -func (e *LessThanOperator) GetOperator() constant.Operator { +func (e *LessThanOperator) GetOperator() constant.Operator { return constant.LESS_THAN } +func (e *LessThanOperator) GetAllowedContainerTypes() []constant.ContainerDataType { + return []constant.ContainerDataType{constant.PRIMITIVE} +} + +func (e *LessThanOperator) GetAllowedDataTypes() []constant.DataType { + return []constant.DataType{constant.STRING, constant.INTEGER, constant.LONG, constant.DECIMAL, constant.VERSION} +} + func NewLessThanOperator() AbstractOperator { return &LessThanOperator{} } diff --git a/internal/operator/not_equals_operator.go b/internal/operator/not_equals_operator.go index d202b2b..9734e86 100644 --- a/internal/operator/not_equals_operator.go +++ b/internal/operator/not_equals_operator.go @@ -7,9 +7,9 @@ import ( type NotEqualsOperator struct { } -func (e *NotEqualsOperator) Evaluate(dataType constant.DataType, left interface{}, right ...interface{}) (bool, error) { +func (e *NotEqualsOperator) Evaluate(containerDataType constant.ContainerDataType, dataType constant.DataType, validated bool, left interface{}, right ...interface{}) (bool, error) { eq := GetOperator(constant.EQUALS) - res, err := eq.Evaluate(dataType, left, right[0]) + res, err := eq.Evaluate(containerDataType, dataType, validated, left, right[0]) if err != nil { return false, err } @@ -24,6 +24,14 @@ func (e *NotEqualsOperator) GetOperator() constant.Operator { return constant.NOT_EQUAL } +func (e *NotEqualsOperator) GetAllowedContainerTypes() []constant.ContainerDataType { + return []constant.ContainerDataType{constant.PRIMITIVE} +} + +func (e *NotEqualsOperator) GetAllowedDataTypes() []constant.DataType { + return []constant.DataType{constant.STRING, constant.INTEGER, constant.LONG, constant.DECIMAL, constant.BOOLEAN, constant.VERSION} +} + func NewNotEqualsOperator() AbstractOperator { return &NotEqualsOperator{} } diff --git a/internal/operator/operator_factory.go b/internal/operator/operator_factory.go index fd35217..b3a2605 100644 --- a/internal/operator/operator_factory.go +++ b/internal/operator/operator_factory.go @@ -10,6 +10,8 @@ var operatorMap = map[constant.Operator]AbstractOperator{ constant.LESS_THAN: NewLessThanOperator(), constant.LESS_THAN_EQUAL: NewLessThanEqualOperator(), constant.IN: NewInOperator(), + constant.CONTAINS_ANY: NewContainsAnyOperator(), + constant.CONTAINS_ALL: NewContainsAllOperator(), } func GetOperator(operator constant.Operator) AbstractOperator { diff --git a/internal/parser/antlr/antlr_parser.go b/internal/parser/antlr/antlr_parser.go index 18de473..12ef6b0 100644 --- a/internal/parser/antlr/antlr_parser.go +++ b/internal/parser/antlr/antlr_parser.go @@ -2,7 +2,7 @@ package parser import ( "errors" - "github.com/antlr/antlr4/runtime/Go/antlr/v4" + "github.com/antlr4-go/antlr/v4" lru "github.com/hashicorp/golang-lru/v2" "github.com/sidhant92/bool-parser-go/internal/parser/antlr/lib" "github.com/sidhant92/bool-parser-go/pkg/domain" @@ -10,22 +10,22 @@ import ( ) type ANTLRParser struct { - UseCache bool - cache *lru.Cache[string, domain.Node] + UseCache bool + cache *lru.Cache[string, domain.Node] } func Default() *ANTLRParser { return &ANTLRParser{ - UseCache: false, - cache: nil, + UseCache: false, + cache: nil, } } func Cached(size int) *ANTLRParser { cache, _ := lru.New[string, domain.Node](size) return &ANTLRParser{ - UseCache: true, - cache: cache, + UseCache: true, + cache: cache, } } diff --git a/internal/parser/antlr/antlr_parser_test.go b/internal/parser/antlr/antlr_parser_test.go index 152863e..7f18b8b 100644 --- a/internal/parser/antlr/antlr_parser_test.go +++ b/internal/parser/antlr/antlr_parser_test.go @@ -263,3 +263,21 @@ func TestInvalidNotExpression(t *testing.T) { _, err := parser.Parse("not a > 5") assert.NotNil(t, err) } + +func TestContainsAny(t *testing.T) { + res, _ := parser.Parse("a contains_any (1,2,3)") + assert.Equal(t, res.GetNodeType(), constant.ARRAY_NODE) + assert.Equal(t, res.(domain.ArrayNode).Field, "a") + assert.Equal(t, res.(domain.ArrayNode).Operator, constant.CONTAINS_ANY) + assert.Equal(t, len(res.(domain.ArrayNode).Items), 3) + assert.Equal(t, res.(domain.ArrayNode).Items[0].Value, 1) +} + +func TestContainsAll(t *testing.T) { + res, _ := parser.Parse("a CONTAINS_ALL (\"a\", \"b\")") + assert.Equal(t, res.GetNodeType(), constant.ARRAY_NODE) + assert.Equal(t, res.(domain.ArrayNode).Field, "a") + assert.Equal(t, res.(domain.ArrayNode).Operator, constant.CONTAINS_ALL) + assert.Equal(t, len(res.(domain.ArrayNode).Items), 2) + assert.Equal(t, res.(domain.ArrayNode).Items[0].Value, "a") +} diff --git a/internal/parser/antlr/boolean_expression.g4 b/internal/parser/antlr/boolean_expression.g4 index ebebc95..3c2bbba 100644 --- a/internal/parser/antlr/boolean_expression.g4 +++ b/internal/parser/antlr/boolean_expression.g4 @@ -10,8 +10,9 @@ expression | left=expression op=comparator right=expression #comparatorExpression | left=expression op=binary right=expression #binaryExpression | types #typesExpression - | field=WORD lower=numericTypes TO upper=numericTypes #toExpression - | field=WORD IN data=wordlist #inExpression + | (field=WORD)? lower=numericTypes TO upper=numericTypes #toExpression + | (field=WORD)? (not=NOT)? IN data=wordlist #inExpression + | (field=WORD)? op=arrayOperators data=wordlist #arrayExpression ; comparator @@ -23,6 +24,10 @@ comparator : LPAREN WS* first=types WS* (',' WS* rest=types WS*)* RPAREN ; + arrayOperators + : CONTAINS_ANY | CONTAINS_ALL + ; + numericTypes : INTEGER | DECIMAL @@ -49,6 +54,8 @@ OR : 'OR' | 'or' | '||'; NOT : 'NOT' | 'not'; TRUE : 'TRUE' | 'true'; FALSE : 'FALSE' | 'false'; +CONTAINS_ALL : 'CONTAINS_ALL' | 'contains_all'; +CONTAINS_ANY : 'CONTAINS_ANY' | 'contains_any'; NE : '!='; GT : '>' ; GE : '>=' ; diff --git a/internal/parser/antlr/lib/booleanexpression_lexer.go b/internal/parser/antlr/lib/booleanexpression_lexer.go index b4463c8..46c3ff5 100644 --- a/internal/parser/antlr/lib/booleanexpression_lexer.go +++ b/internal/parser/antlr/lib/booleanexpression_lexer.go @@ -1,13 +1,12 @@ -// Code generated from java-escape by ANTLR 4.11.1. DO NOT EDIT. +// Code generated from /Users/sid/Desktop/filter1/BooleanExpression.g4 by ANTLR 4.13.1. DO NOT EDIT. package lib import ( "fmt" + "github.com/antlr4-go/antlr/v4" "sync" "unicode" - - "github.com/antlr/antlr4/runtime/Go/antlr/v4" ) // Suppress unused import error @@ -22,128 +21,154 @@ type BooleanExpressionLexer struct { // TODO: EOF string } -var booleanexpressionlexerLexerStaticData struct { +var BooleanExpressionLexerLexerStaticData struct { once sync.Once serializedATN []int32 - channelNames []string - modeNames []string - literalNames []string - symbolicNames []string - ruleNames []string - predictionContextCache *antlr.PredictionContextCache + ChannelNames []string + ModeNames []string + LiteralNames []string + SymbolicNames []string + RuleNames []string + PredictionContextCache *antlr.PredictionContextCache atn *antlr.ATN decisionToDFA []*antlr.DFA } func booleanexpressionlexerLexerInit() { - staticData := &booleanexpressionlexerLexerStaticData - staticData.channelNames = []string{ + staticData := &BooleanExpressionLexerLexerStaticData + staticData.ChannelNames = []string{ "DEFAULT_TOKEN_CHANNEL", "HIDDEN", } - staticData.modeNames = []string{ + staticData.ModeNames = []string{ "DEFAULT_MODE", } - staticData.literalNames = []string{ - "", "','", "", "", "", "", "", "", "", "'!='", "'>'", "'>='", "'<'", - "'<='", "'='", "'('", "')'", + staticData.LiteralNames = []string{ + "", "','", "", "", "", "", "", "", "", "", "", "'!='", "'>'", "'>='", + "'<'", "'<='", "'='", "'('", "')'", } - staticData.symbolicNames = []string{ - "", "", "IN", "TO", "AND", "OR", "NOT", "TRUE", "FALSE", "NE", "GT", - "GE", "LT", "LE", "EQ", "LPAREN", "RPAREN", "DECIMAL", "APP_VERSION", - "INTEGER", "WS", "WORD", "ALPHANUMERIC", "SQ", "DQ", + staticData.SymbolicNames = []string{ + "", "", "IN", "TO", "AND", "OR", "NOT", "TRUE", "FALSE", "CONTAINS_ALL", + "CONTAINS_ANY", "NE", "GT", "GE", "LT", "LE", "EQ", "LPAREN", "RPAREN", + "DECIMAL", "APP_VERSION", "INTEGER", "WS", "WORD", "ALPHANUMERIC", "SQ", + "DQ", } - staticData.ruleNames = []string{ - "T__0", "IN", "TO", "AND", "OR", "NOT", "TRUE", "FALSE", "NE", "GT", - "GE", "LT", "LE", "EQ", "LPAREN", "RPAREN", "DECIMAL", "APP_VERSION", - "INTEGER", "WS", "WORD", "ALPHANUMERIC", "SQ", "DQ", + staticData.RuleNames = []string{ + "T__0", "IN", "TO", "AND", "OR", "NOT", "TRUE", "FALSE", "CONTAINS_ALL", + "CONTAINS_ANY", "NE", "GT", "GE", "LT", "LE", "EQ", "LPAREN", "RPAREN", + "DECIMAL", "APP_VERSION", "INTEGER", "WS", "WORD", "ALPHANUMERIC", "SQ", + "DQ", } - staticData.predictionContextCache = antlr.NewPredictionContextCache() + staticData.PredictionContextCache = antlr.NewPredictionContextCache() staticData.serializedATN = []int32{ - 4, 0, 24, 188, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, + 4, 0, 26, 244, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, - 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 3, 1, 56, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 62, 8, 2, 1, 3, - 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 72, 8, 3, 1, 4, 1, 4, 1, - 4, 1, 4, 1, 4, 1, 4, 3, 4, 80, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, - 3, 5, 88, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 98, - 8, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, - 110, 8, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 11, 1, - 11, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, - 4, 16, 132, 8, 16, 11, 16, 12, 16, 133, 1, 16, 1, 16, 4, 16, 138, 8, 16, - 11, 16, 12, 16, 139, 1, 17, 1, 17, 1, 17, 4, 17, 145, 8, 17, 11, 17, 12, - 17, 146, 1, 18, 4, 18, 150, 8, 18, 11, 18, 12, 18, 151, 1, 19, 4, 19, 155, - 8, 19, 11, 19, 12, 19, 156, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 4, - 20, 165, 8, 20, 11, 20, 12, 20, 166, 1, 21, 1, 21, 1, 22, 1, 22, 5, 22, - 173, 8, 22, 10, 22, 12, 22, 176, 9, 22, 1, 22, 1, 22, 1, 23, 1, 23, 5, - 23, 182, 8, 23, 10, 23, 12, 23, 185, 9, 23, 1, 23, 1, 23, 2, 174, 183, - 0, 24, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, + 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, + 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 60, 8, 1, 1, 2, 1, 2, 1, 2, 1, + 2, 3, 2, 66, 8, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, + 76, 8, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 84, 8, 4, 1, 5, 1, + 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 92, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, + 1, 6, 1, 6, 1, 6, 3, 6, 102, 8, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, + 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 114, 8, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, + 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, + 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 3, 8, 140, 8, 8, 1, 9, 1, 9, + 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, + 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 3, 9, 166, + 8, 9, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 13, 1, + 13, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, + 4, 18, 188, 8, 18, 11, 18, 12, 18, 189, 1, 18, 1, 18, 4, 18, 194, 8, 18, + 11, 18, 12, 18, 195, 1, 19, 1, 19, 1, 19, 4, 19, 201, 8, 19, 11, 19, 12, + 19, 202, 1, 20, 4, 20, 206, 8, 20, 11, 20, 12, 20, 207, 1, 21, 4, 21, 211, + 8, 21, 11, 21, 12, 21, 212, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 1, 22, 4, + 22, 221, 8, 22, 11, 22, 12, 22, 222, 1, 23, 1, 23, 1, 24, 1, 24, 5, 24, + 229, 8, 24, 10, 24, 12, 24, 232, 9, 24, 1, 24, 1, 24, 1, 25, 1, 25, 5, + 25, 238, 8, 25, 10, 25, 12, 25, 241, 9, 25, 1, 25, 1, 25, 2, 230, 239, + 0, 26, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, - 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 1, 0, 4, 1, 0, 48, 57, 3, 0, 9, - 10, 12, 13, 32, 32, 2, 0, 45, 46, 95, 95, 3, 0, 48, 57, 65, 90, 97, 122, - 207, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, - 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, - 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, - 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, - 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, - 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, - 0, 0, 47, 1, 0, 0, 0, 1, 49, 1, 0, 0, 0, 3, 55, 1, 0, 0, 0, 5, 61, 1, 0, - 0, 0, 7, 71, 1, 0, 0, 0, 9, 79, 1, 0, 0, 0, 11, 87, 1, 0, 0, 0, 13, 97, - 1, 0, 0, 0, 15, 109, 1, 0, 0, 0, 17, 111, 1, 0, 0, 0, 19, 114, 1, 0, 0, - 0, 21, 116, 1, 0, 0, 0, 23, 119, 1, 0, 0, 0, 25, 121, 1, 0, 0, 0, 27, 124, - 1, 0, 0, 0, 29, 126, 1, 0, 0, 0, 31, 128, 1, 0, 0, 0, 33, 131, 1, 0, 0, - 0, 35, 141, 1, 0, 0, 0, 37, 149, 1, 0, 0, 0, 39, 154, 1, 0, 0, 0, 41, 164, - 1, 0, 0, 0, 43, 168, 1, 0, 0, 0, 45, 170, 1, 0, 0, 0, 47, 179, 1, 0, 0, - 0, 49, 50, 5, 44, 0, 0, 50, 2, 1, 0, 0, 0, 51, 52, 5, 73, 0, 0, 52, 56, - 5, 78, 0, 0, 53, 54, 5, 105, 0, 0, 54, 56, 5, 110, 0, 0, 55, 51, 1, 0, - 0, 0, 55, 53, 1, 0, 0, 0, 56, 4, 1, 0, 0, 0, 57, 58, 5, 84, 0, 0, 58, 62, - 5, 79, 0, 0, 59, 60, 5, 116, 0, 0, 60, 62, 5, 111, 0, 0, 61, 57, 1, 0, - 0, 0, 61, 59, 1, 0, 0, 0, 62, 6, 1, 0, 0, 0, 63, 64, 5, 65, 0, 0, 64, 65, - 5, 78, 0, 0, 65, 72, 5, 68, 0, 0, 66, 67, 5, 97, 0, 0, 67, 68, 5, 110, - 0, 0, 68, 72, 5, 100, 0, 0, 69, 70, 5, 38, 0, 0, 70, 72, 5, 38, 0, 0, 71, - 63, 1, 0, 0, 0, 71, 66, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 72, 8, 1, 0, 0, - 0, 73, 74, 5, 79, 0, 0, 74, 80, 5, 82, 0, 0, 75, 76, 5, 111, 0, 0, 76, - 80, 5, 114, 0, 0, 77, 78, 5, 124, 0, 0, 78, 80, 5, 124, 0, 0, 79, 73, 1, - 0, 0, 0, 79, 75, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 80, 10, 1, 0, 0, 0, 81, - 82, 5, 78, 0, 0, 82, 83, 5, 79, 0, 0, 83, 88, 5, 84, 0, 0, 84, 85, 5, 110, - 0, 0, 85, 86, 5, 111, 0, 0, 86, 88, 5, 116, 0, 0, 87, 81, 1, 0, 0, 0, 87, - 84, 1, 0, 0, 0, 88, 12, 1, 0, 0, 0, 89, 90, 5, 84, 0, 0, 90, 91, 5, 82, - 0, 0, 91, 92, 5, 85, 0, 0, 92, 98, 5, 69, 0, 0, 93, 94, 5, 116, 0, 0, 94, - 95, 5, 114, 0, 0, 95, 96, 5, 117, 0, 0, 96, 98, 5, 101, 0, 0, 97, 89, 1, - 0, 0, 0, 97, 93, 1, 0, 0, 0, 98, 14, 1, 0, 0, 0, 99, 100, 5, 70, 0, 0, - 100, 101, 5, 65, 0, 0, 101, 102, 5, 76, 0, 0, 102, 103, 5, 83, 0, 0, 103, - 110, 5, 69, 0, 0, 104, 105, 5, 102, 0, 0, 105, 106, 5, 97, 0, 0, 106, 107, - 5, 108, 0, 0, 107, 108, 5, 115, 0, 0, 108, 110, 5, 101, 0, 0, 109, 99, - 1, 0, 0, 0, 109, 104, 1, 0, 0, 0, 110, 16, 1, 0, 0, 0, 111, 112, 5, 33, - 0, 0, 112, 113, 5, 61, 0, 0, 113, 18, 1, 0, 0, 0, 114, 115, 5, 62, 0, 0, - 115, 20, 1, 0, 0, 0, 116, 117, 5, 62, 0, 0, 117, 118, 5, 61, 0, 0, 118, - 22, 1, 0, 0, 0, 119, 120, 5, 60, 0, 0, 120, 24, 1, 0, 0, 0, 121, 122, 5, - 60, 0, 0, 122, 123, 5, 61, 0, 0, 123, 26, 1, 0, 0, 0, 124, 125, 5, 61, - 0, 0, 125, 28, 1, 0, 0, 0, 126, 127, 5, 40, 0, 0, 127, 30, 1, 0, 0, 0, - 128, 129, 5, 41, 0, 0, 129, 32, 1, 0, 0, 0, 130, 132, 7, 0, 0, 0, 131, - 130, 1, 0, 0, 0, 132, 133, 1, 0, 0, 0, 133, 131, 1, 0, 0, 0, 133, 134, - 1, 0, 0, 0, 134, 135, 1, 0, 0, 0, 135, 137, 5, 46, 0, 0, 136, 138, 7, 0, - 0, 0, 137, 136, 1, 0, 0, 0, 138, 139, 1, 0, 0, 0, 139, 137, 1, 0, 0, 0, - 139, 140, 1, 0, 0, 0, 140, 34, 1, 0, 0, 0, 141, 144, 7, 0, 0, 0, 142, 143, - 5, 46, 0, 0, 143, 145, 3, 37, 18, 0, 144, 142, 1, 0, 0, 0, 145, 146, 1, - 0, 0, 0, 146, 144, 1, 0, 0, 0, 146, 147, 1, 0, 0, 0, 147, 36, 1, 0, 0, - 0, 148, 150, 7, 0, 0, 0, 149, 148, 1, 0, 0, 0, 150, 151, 1, 0, 0, 0, 151, - 149, 1, 0, 0, 0, 151, 152, 1, 0, 0, 0, 152, 38, 1, 0, 0, 0, 153, 155, 7, - 1, 0, 0, 154, 153, 1, 0, 0, 0, 155, 156, 1, 0, 0, 0, 156, 154, 1, 0, 0, - 0, 156, 157, 1, 0, 0, 0, 157, 158, 1, 0, 0, 0, 158, 159, 6, 19, 0, 0, 159, - 40, 1, 0, 0, 0, 160, 165, 3, 43, 21, 0, 161, 165, 7, 2, 0, 0, 162, 165, - 3, 45, 22, 0, 163, 165, 3, 47, 23, 0, 164, 160, 1, 0, 0, 0, 164, 161, 1, - 0, 0, 0, 164, 162, 1, 0, 0, 0, 164, 163, 1, 0, 0, 0, 165, 166, 1, 0, 0, - 0, 166, 164, 1, 0, 0, 0, 166, 167, 1, 0, 0, 0, 167, 42, 1, 0, 0, 0, 168, - 169, 7, 3, 0, 0, 169, 44, 1, 0, 0, 0, 170, 174, 5, 39, 0, 0, 171, 173, - 9, 0, 0, 0, 172, 171, 1, 0, 0, 0, 173, 176, 1, 0, 0, 0, 174, 175, 1, 0, - 0, 0, 174, 172, 1, 0, 0, 0, 175, 177, 1, 0, 0, 0, 176, 174, 1, 0, 0, 0, - 177, 178, 5, 39, 0, 0, 178, 46, 1, 0, 0, 0, 179, 183, 5, 34, 0, 0, 180, - 182, 9, 0, 0, 0, 181, 180, 1, 0, 0, 0, 182, 185, 1, 0, 0, 0, 183, 184, - 1, 0, 0, 0, 183, 181, 1, 0, 0, 0, 184, 186, 1, 0, 0, 0, 185, 183, 1, 0, - 0, 0, 186, 187, 5, 34, 0, 0, 187, 48, 1, 0, 0, 0, 17, 0, 55, 61, 71, 79, - 87, 97, 109, 133, 139, 146, 151, 156, 164, 166, 174, 183, 1, 6, 0, 0, + 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 1, 0, 4, 1, 0, + 48, 57, 3, 0, 9, 10, 12, 13, 32, 32, 2, 0, 45, 46, 95, 95, 3, 0, 48, 57, + 65, 90, 97, 122, 265, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, + 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, + 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, + 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, + 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, + 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, + 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, + 0, 1, 53, 1, 0, 0, 0, 3, 59, 1, 0, 0, 0, 5, 65, 1, 0, 0, 0, 7, 75, 1, 0, + 0, 0, 9, 83, 1, 0, 0, 0, 11, 91, 1, 0, 0, 0, 13, 101, 1, 0, 0, 0, 15, 113, + 1, 0, 0, 0, 17, 139, 1, 0, 0, 0, 19, 165, 1, 0, 0, 0, 21, 167, 1, 0, 0, + 0, 23, 170, 1, 0, 0, 0, 25, 172, 1, 0, 0, 0, 27, 175, 1, 0, 0, 0, 29, 177, + 1, 0, 0, 0, 31, 180, 1, 0, 0, 0, 33, 182, 1, 0, 0, 0, 35, 184, 1, 0, 0, + 0, 37, 187, 1, 0, 0, 0, 39, 197, 1, 0, 0, 0, 41, 205, 1, 0, 0, 0, 43, 210, + 1, 0, 0, 0, 45, 220, 1, 0, 0, 0, 47, 224, 1, 0, 0, 0, 49, 226, 1, 0, 0, + 0, 51, 235, 1, 0, 0, 0, 53, 54, 5, 44, 0, 0, 54, 2, 1, 0, 0, 0, 55, 56, + 5, 73, 0, 0, 56, 60, 5, 78, 0, 0, 57, 58, 5, 105, 0, 0, 58, 60, 5, 110, + 0, 0, 59, 55, 1, 0, 0, 0, 59, 57, 1, 0, 0, 0, 60, 4, 1, 0, 0, 0, 61, 62, + 5, 84, 0, 0, 62, 66, 5, 79, 0, 0, 63, 64, 5, 116, 0, 0, 64, 66, 5, 111, + 0, 0, 65, 61, 1, 0, 0, 0, 65, 63, 1, 0, 0, 0, 66, 6, 1, 0, 0, 0, 67, 68, + 5, 65, 0, 0, 68, 69, 5, 78, 0, 0, 69, 76, 5, 68, 0, 0, 70, 71, 5, 97, 0, + 0, 71, 72, 5, 110, 0, 0, 72, 76, 5, 100, 0, 0, 73, 74, 5, 38, 0, 0, 74, + 76, 5, 38, 0, 0, 75, 67, 1, 0, 0, 0, 75, 70, 1, 0, 0, 0, 75, 73, 1, 0, + 0, 0, 76, 8, 1, 0, 0, 0, 77, 78, 5, 79, 0, 0, 78, 84, 5, 82, 0, 0, 79, + 80, 5, 111, 0, 0, 80, 84, 5, 114, 0, 0, 81, 82, 5, 124, 0, 0, 82, 84, 5, + 124, 0, 0, 83, 77, 1, 0, 0, 0, 83, 79, 1, 0, 0, 0, 83, 81, 1, 0, 0, 0, + 84, 10, 1, 0, 0, 0, 85, 86, 5, 78, 0, 0, 86, 87, 5, 79, 0, 0, 87, 92, 5, + 84, 0, 0, 88, 89, 5, 110, 0, 0, 89, 90, 5, 111, 0, 0, 90, 92, 5, 116, 0, + 0, 91, 85, 1, 0, 0, 0, 91, 88, 1, 0, 0, 0, 92, 12, 1, 0, 0, 0, 93, 94, + 5, 84, 0, 0, 94, 95, 5, 82, 0, 0, 95, 96, 5, 85, 0, 0, 96, 102, 5, 69, + 0, 0, 97, 98, 5, 116, 0, 0, 98, 99, 5, 114, 0, 0, 99, 100, 5, 117, 0, 0, + 100, 102, 5, 101, 0, 0, 101, 93, 1, 0, 0, 0, 101, 97, 1, 0, 0, 0, 102, + 14, 1, 0, 0, 0, 103, 104, 5, 70, 0, 0, 104, 105, 5, 65, 0, 0, 105, 106, + 5, 76, 0, 0, 106, 107, 5, 83, 0, 0, 107, 114, 5, 69, 0, 0, 108, 109, 5, + 102, 0, 0, 109, 110, 5, 97, 0, 0, 110, 111, 5, 108, 0, 0, 111, 112, 5, + 115, 0, 0, 112, 114, 5, 101, 0, 0, 113, 103, 1, 0, 0, 0, 113, 108, 1, 0, + 0, 0, 114, 16, 1, 0, 0, 0, 115, 116, 5, 67, 0, 0, 116, 117, 5, 79, 0, 0, + 117, 118, 5, 78, 0, 0, 118, 119, 5, 84, 0, 0, 119, 120, 5, 65, 0, 0, 120, + 121, 5, 73, 0, 0, 121, 122, 5, 78, 0, 0, 122, 123, 5, 83, 0, 0, 123, 124, + 5, 95, 0, 0, 124, 125, 5, 65, 0, 0, 125, 126, 5, 76, 0, 0, 126, 140, 5, + 76, 0, 0, 127, 128, 5, 99, 0, 0, 128, 129, 5, 111, 0, 0, 129, 130, 5, 110, + 0, 0, 130, 131, 5, 116, 0, 0, 131, 132, 5, 97, 0, 0, 132, 133, 5, 105, + 0, 0, 133, 134, 5, 110, 0, 0, 134, 135, 5, 115, 0, 0, 135, 136, 5, 95, + 0, 0, 136, 137, 5, 97, 0, 0, 137, 138, 5, 108, 0, 0, 138, 140, 5, 108, + 0, 0, 139, 115, 1, 0, 0, 0, 139, 127, 1, 0, 0, 0, 140, 18, 1, 0, 0, 0, + 141, 142, 5, 67, 0, 0, 142, 143, 5, 79, 0, 0, 143, 144, 5, 78, 0, 0, 144, + 145, 5, 84, 0, 0, 145, 146, 5, 65, 0, 0, 146, 147, 5, 73, 0, 0, 147, 148, + 5, 78, 0, 0, 148, 149, 5, 83, 0, 0, 149, 150, 5, 95, 0, 0, 150, 151, 5, + 65, 0, 0, 151, 152, 5, 78, 0, 0, 152, 166, 5, 89, 0, 0, 153, 154, 5, 99, + 0, 0, 154, 155, 5, 111, 0, 0, 155, 156, 5, 110, 0, 0, 156, 157, 5, 116, + 0, 0, 157, 158, 5, 97, 0, 0, 158, 159, 5, 105, 0, 0, 159, 160, 5, 110, + 0, 0, 160, 161, 5, 115, 0, 0, 161, 162, 5, 95, 0, 0, 162, 163, 5, 97, 0, + 0, 163, 164, 5, 110, 0, 0, 164, 166, 5, 121, 0, 0, 165, 141, 1, 0, 0, 0, + 165, 153, 1, 0, 0, 0, 166, 20, 1, 0, 0, 0, 167, 168, 5, 33, 0, 0, 168, + 169, 5, 61, 0, 0, 169, 22, 1, 0, 0, 0, 170, 171, 5, 62, 0, 0, 171, 24, + 1, 0, 0, 0, 172, 173, 5, 62, 0, 0, 173, 174, 5, 61, 0, 0, 174, 26, 1, 0, + 0, 0, 175, 176, 5, 60, 0, 0, 176, 28, 1, 0, 0, 0, 177, 178, 5, 60, 0, 0, + 178, 179, 5, 61, 0, 0, 179, 30, 1, 0, 0, 0, 180, 181, 5, 61, 0, 0, 181, + 32, 1, 0, 0, 0, 182, 183, 5, 40, 0, 0, 183, 34, 1, 0, 0, 0, 184, 185, 5, + 41, 0, 0, 185, 36, 1, 0, 0, 0, 186, 188, 7, 0, 0, 0, 187, 186, 1, 0, 0, + 0, 188, 189, 1, 0, 0, 0, 189, 187, 1, 0, 0, 0, 189, 190, 1, 0, 0, 0, 190, + 191, 1, 0, 0, 0, 191, 193, 5, 46, 0, 0, 192, 194, 7, 0, 0, 0, 193, 192, + 1, 0, 0, 0, 194, 195, 1, 0, 0, 0, 195, 193, 1, 0, 0, 0, 195, 196, 1, 0, + 0, 0, 196, 38, 1, 0, 0, 0, 197, 200, 7, 0, 0, 0, 198, 199, 5, 46, 0, 0, + 199, 201, 3, 41, 20, 0, 200, 198, 1, 0, 0, 0, 201, 202, 1, 0, 0, 0, 202, + 200, 1, 0, 0, 0, 202, 203, 1, 0, 0, 0, 203, 40, 1, 0, 0, 0, 204, 206, 7, + 0, 0, 0, 205, 204, 1, 0, 0, 0, 206, 207, 1, 0, 0, 0, 207, 205, 1, 0, 0, + 0, 207, 208, 1, 0, 0, 0, 208, 42, 1, 0, 0, 0, 209, 211, 7, 1, 0, 0, 210, + 209, 1, 0, 0, 0, 211, 212, 1, 0, 0, 0, 212, 210, 1, 0, 0, 0, 212, 213, + 1, 0, 0, 0, 213, 214, 1, 0, 0, 0, 214, 215, 6, 21, 0, 0, 215, 44, 1, 0, + 0, 0, 216, 221, 3, 47, 23, 0, 217, 221, 7, 2, 0, 0, 218, 221, 3, 49, 24, + 0, 219, 221, 3, 51, 25, 0, 220, 216, 1, 0, 0, 0, 220, 217, 1, 0, 0, 0, + 220, 218, 1, 0, 0, 0, 220, 219, 1, 0, 0, 0, 221, 222, 1, 0, 0, 0, 222, + 220, 1, 0, 0, 0, 222, 223, 1, 0, 0, 0, 223, 46, 1, 0, 0, 0, 224, 225, 7, + 3, 0, 0, 225, 48, 1, 0, 0, 0, 226, 230, 5, 39, 0, 0, 227, 229, 9, 0, 0, + 0, 228, 227, 1, 0, 0, 0, 229, 232, 1, 0, 0, 0, 230, 231, 1, 0, 0, 0, 230, + 228, 1, 0, 0, 0, 231, 233, 1, 0, 0, 0, 232, 230, 1, 0, 0, 0, 233, 234, + 5, 39, 0, 0, 234, 50, 1, 0, 0, 0, 235, 239, 5, 34, 0, 0, 236, 238, 9, 0, + 0, 0, 237, 236, 1, 0, 0, 0, 238, 241, 1, 0, 0, 0, 239, 240, 1, 0, 0, 0, + 239, 237, 1, 0, 0, 0, 240, 242, 1, 0, 0, 0, 241, 239, 1, 0, 0, 0, 242, + 243, 5, 34, 0, 0, 243, 52, 1, 0, 0, 0, 19, 0, 59, 65, 75, 83, 91, 101, + 113, 139, 165, 189, 195, 202, 207, 212, 220, 222, 230, 239, 1, 6, 0, 0, } deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) @@ -160,7 +185,7 @@ func booleanexpressionlexerLexerInit() { // NewBooleanExpressionLexer(). You can call this function if you wish to initialize the static state ahead // of time. func BooleanExpressionLexerInit() { - staticData := &booleanexpressionlexerLexerStaticData + staticData := &BooleanExpressionLexerLexerStaticData staticData.once.Do(booleanexpressionlexerLexerInit) } @@ -169,13 +194,13 @@ func NewBooleanExpressionLexer(input antlr.CharStream) *BooleanExpressionLexer { BooleanExpressionLexerInit() l := new(BooleanExpressionLexer) l.BaseLexer = antlr.NewBaseLexer(input) - staticData := &booleanexpressionlexerLexerStaticData - l.Interpreter = antlr.NewLexerATNSimulator(l, staticData.atn, staticData.decisionToDFA, staticData.predictionContextCache) - l.channelNames = staticData.channelNames - l.modeNames = staticData.modeNames - l.RuleNames = staticData.ruleNames - l.LiteralNames = staticData.literalNames - l.SymbolicNames = staticData.symbolicNames + staticData := &BooleanExpressionLexerLexerStaticData + l.Interpreter = antlr.NewLexerATNSimulator(l, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache) + l.channelNames = staticData.ChannelNames + l.modeNames = staticData.ModeNames + l.RuleNames = staticData.RuleNames + l.LiteralNames = staticData.LiteralNames + l.SymbolicNames = staticData.SymbolicNames l.GrammarFileName = "BooleanExpression.g4" // TODO: l.EOF = antlr.TokenEOF @@ -192,20 +217,22 @@ const ( BooleanExpressionLexerNOT = 6 BooleanExpressionLexerTRUE = 7 BooleanExpressionLexerFALSE = 8 - BooleanExpressionLexerNE = 9 - BooleanExpressionLexerGT = 10 - BooleanExpressionLexerGE = 11 - BooleanExpressionLexerLT = 12 - BooleanExpressionLexerLE = 13 - BooleanExpressionLexerEQ = 14 - BooleanExpressionLexerLPAREN = 15 - BooleanExpressionLexerRPAREN = 16 - BooleanExpressionLexerDECIMAL = 17 - BooleanExpressionLexerAPP_VERSION = 18 - BooleanExpressionLexerINTEGER = 19 - BooleanExpressionLexerWS = 20 - BooleanExpressionLexerWORD = 21 - BooleanExpressionLexerALPHANUMERIC = 22 - BooleanExpressionLexerSQ = 23 - BooleanExpressionLexerDQ = 24 + BooleanExpressionLexerCONTAINS_ALL = 9 + BooleanExpressionLexerCONTAINS_ANY = 10 + BooleanExpressionLexerNE = 11 + BooleanExpressionLexerGT = 12 + BooleanExpressionLexerGE = 13 + BooleanExpressionLexerLT = 14 + BooleanExpressionLexerLE = 15 + BooleanExpressionLexerEQ = 16 + BooleanExpressionLexerLPAREN = 17 + BooleanExpressionLexerRPAREN = 18 + BooleanExpressionLexerDECIMAL = 19 + BooleanExpressionLexerAPP_VERSION = 20 + BooleanExpressionLexerINTEGER = 21 + BooleanExpressionLexerWS = 22 + BooleanExpressionLexerWORD = 23 + BooleanExpressionLexerALPHANUMERIC = 24 + BooleanExpressionLexerSQ = 25 + BooleanExpressionLexerDQ = 26 ) diff --git a/internal/parser/antlr/lib/booleanexpression_listener.go b/internal/parser/antlr/lib/booleanexpression_listener.go index aa832ba..53e1507 100644 --- a/internal/parser/antlr/lib/booleanexpression_listener.go +++ b/internal/parser/antlr/lib/booleanexpression_listener.go @@ -1,8 +1,8 @@ -// Code generated from java-escape by ANTLR 4.11.1. DO NOT EDIT. +// Code generated from /Users/sid/Desktop/filter1/BooleanExpression.g4 by ANTLR 4.13.1. DO NOT EDIT. package lib // BooleanExpression -import "github.com/antlr/antlr4/runtime/Go/antlr/v4" +import "github.com/antlr4-go/antlr/v4" // BooleanExpressionListener is a complete listener for a parse tree produced by BooleanExpressionParser. type BooleanExpressionListener interface { @@ -20,6 +20,9 @@ type BooleanExpressionListener interface { // EnterInExpression is called when entering the inExpression production. EnterInExpression(c *InExpressionContext) + // EnterArrayExpression is called when entering the arrayExpression production. + EnterArrayExpression(c *ArrayExpressionContext) + // EnterToExpression is called when entering the toExpression production. EnterToExpression(c *ToExpressionContext) @@ -38,6 +41,9 @@ type BooleanExpressionListener interface { // EnterWordlist is called when entering the wordlist production. EnterWordlist(c *WordlistContext) + // EnterArrayOperators is called when entering the arrayOperators production. + EnterArrayOperators(c *ArrayOperatorsContext) + // EnterNumericTypes is called when entering the numericTypes production. EnterNumericTypes(c *NumericTypesContext) @@ -62,6 +68,9 @@ type BooleanExpressionListener interface { // ExitInExpression is called when exiting the inExpression production. ExitInExpression(c *InExpressionContext) + // ExitArrayExpression is called when exiting the arrayExpression production. + ExitArrayExpression(c *ArrayExpressionContext) + // ExitToExpression is called when exiting the toExpression production. ExitToExpression(c *ToExpressionContext) @@ -80,6 +89,9 @@ type BooleanExpressionListener interface { // ExitWordlist is called when exiting the wordlist production. ExitWordlist(c *WordlistContext) + // ExitArrayOperators is called when exiting the arrayOperators production. + ExitArrayOperators(c *ArrayOperatorsContext) + // ExitNumericTypes is called when exiting the numericTypes production. ExitNumericTypes(c *NumericTypesContext) diff --git a/internal/parser/antlr/lib/booleanexpression_parser.go b/internal/parser/antlr/lib/booleanexpression_parser.go index 649cede..6c9b08a 100644 --- a/internal/parser/antlr/lib/booleanexpression_parser.go +++ b/internal/parser/antlr/lib/booleanexpression_parser.go @@ -1,4 +1,4 @@ -// Code generated from java-escape by ANTLR 4.11.1. DO NOT EDIT. +// Code generated from /Users/sid/Desktop/filter1/BooleanExpression.g4 by ANTLR 4.13.1. DO NOT EDIT. package lib // BooleanExpression @@ -7,7 +7,7 @@ import ( "strconv" "sync" - "github.com/antlr/antlr4/runtime/Go/antlr/v4" + "github.com/antlr4-go/antlr/v4" ) // Suppress unused import errors @@ -19,76 +19,86 @@ type BooleanExpressionParser struct { *antlr.BaseParser } -var booleanexpressionParserStaticData struct { +var BooleanExpressionParserStaticData struct { once sync.Once serializedATN []int32 - literalNames []string - symbolicNames []string - ruleNames []string - predictionContextCache *antlr.PredictionContextCache + LiteralNames []string + SymbolicNames []string + RuleNames []string + PredictionContextCache *antlr.PredictionContextCache atn *antlr.ATN decisionToDFA []*antlr.DFA } func booleanexpressionParserInit() { - staticData := &booleanexpressionParserStaticData - staticData.literalNames = []string{ - "", "','", "", "", "", "", "", "", "", "'!='", "'>'", "'>='", "'<'", - "'<='", "'='", "'('", "')'", - } - staticData.symbolicNames = []string{ - "", "", "IN", "TO", "AND", "OR", "NOT", "TRUE", "FALSE", "NE", "GT", - "GE", "LT", "LE", "EQ", "LPAREN", "RPAREN", "DECIMAL", "APP_VERSION", - "INTEGER", "WS", "WORD", "ALPHANUMERIC", "SQ", "DQ", - } - staticData.ruleNames = []string{ - "parse", "expression", "comparator", "wordlist", "numericTypes", "types", - "binary", "bool", - } - staticData.predictionContextCache = antlr.NewPredictionContextCache() + staticData := &BooleanExpressionParserStaticData + staticData.LiteralNames = []string{ + "", "','", "", "", "", "", "", "", "", "", "", "'!='", "'>'", "'>='", + "'<'", "'<='", "'='", "'('", "')'", + } + staticData.SymbolicNames = []string{ + "", "", "IN", "TO", "AND", "OR", "NOT", "TRUE", "FALSE", "CONTAINS_ALL", + "CONTAINS_ANY", "NE", "GT", "GE", "LT", "LE", "EQ", "LPAREN", "RPAREN", + "DECIMAL", "APP_VERSION", "INTEGER", "WS", "WORD", "ALPHANUMERIC", "SQ", + "DQ", + } + staticData.RuleNames = []string{ + "parse", "expression", "comparator", "wordlist", "arrayOperators", "numericTypes", + "types", "binary", "bool", + } + staticData.PredictionContextCache = antlr.NewPredictionContextCache() staticData.serializedATN = []int32{ - 4, 1, 24, 102, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, - 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 3, 1, 36, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 5, 1, 46, 8, 1, 10, 1, 12, 1, 49, 9, 1, 1, 2, 1, 2, 1, 3, 1, 3, 5, 3, 55, - 8, 3, 10, 3, 12, 3, 58, 9, 3, 1, 3, 1, 3, 5, 3, 62, 8, 3, 10, 3, 12, 3, - 65, 9, 3, 1, 3, 1, 3, 5, 3, 69, 8, 3, 10, 3, 12, 3, 72, 9, 3, 1, 3, 1, - 3, 5, 3, 76, 8, 3, 10, 3, 12, 3, 79, 9, 3, 5, 3, 81, 8, 3, 10, 3, 12, 3, - 84, 9, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, - 5, 96, 8, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 0, 1, 2, 8, 0, 2, 4, 6, 8, 10, - 12, 14, 0, 4, 1, 0, 9, 14, 2, 0, 17, 17, 19, 19, 1, 0, 4, 5, 1, 0, 7, 8, - 109, 0, 16, 1, 0, 0, 0, 2, 35, 1, 0, 0, 0, 4, 50, 1, 0, 0, 0, 6, 52, 1, - 0, 0, 0, 8, 87, 1, 0, 0, 0, 10, 95, 1, 0, 0, 0, 12, 97, 1, 0, 0, 0, 14, - 99, 1, 0, 0, 0, 16, 17, 3, 2, 1, 0, 17, 18, 5, 0, 0, 1, 18, 1, 1, 0, 0, - 0, 19, 20, 6, 1, -1, 0, 20, 21, 5, 15, 0, 0, 21, 22, 3, 2, 1, 0, 22, 23, - 5, 16, 0, 0, 23, 36, 1, 0, 0, 0, 24, 25, 5, 6, 0, 0, 25, 36, 3, 2, 1, 6, - 26, 36, 3, 10, 5, 0, 27, 28, 5, 21, 0, 0, 28, 29, 3, 8, 4, 0, 29, 30, 5, - 3, 0, 0, 30, 31, 3, 8, 4, 0, 31, 36, 1, 0, 0, 0, 32, 33, 5, 21, 0, 0, 33, - 34, 5, 2, 0, 0, 34, 36, 3, 6, 3, 0, 35, 19, 1, 0, 0, 0, 35, 24, 1, 0, 0, - 0, 35, 26, 1, 0, 0, 0, 35, 27, 1, 0, 0, 0, 35, 32, 1, 0, 0, 0, 36, 47, - 1, 0, 0, 0, 37, 38, 10, 5, 0, 0, 38, 39, 3, 4, 2, 0, 39, 40, 3, 2, 1, 6, - 40, 46, 1, 0, 0, 0, 41, 42, 10, 4, 0, 0, 42, 43, 3, 12, 6, 0, 43, 44, 3, - 2, 1, 5, 44, 46, 1, 0, 0, 0, 45, 37, 1, 0, 0, 0, 45, 41, 1, 0, 0, 0, 46, - 49, 1, 0, 0, 0, 47, 45, 1, 0, 0, 0, 47, 48, 1, 0, 0, 0, 48, 3, 1, 0, 0, - 0, 49, 47, 1, 0, 0, 0, 50, 51, 7, 0, 0, 0, 51, 5, 1, 0, 0, 0, 52, 56, 5, - 15, 0, 0, 53, 55, 5, 20, 0, 0, 54, 53, 1, 0, 0, 0, 55, 58, 1, 0, 0, 0, - 56, 54, 1, 0, 0, 0, 56, 57, 1, 0, 0, 0, 57, 59, 1, 0, 0, 0, 58, 56, 1, - 0, 0, 0, 59, 63, 3, 10, 5, 0, 60, 62, 5, 20, 0, 0, 61, 60, 1, 0, 0, 0, - 62, 65, 1, 0, 0, 0, 63, 61, 1, 0, 0, 0, 63, 64, 1, 0, 0, 0, 64, 82, 1, - 0, 0, 0, 65, 63, 1, 0, 0, 0, 66, 70, 5, 1, 0, 0, 67, 69, 5, 20, 0, 0, 68, - 67, 1, 0, 0, 0, 69, 72, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 70, 71, 1, 0, 0, - 0, 71, 73, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 73, 77, 3, 10, 5, 0, 74, 76, - 5, 20, 0, 0, 75, 74, 1, 0, 0, 0, 76, 79, 1, 0, 0, 0, 77, 75, 1, 0, 0, 0, - 77, 78, 1, 0, 0, 0, 78, 81, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 80, 66, 1, - 0, 0, 0, 81, 84, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, - 85, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 85, 86, 5, 16, 0, 0, 86, 7, 1, 0, 0, - 0, 87, 88, 7, 1, 0, 0, 88, 9, 1, 0, 0, 0, 89, 96, 5, 19, 0, 0, 90, 96, - 5, 17, 0, 0, 91, 96, 5, 18, 0, 0, 92, 96, 3, 14, 7, 0, 93, 96, 5, 21, 0, - 0, 94, 96, 1, 0, 0, 0, 95, 89, 1, 0, 0, 0, 95, 90, 1, 0, 0, 0, 95, 91, - 1, 0, 0, 0, 95, 92, 1, 0, 0, 0, 95, 93, 1, 0, 0, 0, 95, 94, 1, 0, 0, 0, - 96, 11, 1, 0, 0, 0, 97, 98, 7, 2, 0, 0, 98, 13, 1, 0, 0, 0, 99, 100, 7, - 3, 0, 0, 100, 15, 1, 0, 0, 0, 9, 35, 45, 47, 56, 63, 70, 77, 82, 95, + 4, 1, 26, 119, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, + 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 1, 0, 1, 0, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 31, 8, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 38, 8, 1, 1, 1, 3, 1, 41, 8, 1, 1, 1, 1, + 1, 1, 1, 3, 1, 46, 8, 1, 1, 1, 1, 1, 1, 1, 3, 1, 51, 8, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 61, 8, 1, 10, 1, 12, 1, 64, 9, + 1, 1, 2, 1, 2, 1, 3, 1, 3, 5, 3, 70, 8, 3, 10, 3, 12, 3, 73, 9, 3, 1, 3, + 1, 3, 5, 3, 77, 8, 3, 10, 3, 12, 3, 80, 9, 3, 1, 3, 1, 3, 5, 3, 84, 8, + 3, 10, 3, 12, 3, 87, 9, 3, 1, 3, 1, 3, 5, 3, 91, 8, 3, 10, 3, 12, 3, 94, + 9, 3, 5, 3, 96, 8, 3, 10, 3, 12, 3, 99, 9, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, + 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 113, 8, 6, 1, 7, 1, + 7, 1, 8, 1, 8, 1, 8, 0, 1, 2, 9, 0, 2, 4, 6, 8, 10, 12, 14, 16, 0, 5, 1, + 0, 11, 16, 1, 0, 9, 10, 2, 0, 19, 19, 21, 21, 1, 0, 4, 5, 1, 0, 7, 8, 130, + 0, 18, 1, 0, 0, 0, 2, 50, 1, 0, 0, 0, 4, 65, 1, 0, 0, 0, 6, 67, 1, 0, 0, + 0, 8, 102, 1, 0, 0, 0, 10, 104, 1, 0, 0, 0, 12, 112, 1, 0, 0, 0, 14, 114, + 1, 0, 0, 0, 16, 116, 1, 0, 0, 0, 18, 19, 3, 2, 1, 0, 19, 20, 5, 0, 0, 1, + 20, 1, 1, 0, 0, 0, 21, 22, 6, 1, -1, 0, 22, 23, 5, 17, 0, 0, 23, 24, 3, + 2, 1, 0, 24, 25, 5, 18, 0, 0, 25, 51, 1, 0, 0, 0, 26, 27, 5, 6, 0, 0, 27, + 51, 3, 2, 1, 7, 28, 51, 3, 12, 6, 0, 29, 31, 5, 23, 0, 0, 30, 29, 1, 0, + 0, 0, 30, 31, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 33, 3, 10, 5, 0, 33, + 34, 5, 3, 0, 0, 34, 35, 3, 10, 5, 0, 35, 51, 1, 0, 0, 0, 36, 38, 5, 23, + 0, 0, 37, 36, 1, 0, 0, 0, 37, 38, 1, 0, 0, 0, 38, 40, 1, 0, 0, 0, 39, 41, + 5, 6, 0, 0, 40, 39, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, + 42, 43, 5, 2, 0, 0, 43, 51, 3, 6, 3, 0, 44, 46, 5, 23, 0, 0, 45, 44, 1, + 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 48, 3, 8, 4, 0, 48, + 49, 3, 6, 3, 0, 49, 51, 1, 0, 0, 0, 50, 21, 1, 0, 0, 0, 50, 26, 1, 0, 0, + 0, 50, 28, 1, 0, 0, 0, 50, 30, 1, 0, 0, 0, 50, 37, 1, 0, 0, 0, 50, 45, + 1, 0, 0, 0, 51, 62, 1, 0, 0, 0, 52, 53, 10, 6, 0, 0, 53, 54, 3, 4, 2, 0, + 54, 55, 3, 2, 1, 7, 55, 61, 1, 0, 0, 0, 56, 57, 10, 5, 0, 0, 57, 58, 3, + 14, 7, 0, 58, 59, 3, 2, 1, 6, 59, 61, 1, 0, 0, 0, 60, 52, 1, 0, 0, 0, 60, + 56, 1, 0, 0, 0, 61, 64, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, + 0, 63, 3, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 65, 66, 7, 0, 0, 0, 66, 5, 1, + 0, 0, 0, 67, 71, 5, 17, 0, 0, 68, 70, 5, 22, 0, 0, 69, 68, 1, 0, 0, 0, + 70, 73, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 71, 72, 1, 0, 0, 0, 72, 74, 1, + 0, 0, 0, 73, 71, 1, 0, 0, 0, 74, 78, 3, 12, 6, 0, 75, 77, 5, 22, 0, 0, + 76, 75, 1, 0, 0, 0, 77, 80, 1, 0, 0, 0, 78, 76, 1, 0, 0, 0, 78, 79, 1, + 0, 0, 0, 79, 97, 1, 0, 0, 0, 80, 78, 1, 0, 0, 0, 81, 85, 5, 1, 0, 0, 82, + 84, 5, 22, 0, 0, 83, 82, 1, 0, 0, 0, 84, 87, 1, 0, 0, 0, 85, 83, 1, 0, + 0, 0, 85, 86, 1, 0, 0, 0, 86, 88, 1, 0, 0, 0, 87, 85, 1, 0, 0, 0, 88, 92, + 3, 12, 6, 0, 89, 91, 5, 22, 0, 0, 90, 89, 1, 0, 0, 0, 91, 94, 1, 0, 0, + 0, 92, 90, 1, 0, 0, 0, 92, 93, 1, 0, 0, 0, 93, 96, 1, 0, 0, 0, 94, 92, + 1, 0, 0, 0, 95, 81, 1, 0, 0, 0, 96, 99, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, + 97, 98, 1, 0, 0, 0, 98, 100, 1, 0, 0, 0, 99, 97, 1, 0, 0, 0, 100, 101, + 5, 18, 0, 0, 101, 7, 1, 0, 0, 0, 102, 103, 7, 1, 0, 0, 103, 9, 1, 0, 0, + 0, 104, 105, 7, 2, 0, 0, 105, 11, 1, 0, 0, 0, 106, 113, 5, 21, 0, 0, 107, + 113, 5, 19, 0, 0, 108, 113, 5, 20, 0, 0, 109, 113, 3, 16, 8, 0, 110, 113, + 5, 23, 0, 0, 111, 113, 1, 0, 0, 0, 112, 106, 1, 0, 0, 0, 112, 107, 1, 0, + 0, 0, 112, 108, 1, 0, 0, 0, 112, 109, 1, 0, 0, 0, 112, 110, 1, 0, 0, 0, + 112, 111, 1, 0, 0, 0, 113, 13, 1, 0, 0, 0, 114, 115, 7, 3, 0, 0, 115, 15, + 1, 0, 0, 0, 116, 117, 7, 4, 0, 0, 117, 17, 1, 0, 0, 0, 13, 30, 37, 40, + 45, 50, 60, 62, 71, 78, 85, 92, 97, 112, } deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) @@ -105,7 +115,7 @@ func booleanexpressionParserInit() { // NewBooleanExpressionParser(). You can call this function if you wish to initialize the static state ahead // of time. func BooleanExpressionParserInit() { - staticData := &booleanexpressionParserStaticData + staticData := &BooleanExpressionParserStaticData staticData.once.Do(booleanexpressionParserInit) } @@ -114,12 +124,12 @@ func NewBooleanExpressionParser(input antlr.TokenStream) *BooleanExpressionParse BooleanExpressionParserInit() this := new(BooleanExpressionParser) this.BaseParser = antlr.NewBaseParser(input) - staticData := &booleanexpressionParserStaticData - this.Interpreter = antlr.NewParserATNSimulator(this, staticData.atn, staticData.decisionToDFA, staticData.predictionContextCache) - this.RuleNames = staticData.ruleNames - this.LiteralNames = staticData.literalNames - this.SymbolicNames = staticData.symbolicNames - this.GrammarFileName = "java-escape" + staticData := &BooleanExpressionParserStaticData + this.Interpreter = antlr.NewParserATNSimulator(this, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache) + this.RuleNames = staticData.RuleNames + this.LiteralNames = staticData.LiteralNames + this.SymbolicNames = staticData.SymbolicNames + this.GrammarFileName = "BooleanExpression.g4" return this } @@ -135,34 +145,37 @@ const ( BooleanExpressionParserNOT = 6 BooleanExpressionParserTRUE = 7 BooleanExpressionParserFALSE = 8 - BooleanExpressionParserNE = 9 - BooleanExpressionParserGT = 10 - BooleanExpressionParserGE = 11 - BooleanExpressionParserLT = 12 - BooleanExpressionParserLE = 13 - BooleanExpressionParserEQ = 14 - BooleanExpressionParserLPAREN = 15 - BooleanExpressionParserRPAREN = 16 - BooleanExpressionParserDECIMAL = 17 - BooleanExpressionParserAPP_VERSION = 18 - BooleanExpressionParserINTEGER = 19 - BooleanExpressionParserWS = 20 - BooleanExpressionParserWORD = 21 - BooleanExpressionParserALPHANUMERIC = 22 - BooleanExpressionParserSQ = 23 - BooleanExpressionParserDQ = 24 + BooleanExpressionParserCONTAINS_ALL = 9 + BooleanExpressionParserCONTAINS_ANY = 10 + BooleanExpressionParserNE = 11 + BooleanExpressionParserGT = 12 + BooleanExpressionParserGE = 13 + BooleanExpressionParserLT = 14 + BooleanExpressionParserLE = 15 + BooleanExpressionParserEQ = 16 + BooleanExpressionParserLPAREN = 17 + BooleanExpressionParserRPAREN = 18 + BooleanExpressionParserDECIMAL = 19 + BooleanExpressionParserAPP_VERSION = 20 + BooleanExpressionParserINTEGER = 21 + BooleanExpressionParserWS = 22 + BooleanExpressionParserWORD = 23 + BooleanExpressionParserALPHANUMERIC = 24 + BooleanExpressionParserSQ = 25 + BooleanExpressionParserDQ = 26 ) // BooleanExpressionParser rules. const ( - BooleanExpressionParserRULE_parse = 0 - BooleanExpressionParserRULE_expression = 1 - BooleanExpressionParserRULE_comparator = 2 - BooleanExpressionParserRULE_wordlist = 3 - BooleanExpressionParserRULE_numericTypes = 4 - BooleanExpressionParserRULE_types = 5 - BooleanExpressionParserRULE_binary = 6 - BooleanExpressionParserRULE_bool = 7 + BooleanExpressionParserRULE_parse = 0 + BooleanExpressionParserRULE_expression = 1 + BooleanExpressionParserRULE_comparator = 2 + BooleanExpressionParserRULE_wordlist = 3 + BooleanExpressionParserRULE_arrayOperators = 4 + BooleanExpressionParserRULE_numericTypes = 5 + BooleanExpressionParserRULE_types = 6 + BooleanExpressionParserRULE_binary = 7 + BooleanExpressionParserRULE_bool = 8 ) // IParseContext is an interface to support dynamic dispatch. @@ -172,28 +185,37 @@ type IParseContext interface { // GetParser returns the parser. GetParser() antlr.Parser + // Getter signatures + Expression() IExpressionContext + EOF() antlr.TerminalNode + // IsParseContext differentiates from other interfaces. IsParseContext() } type ParseContext struct { - *antlr.BaseParserRuleContext + antlr.BaseParserRuleContext parser antlr.Parser } func NewEmptyParseContext() *ParseContext { var p = new(ParseContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) p.RuleIndex = BooleanExpressionParserRULE_parse return p } +func InitEmptyParseContext(p *ParseContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = BooleanExpressionParserRULE_parse +} + func (*ParseContext) IsParseContext() {} func NewParseContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ParseContext { var p = new(ParseContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) p.parser = parser p.RuleIndex = BooleanExpressionParserRULE_parse @@ -244,39 +266,33 @@ func (s *ParseContext) ExitRule(listener antlr.ParseTreeListener) { } func (p *BooleanExpressionParser) Parse() (localctx IParseContext) { - this := p - _ = this - localctx = NewParseContext(p, p.GetParserRuleContext(), p.GetState()) p.EnterRule(localctx, 0, BooleanExpressionParserRULE_parse) - - defer func() { - p.ExitRule() - }() - - defer func() { - if err := recover(); err != nil { - if v, ok := err.(antlr.RecognitionException); ok { - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - } else { - panic(err) - } - } - }() - p.EnterOuterAlt(localctx, 1) { - p.SetState(16) + p.SetState(18) p.expression(0) } { - p.SetState(17) + p.SetState(19) p.Match(BooleanExpressionParserEOF) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() return localctx + goto errorExit // Trick to prevent compiler error if the label is not used } // IExpressionContext is an interface to support dynamic dispatch. @@ -285,29 +301,33 @@ type IExpressionContext interface { // GetParser returns the parser. GetParser() antlr.Parser - // IsExpressionContext differentiates from other interfaces. IsExpressionContext() } type ExpressionContext struct { - *antlr.BaseParserRuleContext + antlr.BaseParserRuleContext parser antlr.Parser } func NewEmptyExpressionContext() *ExpressionContext { var p = new(ExpressionContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) p.RuleIndex = BooleanExpressionParserRULE_expression return p } +func InitEmptyExpressionContext(p *ExpressionContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = BooleanExpressionParserRULE_expression +} + func (*ExpressionContext) IsExpressionContext() {} func NewExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ExpressionContext { var p = new(ExpressionContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) p.parser = parser p.RuleIndex = BooleanExpressionParserRULE_expression @@ -317,8 +337,8 @@ func NewExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, i func (s *ExpressionContext) GetParser() antlr.Parser { return s.parser } -func (s *ExpressionContext) CopyFrom(ctx *ExpressionContext) { - s.BaseParserRuleContext.CopyFrom(ctx.BaseParserRuleContext) +func (s *ExpressionContext) CopyAll(ctx *ExpressionContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) } func (s *ExpressionContext) GetRuleContext() antlr.RuleContext { @@ -330,7 +350,7 @@ func (s *ExpressionContext) ToStringTree(ruleNames []string, recog antlr.Recogni } type BinaryExpressionContext struct { - *ExpressionContext + ExpressionContext left IExpressionContext op IBinaryContext right IExpressionContext @@ -339,9 +359,9 @@ type BinaryExpressionContext struct { func NewBinaryExpressionContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *BinaryExpressionContext { var p = new(BinaryExpressionContext) - p.ExpressionContext = NewEmptyExpressionContext() + InitEmptyExpressionContext(&p.ExpressionContext) p.parser = parser - p.CopyFrom(ctx.(*ExpressionContext)) + p.CopyAll(ctx.(*ExpressionContext)) return p } @@ -432,15 +452,15 @@ func (s *BinaryExpressionContext) ExitRule(listener antlr.ParseTreeListener) { } type TypesExpressionContext struct { - *ExpressionContext + ExpressionContext } func NewTypesExpressionContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *TypesExpressionContext { var p = new(TypesExpressionContext) - p.ExpressionContext = NewEmptyExpressionContext() + InitEmptyExpressionContext(&p.ExpressionContext) p.parser = parser - p.CopyFrom(ctx.(*ExpressionContext)) + p.CopyAll(ctx.(*ExpressionContext)) return p } @@ -478,25 +498,30 @@ func (s *TypesExpressionContext) ExitRule(listener antlr.ParseTreeListener) { } type InExpressionContext struct { - *ExpressionContext + ExpressionContext field antlr.Token + not antlr.Token data IWordlistContext } func NewInExpressionContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *InExpressionContext { var p = new(InExpressionContext) - p.ExpressionContext = NewEmptyExpressionContext() + InitEmptyExpressionContext(&p.ExpressionContext) p.parser = parser - p.CopyFrom(ctx.(*ExpressionContext)) + p.CopyAll(ctx.(*ExpressionContext)) return p } func (s *InExpressionContext) GetField() antlr.Token { return s.field } +func (s *InExpressionContext) GetNot() antlr.Token { return s.not } + func (s *InExpressionContext) SetField(v antlr.Token) { s.field = v } +func (s *InExpressionContext) SetNot(v antlr.Token) { s.not = v } + func (s *InExpressionContext) GetData() IWordlistContext { return s.data } func (s *InExpressionContext) SetData(v IWordlistContext) { s.data = v } @@ -509,10 +534,6 @@ func (s *InExpressionContext) IN() antlr.TerminalNode { return s.GetToken(BooleanExpressionParserIN, 0) } -func (s *InExpressionContext) WORD() antlr.TerminalNode { - return s.GetToken(BooleanExpressionParserWORD, 0) -} - func (s *InExpressionContext) Wordlist() IWordlistContext { var t antlr.RuleContext for _, ctx := range s.GetChildren() { @@ -529,6 +550,14 @@ func (s *InExpressionContext) Wordlist() IWordlistContext { return t.(IWordlistContext) } +func (s *InExpressionContext) WORD() antlr.TerminalNode { + return s.GetToken(BooleanExpressionParserWORD, 0) +} + +func (s *InExpressionContext) NOT() antlr.TerminalNode { + return s.GetToken(BooleanExpressionParserNOT, 0) +} + func (s *InExpressionContext) EnterRule(listener antlr.ParseTreeListener) { if listenerT, ok := listener.(BooleanExpressionListener); ok { listenerT.EnterInExpression(s) @@ -541,8 +570,89 @@ func (s *InExpressionContext) ExitRule(listener antlr.ParseTreeListener) { } } +type ArrayExpressionContext struct { + ExpressionContext + field antlr.Token + op IArrayOperatorsContext + data IWordlistContext +} + +func NewArrayExpressionContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *ArrayExpressionContext { + var p = new(ArrayExpressionContext) + + InitEmptyExpressionContext(&p.ExpressionContext) + p.parser = parser + p.CopyAll(ctx.(*ExpressionContext)) + + return p +} + +func (s *ArrayExpressionContext) GetField() antlr.Token { return s.field } + +func (s *ArrayExpressionContext) SetField(v antlr.Token) { s.field = v } + +func (s *ArrayExpressionContext) GetOp() IArrayOperatorsContext { return s.op } + +func (s *ArrayExpressionContext) GetData() IWordlistContext { return s.data } + +func (s *ArrayExpressionContext) SetOp(v IArrayOperatorsContext) { s.op = v } + +func (s *ArrayExpressionContext) SetData(v IWordlistContext) { s.data = v } + +func (s *ArrayExpressionContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ArrayExpressionContext) ArrayOperators() IArrayOperatorsContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IArrayOperatorsContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IArrayOperatorsContext) +} + +func (s *ArrayExpressionContext) Wordlist() IWordlistContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IWordlistContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IWordlistContext) +} + +func (s *ArrayExpressionContext) WORD() antlr.TerminalNode { + return s.GetToken(BooleanExpressionParserWORD, 0) +} + +func (s *ArrayExpressionContext) EnterRule(listener antlr.ParseTreeListener) { + if listenerT, ok := listener.(BooleanExpressionListener); ok { + listenerT.EnterArrayExpression(s) + } +} + +func (s *ArrayExpressionContext) ExitRule(listener antlr.ParseTreeListener) { + if listenerT, ok := listener.(BooleanExpressionListener); ok { + listenerT.ExitArrayExpression(s) + } +} + type ToExpressionContext struct { - *ExpressionContext + ExpressionContext field antlr.Token lower INumericTypesContext upper INumericTypesContext @@ -551,9 +661,9 @@ type ToExpressionContext struct { func NewToExpressionContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *ToExpressionContext { var p = new(ToExpressionContext) - p.ExpressionContext = NewEmptyExpressionContext() + InitEmptyExpressionContext(&p.ExpressionContext) p.parser = parser - p.CopyFrom(ctx.(*ExpressionContext)) + p.CopyAll(ctx.(*ExpressionContext)) return p } @@ -578,10 +688,6 @@ func (s *ToExpressionContext) TO() antlr.TerminalNode { return s.GetToken(BooleanExpressionParserTO, 0) } -func (s *ToExpressionContext) WORD() antlr.TerminalNode { - return s.GetToken(BooleanExpressionParserWORD, 0) -} - func (s *ToExpressionContext) AllNumericTypes() []INumericTypesContext { children := s.GetChildren() len := 0 @@ -623,6 +729,10 @@ func (s *ToExpressionContext) NumericTypes(i int) INumericTypesContext { return t.(INumericTypesContext) } +func (s *ToExpressionContext) WORD() antlr.TerminalNode { + return s.GetToken(BooleanExpressionParserWORD, 0) +} + func (s *ToExpressionContext) EnterRule(listener antlr.ParseTreeListener) { if listenerT, ok := listener.(BooleanExpressionListener); ok { listenerT.EnterToExpression(s) @@ -636,15 +746,15 @@ func (s *ToExpressionContext) ExitRule(listener antlr.ParseTreeListener) { } type NotExpressionContext struct { - *ExpressionContext + ExpressionContext } func NewNotExpressionContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *NotExpressionContext { var p = new(NotExpressionContext) - p.ExpressionContext = NewEmptyExpressionContext() + InitEmptyExpressionContext(&p.ExpressionContext) p.parser = parser - p.CopyFrom(ctx.(*ExpressionContext)) + p.CopyAll(ctx.(*ExpressionContext)) return p } @@ -686,7 +796,7 @@ func (s *NotExpressionContext) ExitRule(listener antlr.ParseTreeListener) { } type ComparatorExpressionContext struct { - *ExpressionContext + ExpressionContext left IExpressionContext op IComparatorContext right IExpressionContext @@ -695,9 +805,9 @@ type ComparatorExpressionContext struct { func NewComparatorExpressionContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *ComparatorExpressionContext { var p = new(ComparatorExpressionContext) - p.ExpressionContext = NewEmptyExpressionContext() + InitEmptyExpressionContext(&p.ExpressionContext) p.parser = parser - p.CopyFrom(ctx.(*ExpressionContext)) + p.CopyAll(ctx.(*ExpressionContext)) return p } @@ -788,15 +898,15 @@ func (s *ComparatorExpressionContext) ExitRule(listener antlr.ParseTreeListener) } type ParentExpressionContext struct { - *ExpressionContext + ExpressionContext } func NewParentExpressionContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *ParentExpressionContext { var p = new(ParentExpressionContext) - p.ExpressionContext = NewEmptyExpressionContext() + InitEmptyExpressionContext(&p.ExpressionContext) p.parser = parser - p.CopyFrom(ctx.(*ExpressionContext)) + p.CopyAll(ctx.(*ExpressionContext)) return p } @@ -846,55 +956,50 @@ func (p *BooleanExpressionParser) Expression() (localctx IExpressionContext) { } func (p *BooleanExpressionParser) expression(_p int) (localctx IExpressionContext) { - this := p - _ = this - var _parentctx antlr.ParserRuleContext = p.GetParserRuleContext() + _parentState := p.GetState() localctx = NewExpressionContext(p, p.GetParserRuleContext(), _parentState) var _prevctx IExpressionContext = localctx var _ antlr.ParserRuleContext = _prevctx // TODO: To prevent unused variable warning. _startState := 2 p.EnterRecursionRule(localctx, 2, BooleanExpressionParserRULE_expression, _p) - - defer func() { - p.UnrollRecursionContexts(_parentctx) - }() - - defer func() { - if err := recover(); err != nil { - if v, ok := err.(antlr.RecognitionException); ok { - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - } else { - panic(err) - } - } - }() + var _la int var _alt int p.EnterOuterAlt(localctx, 1) - p.SetState(35) + p.SetState(50) p.GetErrorHandler().Sync(p) - switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 0, p.GetParserRuleContext()) { + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 4, p.GetParserRuleContext()) { case 1: localctx = NewParentExpressionContext(p, localctx) p.SetParserRuleContext(localctx) _prevctx = localctx { - p.SetState(20) + p.SetState(22) p.Match(BooleanExpressionParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } { - p.SetState(21) + p.SetState(23) p.expression(0) } { - p.SetState(22) + p.SetState(24) p.Match(BooleanExpressionParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } case 2: @@ -902,12 +1007,16 @@ func (p *BooleanExpressionParser) expression(_p int) (localctx IExpressionContex p.SetParserRuleContext(localctx) _prevctx = localctx { - p.SetState(24) + p.SetState(26) p.Match(BooleanExpressionParserNOT) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } { - p.SetState(25) - p.expression(6) + p.SetState(27) + p.expression(7) } case 3: @@ -915,7 +1024,7 @@ func (p *BooleanExpressionParser) expression(_p int) (localctx IExpressionContex p.SetParserRuleContext(localctx) _prevctx = localctx { - p.SetState(26) + p.SetState(28) p.Types() } @@ -923,26 +1032,44 @@ func (p *BooleanExpressionParser) expression(_p int) (localctx IExpressionContex localctx = NewToExpressionContext(p, localctx) p.SetParserRuleContext(localctx) _prevctx = localctx - { - p.SetState(27) + p.SetState(30) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == BooleanExpressionParserWORD { + { + p.SetState(29) + + var _m = p.Match(BooleanExpressionParserWORD) - var _m = p.Match(BooleanExpressionParserWORD) + localctx.(*ToExpressionContext).field = _m + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } - localctx.(*ToExpressionContext).field = _m } { - p.SetState(28) + p.SetState(32) var _x = p.NumericTypes() localctx.(*ToExpressionContext).lower = _x } { - p.SetState(29) + p.SetState(33) p.Match(BooleanExpressionParserTO) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } { - p.SetState(30) + p.SetState(34) var _x = p.NumericTypes() @@ -953,61 +1080,152 @@ func (p *BooleanExpressionParser) expression(_p int) (localctx IExpressionContex localctx = NewInExpressionContext(p, localctx) p.SetParserRuleContext(localctx) _prevctx = localctx - { - p.SetState(32) + p.SetState(37) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == BooleanExpressionParserWORD { + { + p.SetState(36) - var _m = p.Match(BooleanExpressionParserWORD) + var _m = p.Match(BooleanExpressionParserWORD) + + localctx.(*InExpressionContext).field = _m + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + } + p.SetState(40) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == BooleanExpressionParserNOT { + { + p.SetState(39) + + var _m = p.Match(BooleanExpressionParserNOT) + + localctx.(*InExpressionContext).not = _m + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } - localctx.(*InExpressionContext).field = _m } { - p.SetState(33) + p.SetState(42) p.Match(BooleanExpressionParserIN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } { - p.SetState(34) + p.SetState(43) var _x = p.Wordlist() localctx.(*InExpressionContext).data = _x } + case 6: + localctx = NewArrayExpressionContext(p, localctx) + p.SetParserRuleContext(localctx) + _prevctx = localctx + p.SetState(45) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == BooleanExpressionParserWORD { + { + p.SetState(44) + + var _m = p.Match(BooleanExpressionParserWORD) + + localctx.(*ArrayExpressionContext).field = _m + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + } + { + p.SetState(47) + + var _x = p.ArrayOperators() + + localctx.(*ArrayExpressionContext).op = _x + } + { + p.SetState(48) + + var _x = p.Wordlist() + + localctx.(*ArrayExpressionContext).data = _x + } + + case antlr.ATNInvalidAltNumber: + goto errorExit } p.GetParserRuleContext().SetStop(p.GetTokenStream().LT(-1)) - p.SetState(47) + p.SetState(62) p.GetErrorHandler().Sync(p) - _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 2, p.GetParserRuleContext()) - + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 6, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { if _alt == 1 { if p.GetParseListeners() != nil { p.TriggerExitRuleEvent() } _prevctx = localctx - p.SetState(45) + p.SetState(60) p.GetErrorHandler().Sync(p) - switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 1, p.GetParserRuleContext()) { + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 5, p.GetParserRuleContext()) { case 1: localctx = NewComparatorExpressionContext(p, NewExpressionContext(p, _parentctx, _parentState)) localctx.(*ComparatorExpressionContext).left = _prevctx p.PushNewRecursionContext(localctx, _startState, BooleanExpressionParserRULE_expression) - p.SetState(37) + p.SetState(52) - if !(p.Precpred(p.GetParserRuleContext(), 5)) { - panic(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 5)", "")) + if !(p.Precpred(p.GetParserRuleContext(), 6)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 6)", "")) + goto errorExit } { - p.SetState(38) + p.SetState(53) var _x = p.Comparator() localctx.(*ComparatorExpressionContext).op = _x } { - p.SetState(39) + p.SetState(54) - var _x = p.expression(6) + var _x = p.expression(7) localctx.(*ComparatorExpressionContext).right = _x } @@ -1017,35 +1235,54 @@ func (p *BooleanExpressionParser) expression(_p int) (localctx IExpressionContex localctx.(*BinaryExpressionContext).left = _prevctx p.PushNewRecursionContext(localctx, _startState, BooleanExpressionParserRULE_expression) - p.SetState(41) + p.SetState(56) - if !(p.Precpred(p.GetParserRuleContext(), 4)) { - panic(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 4)", "")) + if !(p.Precpred(p.GetParserRuleContext(), 5)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 5)", "")) + goto errorExit } { - p.SetState(42) + p.SetState(57) var _x = p.Binary() localctx.(*BinaryExpressionContext).op = _x } { - p.SetState(43) + p.SetState(58) - var _x = p.expression(5) + var _x = p.expression(6) localctx.(*BinaryExpressionContext).right = _x } + case antlr.ATNInvalidAltNumber: + goto errorExit } } - p.SetState(49) + p.SetState(64) p.GetErrorHandler().Sync(p) - _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 2, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 6, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } } +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.UnrollRecursionContexts(_parentctx) return localctx + goto errorExit // Trick to prevent compiler error if the label is not used } // IComparatorContext is an interface to support dynamic dispatch. @@ -1055,28 +1292,41 @@ type IComparatorContext interface { // GetParser returns the parser. GetParser() antlr.Parser + // Getter signatures + GT() antlr.TerminalNode + GE() antlr.TerminalNode + LT() antlr.TerminalNode + LE() antlr.TerminalNode + EQ() antlr.TerminalNode + NE() antlr.TerminalNode + // IsComparatorContext differentiates from other interfaces. IsComparatorContext() } type ComparatorContext struct { - *antlr.BaseParserRuleContext + antlr.BaseParserRuleContext parser antlr.Parser } func NewEmptyComparatorContext() *ComparatorContext { var p = new(ComparatorContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) p.RuleIndex = BooleanExpressionParserRULE_comparator return p } +func InitEmptyComparatorContext(p *ComparatorContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = BooleanExpressionParserRULE_comparator +} + func (*ComparatorContext) IsComparatorContext() {} func NewComparatorContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ComparatorContext { var p = new(ComparatorContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) p.parser = parser p.RuleIndex = BooleanExpressionParserRULE_comparator @@ -1131,35 +1381,16 @@ func (s *ComparatorContext) ExitRule(listener antlr.ParseTreeListener) { } func (p *BooleanExpressionParser) Comparator() (localctx IComparatorContext) { - this := p - _ = this - localctx = NewComparatorContext(p, p.GetParserRuleContext(), p.GetState()) p.EnterRule(localctx, 4, BooleanExpressionParserRULE_comparator) var _la int - defer func() { - p.ExitRule() - }() - - defer func() { - if err := recover(); err != nil { - if v, ok := err.(antlr.RecognitionException); ok { - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - } else { - panic(err) - } - } - }() - p.EnterOuterAlt(localctx, 1) { - p.SetState(50) + p.SetState(65) _la = p.GetTokenStream().LA(1) - if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&32256) != 0) { + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&129024) != 0) { p.GetErrorHandler().RecoverInline(p) } else { p.GetErrorHandler().ReportMatch(p) @@ -1167,7 +1398,17 @@ func (p *BooleanExpressionParser) Comparator() (localctx IComparatorContext) { } } +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() return localctx + goto errorExit // Trick to prevent compiler error if the label is not used } // IWordlistContext is an interface to support dynamic dispatch. @@ -1189,12 +1430,20 @@ type IWordlistContext interface { // SetRest sets the rest rule contexts. SetRest(ITypesContext) + // Getter signatures + LPAREN() antlr.TerminalNode + RPAREN() antlr.TerminalNode + AllTypes() []ITypesContext + Types(i int) ITypesContext + AllWS() []antlr.TerminalNode + WS(i int) antlr.TerminalNode + // IsWordlistContext differentiates from other interfaces. IsWordlistContext() } type WordlistContext struct { - *antlr.BaseParserRuleContext + antlr.BaseParserRuleContext parser antlr.Parser first ITypesContext rest ITypesContext @@ -1202,17 +1451,22 @@ type WordlistContext struct { func NewEmptyWordlistContext() *WordlistContext { var p = new(WordlistContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) p.RuleIndex = BooleanExpressionParserRULE_wordlist return p } +func InitEmptyWordlistContext(p *WordlistContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = BooleanExpressionParserRULE_wordlist +} + func (*WordlistContext) IsWordlistContext() {} func NewWordlistContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *WordlistContext { var p = new(WordlistContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) p.parser = parser p.RuleIndex = BooleanExpressionParserRULE_wordlist @@ -1308,130 +1562,295 @@ func (s *WordlistContext) ExitRule(listener antlr.ParseTreeListener) { } func (p *BooleanExpressionParser) Wordlist() (localctx IWordlistContext) { - this := p - _ = this - localctx = NewWordlistContext(p, p.GetParserRuleContext(), p.GetState()) p.EnterRule(localctx, 6, BooleanExpressionParserRULE_wordlist) var _la int - defer func() { - p.ExitRule() - }() - - defer func() { - if err := recover(); err != nil { - if v, ok := err.(antlr.RecognitionException); ok { - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - } else { - panic(err) - } - } - }() - var _alt int p.EnterOuterAlt(localctx, 1) { - p.SetState(52) + p.SetState(67) p.Match(BooleanExpressionParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } - p.SetState(56) + p.SetState(71) p.GetErrorHandler().Sync(p) - _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 3, p.GetParserRuleContext()) - + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 7, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { if _alt == 1 { { - p.SetState(53) + p.SetState(68) p.Match(BooleanExpressionParserWS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } } - p.SetState(58) + p.SetState(73) p.GetErrorHandler().Sync(p) - _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 3, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 7, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } } { - p.SetState(59) + p.SetState(74) var _x = p.Types() localctx.(*WordlistContext).first = _x } - p.SetState(63) + p.SetState(78) p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } _la = p.GetTokenStream().LA(1) for _la == BooleanExpressionParserWS { { - p.SetState(60) + p.SetState(75) p.Match(BooleanExpressionParserWS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } - p.SetState(65) + p.SetState(80) p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } _la = p.GetTokenStream().LA(1) } - p.SetState(82) + p.SetState(97) p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } _la = p.GetTokenStream().LA(1) for _la == BooleanExpressionParserT__0 { { - p.SetState(66) + p.SetState(81) p.Match(BooleanExpressionParserT__0) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } - p.SetState(70) + p.SetState(85) p.GetErrorHandler().Sync(p) - _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 5, p.GetParserRuleContext()) - + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 9, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { if _alt == 1 { { - p.SetState(67) + p.SetState(82) p.Match(BooleanExpressionParserWS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } } - p.SetState(72) + p.SetState(87) p.GetErrorHandler().Sync(p) - _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 5, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 9, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } } { - p.SetState(73) + p.SetState(88) var _x = p.Types() localctx.(*WordlistContext).rest = _x } - p.SetState(77) + p.SetState(92) p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } _la = p.GetTokenStream().LA(1) for _la == BooleanExpressionParserWS { { - p.SetState(74) + p.SetState(89) p.Match(BooleanExpressionParserWS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } - p.SetState(79) + p.SetState(94) p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } _la = p.GetTokenStream().LA(1) } - p.SetState(84) + p.SetState(99) p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } _la = p.GetTokenStream().LA(1) } { - p.SetState(85) + p.SetState(100) p.Match(BooleanExpressionParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IArrayOperatorsContext is an interface to support dynamic dispatch. +type IArrayOperatorsContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + CONTAINS_ANY() antlr.TerminalNode + CONTAINS_ALL() antlr.TerminalNode + + // IsArrayOperatorsContext differentiates from other interfaces. + IsArrayOperatorsContext() +} + +type ArrayOperatorsContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyArrayOperatorsContext() *ArrayOperatorsContext { + var p = new(ArrayOperatorsContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = BooleanExpressionParserRULE_arrayOperators + return p +} + +func InitEmptyArrayOperatorsContext(p *ArrayOperatorsContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = BooleanExpressionParserRULE_arrayOperators +} + +func (*ArrayOperatorsContext) IsArrayOperatorsContext() {} + +func NewArrayOperatorsContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ArrayOperatorsContext { + var p = new(ArrayOperatorsContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = BooleanExpressionParserRULE_arrayOperators + + return p +} + +func (s *ArrayOperatorsContext) GetParser() antlr.Parser { return s.parser } + +func (s *ArrayOperatorsContext) CONTAINS_ANY() antlr.TerminalNode { + return s.GetToken(BooleanExpressionParserCONTAINS_ANY, 0) +} + +func (s *ArrayOperatorsContext) CONTAINS_ALL() antlr.TerminalNode { + return s.GetToken(BooleanExpressionParserCONTAINS_ALL, 0) +} + +func (s *ArrayOperatorsContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ArrayOperatorsContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ArrayOperatorsContext) EnterRule(listener antlr.ParseTreeListener) { + if listenerT, ok := listener.(BooleanExpressionListener); ok { + listenerT.EnterArrayOperators(s) } +} +func (s *ArrayOperatorsContext) ExitRule(listener antlr.ParseTreeListener) { + if listenerT, ok := listener.(BooleanExpressionListener); ok { + listenerT.ExitArrayOperators(s) + } +} + +func (p *BooleanExpressionParser) ArrayOperators() (localctx IArrayOperatorsContext) { + localctx = NewArrayOperatorsContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 8, BooleanExpressionParserRULE_arrayOperators) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(102) + _la = p.GetTokenStream().LA(1) + + if !(_la == BooleanExpressionParserCONTAINS_ALL || _la == BooleanExpressionParserCONTAINS_ANY) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() return localctx + goto errorExit // Trick to prevent compiler error if the label is not used } // INumericTypesContext is an interface to support dynamic dispatch. @@ -1441,28 +1860,37 @@ type INumericTypesContext interface { // GetParser returns the parser. GetParser() antlr.Parser + // Getter signatures + INTEGER() antlr.TerminalNode + DECIMAL() antlr.TerminalNode + // IsNumericTypesContext differentiates from other interfaces. IsNumericTypesContext() } type NumericTypesContext struct { - *antlr.BaseParserRuleContext + antlr.BaseParserRuleContext parser antlr.Parser } func NewEmptyNumericTypesContext() *NumericTypesContext { var p = new(NumericTypesContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) p.RuleIndex = BooleanExpressionParserRULE_numericTypes return p } +func InitEmptyNumericTypesContext(p *NumericTypesContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = BooleanExpressionParserRULE_numericTypes +} + func (*NumericTypesContext) IsNumericTypesContext() {} func NewNumericTypesContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *NumericTypesContext { var p = new(NumericTypesContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) p.parser = parser p.RuleIndex = BooleanExpressionParserRULE_numericTypes @@ -1501,32 +1929,13 @@ func (s *NumericTypesContext) ExitRule(listener antlr.ParseTreeListener) { } func (p *BooleanExpressionParser) NumericTypes() (localctx INumericTypesContext) { - this := p - _ = this - localctx = NewNumericTypesContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 8, BooleanExpressionParserRULE_numericTypes) + p.EnterRule(localctx, 10, BooleanExpressionParserRULE_numericTypes) var _la int - defer func() { - p.ExitRule() - }() - - defer func() { - if err := recover(); err != nil { - if v, ok := err.(antlr.RecognitionException); ok { - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - } else { - panic(err) - } - } - }() - p.EnterOuterAlt(localctx, 1) { - p.SetState(87) + p.SetState(104) _la = p.GetTokenStream().LA(1) if !(_la == BooleanExpressionParserDECIMAL || _la == BooleanExpressionParserINTEGER) { @@ -1537,7 +1946,17 @@ func (p *BooleanExpressionParser) NumericTypes() (localctx INumericTypesContext) } } +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() return localctx + goto errorExit // Trick to prevent compiler error if the label is not used } // ITypesContext is an interface to support dynamic dispatch. @@ -1547,28 +1966,40 @@ type ITypesContext interface { // GetParser returns the parser. GetParser() antlr.Parser + // Getter signatures + INTEGER() antlr.TerminalNode + DECIMAL() antlr.TerminalNode + APP_VERSION() antlr.TerminalNode + Bool_() IBoolContext + WORD() antlr.TerminalNode + // IsTypesContext differentiates from other interfaces. IsTypesContext() } type TypesContext struct { - *antlr.BaseParserRuleContext + antlr.BaseParserRuleContext parser antlr.Parser } func NewEmptyTypesContext() *TypesContext { var p = new(TypesContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) p.RuleIndex = BooleanExpressionParserRULE_types return p } +func InitEmptyTypesContext(p *TypesContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = BooleanExpressionParserRULE_types +} + func (*TypesContext) IsTypesContext() {} func NewTypesContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypesContext { var p = new(TypesContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) p.parser = parser p.RuleIndex = BooleanExpressionParserRULE_types @@ -1631,72 +2062,84 @@ func (s *TypesContext) ExitRule(listener antlr.ParseTreeListener) { } func (p *BooleanExpressionParser) Types() (localctx ITypesContext) { - this := p - _ = this - localctx = NewTypesContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 10, BooleanExpressionParserRULE_types) - - defer func() { - p.ExitRule() - }() - - defer func() { - if err := recover(); err != nil { - if v, ok := err.(antlr.RecognitionException); ok { - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - } else { - panic(err) - } - } - }() - - p.SetState(95) + p.EnterRule(localctx, 12, BooleanExpressionParserRULE_types) + p.SetState(112) p.GetErrorHandler().Sync(p) - switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 8, p.GetParserRuleContext()) { + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 12, p.GetParserRuleContext()) { case 1: p.EnterOuterAlt(localctx, 1) { - p.SetState(89) + p.SetState(106) p.Match(BooleanExpressionParserINTEGER) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } case 2: p.EnterOuterAlt(localctx, 2) { - p.SetState(90) + p.SetState(107) p.Match(BooleanExpressionParserDECIMAL) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } case 3: p.EnterOuterAlt(localctx, 3) { - p.SetState(91) + p.SetState(108) p.Match(BooleanExpressionParserAPP_VERSION) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } case 4: p.EnterOuterAlt(localctx, 4) { - p.SetState(92) + p.SetState(109) p.Bool_() } case 5: p.EnterOuterAlt(localctx, 5) { - p.SetState(93) + p.SetState(110) p.Match(BooleanExpressionParserWORD) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } } case 6: p.EnterOuterAlt(localctx, 6) + case antlr.ATNInvalidAltNumber: + goto errorExit } +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() return localctx + goto errorExit // Trick to prevent compiler error if the label is not used } // IBinaryContext is an interface to support dynamic dispatch. @@ -1706,28 +2149,37 @@ type IBinaryContext interface { // GetParser returns the parser. GetParser() antlr.Parser + // Getter signatures + AND() antlr.TerminalNode + OR() antlr.TerminalNode + // IsBinaryContext differentiates from other interfaces. IsBinaryContext() } type BinaryContext struct { - *antlr.BaseParserRuleContext + antlr.BaseParserRuleContext parser antlr.Parser } func NewEmptyBinaryContext() *BinaryContext { var p = new(BinaryContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) p.RuleIndex = BooleanExpressionParserRULE_binary return p } +func InitEmptyBinaryContext(p *BinaryContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = BooleanExpressionParserRULE_binary +} + func (*BinaryContext) IsBinaryContext() {} func NewBinaryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *BinaryContext { var p = new(BinaryContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) p.parser = parser p.RuleIndex = BooleanExpressionParserRULE_binary @@ -1766,32 +2218,13 @@ func (s *BinaryContext) ExitRule(listener antlr.ParseTreeListener) { } func (p *BooleanExpressionParser) Binary() (localctx IBinaryContext) { - this := p - _ = this - localctx = NewBinaryContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 12, BooleanExpressionParserRULE_binary) + p.EnterRule(localctx, 14, BooleanExpressionParserRULE_binary) var _la int - defer func() { - p.ExitRule() - }() - - defer func() { - if err := recover(); err != nil { - if v, ok := err.(antlr.RecognitionException); ok { - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - } else { - panic(err) - } - } - }() - p.EnterOuterAlt(localctx, 1) { - p.SetState(97) + p.SetState(114) _la = p.GetTokenStream().LA(1) if !(_la == BooleanExpressionParserAND || _la == BooleanExpressionParserOR) { @@ -1802,7 +2235,17 @@ func (p *BooleanExpressionParser) Binary() (localctx IBinaryContext) { } } +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() return localctx + goto errorExit // Trick to prevent compiler error if the label is not used } // IBoolContext is an interface to support dynamic dispatch. @@ -1812,28 +2255,37 @@ type IBoolContext interface { // GetParser returns the parser. GetParser() antlr.Parser + // Getter signatures + TRUE() antlr.TerminalNode + FALSE() antlr.TerminalNode + // IsBoolContext differentiates from other interfaces. IsBoolContext() } type BoolContext struct { - *antlr.BaseParserRuleContext + antlr.BaseParserRuleContext parser antlr.Parser } func NewEmptyBoolContext() *BoolContext { var p = new(BoolContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) p.RuleIndex = BooleanExpressionParserRULE_bool return p } +func InitEmptyBoolContext(p *BoolContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = BooleanExpressionParserRULE_bool +} + func (*BoolContext) IsBoolContext() {} func NewBoolContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *BoolContext { var p = new(BoolContext) - p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) p.parser = parser p.RuleIndex = BooleanExpressionParserRULE_bool @@ -1872,32 +2324,13 @@ func (s *BoolContext) ExitRule(listener antlr.ParseTreeListener) { } func (p *BooleanExpressionParser) Bool_() (localctx IBoolContext) { - this := p - _ = this - localctx = NewBoolContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 14, BooleanExpressionParserRULE_bool) + p.EnterRule(localctx, 16, BooleanExpressionParserRULE_bool) var _la int - defer func() { - p.ExitRule() - }() - - defer func() { - if err := recover(); err != nil { - if v, ok := err.(antlr.RecognitionException); ok { - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - } else { - panic(err) - } - } - }() - p.EnterOuterAlt(localctx, 1) { - p.SetState(99) + p.SetState(116) _la = p.GetTokenStream().LA(1) if !(_la == BooleanExpressionParserTRUE || _la == BooleanExpressionParserFALSE) { @@ -1908,7 +2341,17 @@ func (p *BooleanExpressionParser) Bool_() (localctx IBoolContext) { } } +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() return localctx + goto errorExit // Trick to prevent compiler error if the label is not used } func (p *BooleanExpressionParser) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool { @@ -1926,15 +2369,12 @@ func (p *BooleanExpressionParser) Sempred(localctx antlr.RuleContext, ruleIndex, } func (p *BooleanExpressionParser) Expression_Sempred(localctx antlr.RuleContext, predIndex int) bool { - this := p - _ = this - switch predIndex { case 0: - return p.Precpred(p.GetParserRuleContext(), 5) + return p.Precpred(p.GetParserRuleContext(), 6) case 1: - return p.Precpred(p.GetParserRuleContext(), 4) + return p.Precpred(p.GetParserRuleContext(), 5) default: panic("No predicate with index: " + fmt.Sprint(predIndex)) diff --git a/internal/parser/antlr/listener.go b/internal/parser/antlr/listener.go index 74055cd..ec85a85 100644 --- a/internal/parser/antlr/listener.go +++ b/internal/parser/antlr/listener.go @@ -1,7 +1,7 @@ package parser import ( - "github.com/antlr/antlr4/runtime/Go/antlr/v4" + "github.com/antlr4-go/antlr/v4" "github.com/sidhant92/bool-parser-go/internal/parser/antlr/lib" "github.com/sidhant92/bool-parser-go/internal/service" "github.com/sidhant92/bool-parser-go/internal/util" @@ -138,18 +138,7 @@ func (l *myListener) ExitInExpression(c *lib.InExpressionContext) { l.ValidateField(c.GetField(), c.GetText()) field := l.GetField(c.GetField().GetText()) - typesContextFilter := func(tree antlr.Tree) bool { return reflect.TypeOf(tree) == reflect.TypeOf(&lib.TypesContext{}) } - var typesContextChildren = util.Filter(c.GetData().GetChildren(), typesContextFilter) - var pairs []domain.Pair - - for _, child := range typesContextChildren { - dataType := GetDataType(child.(*lib.TypesContext).GetStart()) - value, _ := util.ConvertValue(child.(*lib.TypesContext).GetText(), dataType) - pairs = append(pairs, domain.Pair{ - DataType: dataType, - Value: value, - }) - } + pairs := l.GetArrayElements(c.GetData().GetChildren()) l.push(domain.InNode{ Field: field, @@ -157,6 +146,18 @@ func (l *myListener) ExitInExpression(c *lib.InExpressionContext) { }) } +func (l *myListener) ExitArrayExpression(ctx *lib.ArrayExpressionContext) { + l.ValidateField(ctx.GetField(), ctx.GetText()) + field := l.GetField(ctx.GetField().GetText()) + pairs := l.GetArrayElements(ctx.GetData().GetChildren()) + operator := l.OperatorService.GetOperatorFromSymbol(ctx.GetOp().GetText()) + l.push(domain.ArrayNode{ + Field: field, + Operator: operator, + Items: pairs, + }) +} + func (l *myListener) ExitToExpression(c *lib.ToExpressionContext) { l.ValidateField(c.GetField(), c.GetText()) field := l.GetField(c.GetField().GetText()) @@ -206,6 +207,8 @@ func (l *myListener) ExitComparatorExpression(c *lib.ComparatorExpressionContext }) } +func (l *myListener) EnterArrayExpression(ctx *lib.ArrayExpressionContext) {} + func (l myListener) ExitParentExpression(c *lib.ParentExpressionContext) { } @@ -227,6 +230,10 @@ func (l myListener) ExitBinary(c *lib.BinaryContext) { func (l myListener) ExitBool(c *lib.BoolContext) { } +func (l myListener) EnterArrayOperators(ctx *lib.ArrayOperatorsContext) {} + +func (l myListener) ExitArrayOperators(ctx *lib.ArrayOperatorsContext) {} + func GetLogicalOperator(token antlr.Token) constant.LogicalOperatorType { switch token.GetTokenType() { case lib.BooleanExpressionLexerAND: @@ -255,7 +262,7 @@ func GetDataType(token antlr.Token) constant.DataType { } } -func (l myListener) ValidateField(token antlr.Token, text string) { +func (l myListener) ValidateField(token antlr.Token, text string) { if token == nil || (len(token.GetText()) == 0 && len(text) == 0) { panic("Invalid Expression, field and default value both are empty") } @@ -267,3 +274,20 @@ func (l myListener) GetField(field string) string { } return field } + +func (l myListener) GetArrayElements(trees []antlr.Tree) []domain.Pair { + typesContextFilter := func(tree antlr.Tree) bool { return reflect.TypeOf(tree) == reflect.TypeOf(&lib.TypesContext{}) } + var typesContextChildren = util.Filter(trees, typesContextFilter) + var pairs []domain.Pair + + for _, child := range typesContextChildren { + dataType := GetDataType(child.(*lib.TypesContext).GetStart()) + value, _ := util.ConvertValue(child.(*lib.TypesContext).GetText(), dataType) + pairs = append(pairs, domain.Pair{ + DataType: dataType, + Value: value, + }) + } + + return pairs +} diff --git a/internal/service/operator_service.go b/internal/service/operator_service.go index 1da62d2..cc6270c 100644 --- a/internal/service/operator_service.go +++ b/internal/service/operator_service.go @@ -1,8 +1,13 @@ package service import ( + "github.com/sidhant92/bool-parser-go/internal/containerdatatype" op "github.com/sidhant92/bool-parser-go/internal/operator" "github.com/sidhant92/bool-parser-go/pkg/constant" + errors2 "github.com/sidhant92/bool-parser-go/pkg/error" + "log" + "slices" + "strings" ) type OperatorService struct { @@ -10,14 +15,27 @@ type OperatorService struct { } func (o *OperatorService) GetOperatorFromSymbol(symbol string) constant.Operator { - if val, ok := o.symbolMap[symbol]; ok { + if val, ok := o.symbolMap[strings.ToLower(symbol)]; ok { return val } panic("Unknown Operator " + symbol) } -func (o *OperatorService) Evaluate(operator constant.Operator, dataType constant.DataType, leftOperand interface{}, rightOperand ...interface{}) (bool, error) { - res, err := op.GetOperator(operator).Evaluate(dataType, leftOperand, rightOperand...) +func (o *OperatorService) Evaluate(operator constant.Operator, containerDataType constant.ContainerDataType, dataType constant.DataType, leftOperand interface{}, rightOperand ...interface{}) (bool, error) { + var abstractOperator = op.GetOperator(operator) + if !slices.Contains(abstractOperator.GetAllowedContainerTypes(), containerDataType) { + log.Printf("Invalid container type %s for the the operator %s", containerDataType, operator) + return false, errors2.INVALID_CONTAINER_DATA_TYPE + } + if !slices.Contains(abstractOperator.GetAllowedDataTypes(), dataType) { + log.Printf("Invalid data type %s for the the operator %s", dataType, operator) + return false, errors2.INVALID_DATA_TYPE + } + if !containerdatatype.GetContainerDataType(containerDataType).IsValid(dataType, leftOperand) { + log.Printf("validation failed for the operator %s for the the operand %v", operator, leftOperand) + return false, errors2.INVALID_DATA_TYPE + } + res, err := abstractOperator.Evaluate(containerDataType, dataType, true, leftOperand, rightOperand...) if err != nil { return false, err } @@ -28,7 +46,7 @@ func NewOperatorService() *OperatorService { allOperators := op.GetAllValues() symbolMap := map[string]constant.Operator{} for _, op := range allOperators { - symbolMap[op.GetSymbol()] = op.GetOperator() + symbolMap[strings.ToLower(op.GetSymbol())] = op.GetOperator() } return &OperatorService{symbolMap} } diff --git a/internal/util/helper_functions.go b/internal/util/helper_functions.go index f491be3..b1b6235 100644 --- a/internal/util/helper_functions.go +++ b/internal/util/helper_functions.go @@ -1,5 +1,7 @@ package util +import "reflect" + func Filter[T any](ss []T, test func(T) bool) (ret []T) { for _, s := range ss { if test(s) { @@ -8,3 +10,18 @@ func Filter[T any](ss []T, test func(T) bool) (ret []T) { } return } + +func IsSlice(v interface{}) bool { + return reflect.TypeOf(v).Kind() == reflect.Slice +} + +func GetSliceFromInterface(value interface{}) []interface{} { + var slice []interface{} + rv := reflect.ValueOf(value) + if rv.Kind() == reflect.Slice { + for i := 0; i < rv.Len(); i++ { + slice = append(slice, rv.Index(i).Interface()) + } + } + return slice +} \ No newline at end of file diff --git a/pkg/application/boolean_expression_evaluator.go b/pkg/application/boolean_expression_evaluator.go index 7d17a46..a92481c 100644 --- a/pkg/application/boolean_expression_evaluator.go +++ b/pkg/application/boolean_expression_evaluator.go @@ -35,6 +35,8 @@ func (b *BooleanExpressionEvaluator) evaluateNode(node domain.Node, data map[str return b.evaluateUnaryNode(node.(domain.UnaryNode), data) case constant.BOOLEAN_NODE: return b.evaluateBooleanNode(node.(domain.BooleanNode), data) + case constant.ARRAY_NODE: + return b.evaluateArrayNode(node.(domain.ArrayNode), data) default: return false, errors.New("unknown node") } @@ -45,7 +47,7 @@ func (b *BooleanExpressionEvaluator) evaluateComparisonNode(node domain.Comparis if fieldData == nil { return false, errors2.KEY_DATA_NOT_PRESENT } - return b.OperatorService.Evaluate(node.Operator, node.DataType, fieldData, node.Value) + return b.OperatorService.Evaluate(node.Operator, constant.PRIMITIVE, node.DataType, fieldData, node.Value) } func (b *BooleanExpressionEvaluator) evaluateNumericRangeNode(node domain.NumericRangeNode, data map[string]interface{}) (bool, error) { @@ -53,11 +55,11 @@ func (b *BooleanExpressionEvaluator) evaluateNumericRangeNode(node domain.Numeri if fieldData == nil { return false, errors2.KEY_DATA_NOT_PRESENT } - leftRes, err := b.OperatorService.Evaluate(constant.GREATER_THAN_EQUAL, node.FromDataType, fieldData, node.FromValue) + leftRes, err := b.OperatorService.Evaluate(constant.GREATER_THAN_EQUAL, constant.PRIMITIVE, node.FromDataType, fieldData, node.FromValue) if err != nil { return false, err } - rightRes, err := b.OperatorService.Evaluate(constant.LESS_THAN_EQUAL, node.ToDataType, fieldData, node.ToValue) + rightRes, err := b.OperatorService.Evaluate(constant.LESS_THAN_EQUAL, constant.PRIMITIVE, node.ToDataType, fieldData, node.ToValue) if err != nil { return false, err } @@ -74,7 +76,7 @@ func (b *BooleanExpressionEvaluator) evaluateInNode(node domain.InNode, data map for _, item := range node.Items { values = append(values, item.Value) } - res, err := b.OperatorService.Evaluate(constant.IN, dataType, fieldData, values...) + res, err := b.OperatorService.Evaluate(constant.IN, constant.PRIMITIVE, dataType, fieldData, values...) if err != nil { return false, err } @@ -127,6 +129,23 @@ func (b *BooleanExpressionEvaluator) evaluateBooleanNode(node domain.BooleanNode } } +func (b *BooleanExpressionEvaluator) evaluateArrayNode(node domain.ArrayNode, data map[string]interface{}) (bool, error) { + fieldData := util.GetValueFromMap(node.Field, data) + if fieldData == nil { + return false, errors2.KEY_DATA_NOT_PRESENT + } + dataType := node.Items[0].DataType + var values []interface{} + for _, item := range node.Items { + values = append(values, item.Value) + } + res, err := b.OperatorService.Evaluate(node.Operator, constant.LIST, dataType, fieldData, values...) + if err != nil { + return false, err + } + return res, nil +} + func NewBooleanExpressionEvaluator(parser parser.Parser) BooleanExpressionEvaluator { return BooleanExpressionEvaluator{parser, service.NewOperatorService()} } diff --git a/pkg/application/boolean_expression_evaluator_test.go b/pkg/application/boolean_expression_evaluator_test.go index bc3642d..6933316 100644 --- a/pkg/application/boolean_expression_evaluator_test.go +++ b/pkg/application/boolean_expression_evaluator_test.go @@ -427,3 +427,48 @@ func TestDefaultFieldFalse(t *testing.T) { assert.Nil(t, err) assert.False(t, res) } + +func TestContainsAnyTrueCondition(t *testing.T) { + data := map[string]interface{}{ + "age": []int32{1, 2, 3}, + } + res, err := evaluator.Evaluate("age contains_any (2)", data) + assert.Nil(t, err) + assert.True(t, res) +} + +func TestContainsAnyFalseCondition(t *testing.T) { + data := map[string]interface{}{ + "age": []int32{1, 2, 3}, + } + res, err := evaluator.Evaluate("age contains_any (12)", data) + assert.Nil(t, err) + assert.False(t, res) +} + +func TestContainsAllTrueCondition(t *testing.T) { + data := map[string]interface{}{ + "age": []int32{1, 2, 3}, + } + res, err := evaluator.Evaluate("age contains_all (1,2)", data) + assert.Nil(t, err) + assert.True(t, res) +} + +func TestContainsAllFalseCondition(t *testing.T) { + data := map[string]interface{}{ + "age": []int32{1, 2, 3}, + } + res, err := evaluator.Evaluate("age contains_all (2,5)", data) + assert.Nil(t, err) + assert.False(t, res) +} + +func TestContainsAllFailureCondition(t *testing.T) { + data := map[string]interface{}{ + "age": "sid", + } + _, err := evaluator.Evaluate("age contains_all (2,5)", data) + assert.NotNil(t, err) + assert.ErrorIs(t, err, errors2.INVALID_DATA_TYPE) +} diff --git a/pkg/constant/container_data_type.go b/pkg/constant/container_data_type.go new file mode 100644 index 0000000..0999a2f --- /dev/null +++ b/pkg/constant/container_data_type.go @@ -0,0 +1,8 @@ +package constant + +type ContainerDataType string + +const ( + PRIMITIVE ContainerDataType = "PRIMITIVE" + LIST ContainerDataType = "LIST" +) diff --git a/pkg/constant/node_type.go b/pkg/constant/node_type.go index e93e2cf..30e71ee 100644 --- a/pkg/constant/node_type.go +++ b/pkg/constant/node_type.go @@ -3,9 +3,10 @@ package constant type NodeType string const ( - BOOLEAN_NODE NodeType = "BOOLEAN_NODE" + BOOLEAN_NODE NodeType = "BOOLEAN_NODE" COMPARISON_NODE NodeType = "COMPARISON_NODE" NUMERIC_RANGE_NODE NodeType = "NUMERIC_RANGE_NODE" IN_NODE NodeType = "IN_NODE" - UNARY_NODE NodeType = "UNARY_NODE" + ARRAY_NODE NodeType = "ARRAY_NODE" + UNARY_NODE NodeType = "UNARY_NODE" ) diff --git a/pkg/constant/operator.go b/pkg/constant/operator.go index fe8a3fc..5bf4a0a 100644 --- a/pkg/constant/operator.go +++ b/pkg/constant/operator.go @@ -10,5 +10,6 @@ const ( LESS_THAN_EQUAL Operator = "LESS_THAN_EQUAL" NOT_EQUAL Operator = "NOT_EQUAL" IN Operator = "IN" + CONTAINS_ANY Operator = "CONTAINS_ANY" + CONTAINS_ALL Operator = "CONTAINS_ALL" ) - diff --git a/pkg/domain/array_node.go b/pkg/domain/array_node.go new file mode 100644 index 0000000..c5c5fbd --- /dev/null +++ b/pkg/domain/array_node.go @@ -0,0 +1,13 @@ +package domain + +import "github.com/sidhant92/bool-parser-go/pkg/constant" + +type ArrayNode struct { + Field string + Operator constant.Operator + Items []Pair +} + +func (c ArrayNode) GetNodeType() constant.NodeType { + return constant.ARRAY_NODE +} diff --git a/pkg/error/errors.go b/pkg/error/errors.go index 2c4d9e3..46e0a67 100644 --- a/pkg/error/errors.go +++ b/pkg/error/errors.go @@ -4,6 +4,8 @@ import "errors" var INVALID_DATA_TYPE = errors.New("invalid data type") +var INVALID_CONTAINER_DATA_TYPE = errors.New("invalid container data type") + var INVALID_UNARY_OPERAND = errors.New("invalid unary operand") var KEY_DATA_NOT_PRESENT = errors.New("key data not present") From 4195350476f0d67c94fe149e8f9548db8604275e Mon Sep 17 00:00:00 2001 From: Sidhant Aggarwal <10743214+sidhant92@users.noreply.github.com> Date: Tue, 7 Nov 2023 18:20:49 +0530 Subject: [PATCH 2/4] add not in support --- internal/parser/antlr/antlr_parser_test.go | 13 +++++++++++++ internal/parser/antlr/listener.go | 15 ++++++++++++--- .../boolean_expression_evaluator_test.go | 9 +++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/internal/parser/antlr/antlr_parser_test.go b/internal/parser/antlr/antlr_parser_test.go index 7f18b8b..fb7b8b3 100644 --- a/internal/parser/antlr/antlr_parser_test.go +++ b/internal/parser/antlr/antlr_parser_test.go @@ -218,6 +218,19 @@ func TestIntegerList(t *testing.T) { assert.Equal(t, res.(domain.InNode).Items[1].Value, 45) } +func TestIntegerNotInList(t *testing.T) { + res, _ := parser.Parse("age not IN (12,45)") + assert.Equal(t, res.GetNodeType(), constant.BOOLEAN_NODE) + assert.Equal(t, res.(domain.BooleanNode).Operator, constant.NOT) + assert.Nil(t, res.(domain.BooleanNode).Right) + assert.Equal(t, res.(domain.BooleanNode).Left.GetNodeType(), constant.IN_NODE) + assert.Equal(t, res.(domain.BooleanNode).Left.(domain.InNode).Field, "age") + assert.Equal(t, res.(domain.BooleanNode).Left.(domain.InNode).Items[0].DataType, constant.INTEGER) + assert.Equal(t, res.(domain.BooleanNode).Left.(domain.InNode).Items[0].Value, 12) + assert.Equal(t, res.(domain.BooleanNode).Left.(domain.InNode).Items[1].DataType, constant.INTEGER) + assert.Equal(t, res.(domain.BooleanNode).Left.(domain.InNode).Items[1].Value, 45) +} + func TestStringList(t *testing.T) { res, _ := parser.Parse("name IN (abc, def, 'abc def')") assert.Equal(t, res.GetNodeType(), constant.IN_NODE) diff --git a/internal/parser/antlr/listener.go b/internal/parser/antlr/listener.go index ec85a85..6f1b0b0 100644 --- a/internal/parser/antlr/listener.go +++ b/internal/parser/antlr/listener.go @@ -139,11 +139,20 @@ func (l *myListener) ExitInExpression(c *lib.InExpressionContext) { field := l.GetField(c.GetField().GetText()) pairs := l.GetArrayElements(c.GetData().GetChildren()) - - l.push(domain.InNode{ + var inNode = domain.InNode{ Field: field, Items: pairs, - }) + } + if c.NOT() == nil { + l.push(inNode) + } else { + var booleanNode = domain.BooleanNode{ + Left: inNode, + Right: nil, + Operator: constant.NOT, + } + l.push(booleanNode) + } } func (l *myListener) ExitArrayExpression(ctx *lib.ArrayExpressionContext) { diff --git a/pkg/application/boolean_expression_evaluator_test.go b/pkg/application/boolean_expression_evaluator_test.go index 6933316..33b0a66 100644 --- a/pkg/application/boolean_expression_evaluator_test.go +++ b/pkg/application/boolean_expression_evaluator_test.go @@ -280,6 +280,15 @@ func TestPositiveInClauseForDecimals(t *testing.T) { assert.True(t, res) } +func TestPositiveNotInClauseForDecimals(t *testing.T) { + data := map[string]interface{}{ + "num": 25.3, + } + res, err := evaluator.Evaluate("num not in (26.3,26.3,34.4)", data) + assert.Nil(t, err) + assert.True(t, res) +} + func TestNegativeInClauseForStrings(t *testing.T) { data := map[string]interface{}{ "name": "test", From 3775531738ebdac4c5ff6fddb76be5a42a1a7d7f Mon Sep 17 00:00:00 2001 From: Sidhant Aggarwal <10743214+sidhant92@users.noreply.github.com> Date: Tue, 7 Nov 2023 18:25:39 +0530 Subject: [PATCH 3/4] upgrade go --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 911ca13..8d43ede 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/sidhant92/bool-parser-go -go 1.20 +go 1.21 require ( github.com/antlr4-go/antlr v0.0.0-20230518091524-98b52378c522 From d2917d86862f3786fbdf1faf26302542fb001009 Mon Sep 17 00:00:00 2001 From: Sidhant Aggarwal <10743214+sidhant92@users.noreply.github.com> Date: Tue, 7 Nov 2023 18:26:34 +0530 Subject: [PATCH 4/4] upgrade go --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d01ce23..9a73d71 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,7 +17,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v2 with: - go-version: '1.20' + go-version: '1.21' - name: Build run: make build