Skip to content

Commit cf889e1

Browse files
authored
Merge pull request #15 from sidhant92/develop
Array Support
2 parents a4e46d3 + a8c8e65 commit cf889e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1591
-626
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup Go
1818
uses: actions/setup-go@v2
1919
with:
20-
go-version: '1.20'
20+
go-version: '1.21'
2121

2222
- name: Build
2323
run: make build

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
module github.com/sidhant92/bool-parser-go
22

3-
go 1.20
3+
go 1.21
44

55
require (
6-
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12
6+
github.com/antlr4-go/antlr v0.0.0-20230518091524-98b52378c522
7+
github.com/antlr4-go/antlr/v4 v4.13.0
78
github.com/hashicorp/go-version v1.6.0
9+
github.com/hashicorp/golang-lru/v2 v2.0.1
810
github.com/stretchr/testify v1.8.1
911
)
1012

1113
require (
1214
github.com/davecgh/go-spew v1.1.1 // indirect
13-
github.com/hashicorp/golang-lru/v2 v2.0.1 // indirect
1415
github.com/pmezard/go-difflib v1.0.0 // indirect
15-
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
16+
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
1617
gopkg.in/yaml.v3 v3.0.1 // indirect
1718
)

go.sum

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12 h1:npHgfD4Tl2WJS3AJaMUi5ynGDPUBfkg3U3fCzDyXZ+4=
2-
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
1+
github.com/antlr4-go/antlr v0.0.0-20230518091524-98b52378c522 h1:o+W7GDFUwWtVkN28CW/nhh/aCmHn6OJddUs3+8vMMjs=
2+
github.com/antlr4-go/antlr v0.0.0-20230518091524-98b52378c522/go.mod h1:srLVvW4JLxy+tCG9Nn2l8al77mUIMCwAOLQocfLDU2w=
3+
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
4+
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
35
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
46
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
57
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/
1618
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
1719
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
1820
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
19-
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
20-
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
21+
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU=
22+
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
23+
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
24+
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
2125
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2226
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2327
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package containerdatatype
2+
3+
import (
4+
"github.com/sidhant92/bool-parser-go/pkg/constant"
5+
)
6+
7+
type ContainerDataType interface {
8+
IsValid(dataType constant.DataType, value interface{}) bool
9+
10+
GetContainerDataType() constant.ContainerDataType
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package containerdatatype
2+
3+
import (
4+
"github.com/sidhant92/bool-parser-go/pkg/constant"
5+
"golang.org/x/exp/maps"
6+
)
7+
8+
var containerDataTypeMap = map[constant.ContainerDataType]ContainerDataType{
9+
constant.PRIMITIVE: NewPrimitiveContainerDataType(),
10+
constant.LIST: NewListContainerDataType(),
11+
}
12+
13+
func GetContainerDataType(containerDataType constant.ContainerDataType) ContainerDataType {
14+
return containerDataTypeMap[containerDataType]
15+
}
16+
17+
func GetAllDataTypes() []ContainerDataType {
18+
return maps.Values(containerDataTypeMap)
19+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package containerdatatype
2+
3+
import (
4+
"github.com/sidhant92/bool-parser-go/internal/datatype"
5+
"github.com/sidhant92/bool-parser-go/internal/util"
6+
"github.com/sidhant92/bool-parser-go/pkg/constant"
7+
)
8+
9+
type ListContainerDataType struct {
10+
}
11+
12+
func (s *ListContainerDataType) GetContainerDataType() constant.ContainerDataType {
13+
return constant.LIST
14+
}
15+
16+
func (s *ListContainerDataType) IsValid(dataType constant.DataType, value interface{}) bool {
17+
if !util.IsSlice(value) {
18+
return false
19+
}
20+
var slice = util.GetSliceFromInterface(value)
21+
for _, value := range slice {
22+
if !datatype.GetDataType(dataType).IsValid(value) {
23+
return false
24+
}
25+
}
26+
return true
27+
}
28+
29+
func NewListContainerDataType() ContainerDataType {
30+
return &ListContainerDataType{}
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package containerdatatype
2+
3+
import (
4+
"github.com/sidhant92/bool-parser-go/internal/datatype"
5+
"github.com/sidhant92/bool-parser-go/internal/util"
6+
"github.com/sidhant92/bool-parser-go/pkg/constant"
7+
)
8+
9+
type PrimitiveContainerDataType struct {
10+
}
11+
12+
func (s *PrimitiveContainerDataType) GetContainerDataType() constant.ContainerDataType {
13+
return constant.PRIMITIVE
14+
}
15+
16+
func (s *PrimitiveContainerDataType) IsValid(dataType constant.DataType, value interface{}) bool {
17+
if util.IsSlice(value) {
18+
return false
19+
}
20+
return datatype.GetDataType(dataType).IsValid(value)
21+
}
22+
23+
func NewPrimitiveContainerDataType() ContainerDataType {
24+
return &PrimitiveContainerDataType{}
25+
}

internal/datatype/boolean_data_type.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ func (s *BooleanDataType) GetValue(value interface{}) interface{} {
3939
return res
4040
}
4141

42-
func (s *BooleanDataType) Compare(left interface{}, right interface{}) (int, error) {
43-
leftValid := s.IsValid(left)
44-
rightValid := s.IsValid(right)
45-
if !leftValid || !rightValid {
46-
return 0, errors.INVALID_DATA_TYPE
42+
func (s *BooleanDataType) Compare(left interface{}, right interface{}, validated bool) (int, error) {
43+
if !validated {
44+
leftValid := s.IsValid(left)
45+
rightValid := s.IsValid(right)
46+
if !leftValid || !rightValid {
47+
return 0, errors.INVALID_DATA_TYPE
48+
}
4749
}
4850
leftValue := s.GetValue(left).(bool)
4951
rightValue := s.GetValue(right).(bool)

internal/datatype/data_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ type DataType interface {
99

1010
GetValue(value interface{}) any
1111

12-
Compare(left interface{}, right interface{}) (int, error)
12+
Compare(left interface{}, right interface{}, validated bool) (int, error)
1313
}

internal/datatype/data_type_factory.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package datatype
22

33
import (
44
"github.com/sidhant92/bool-parser-go/pkg/constant"
5+
"golang.org/x/exp/maps"
56
)
67

78
var dataTypeMap = map[constant.DataType]DataType{
@@ -16,3 +17,7 @@ var dataTypeMap = map[constant.DataType]DataType{
1617
func GetDataType(dataType constant.DataType) DataType {
1718
return dataTypeMap[dataType]
1819
}
20+
21+
func GetAllDataTypes() []DataType {
22+
return maps.Values(dataTypeMap)
23+
}

0 commit comments

Comments
 (0)