-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from sidhant92/develop
Array Support
- Loading branch information
Showing
43 changed files
with
1,591 additions
and
626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
module github.com/sidhant92/bool-parser-go | ||
|
||
go 1.20 | ||
go 1.21 | ||
|
||
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{} | ||
} |
25 changes: 25 additions & 0 deletions
25
internal/containerdatatype/primitive_container_data_type.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{} | ||
} |
Oops, something went wrong.