-
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 #21 from sidhant92/types_conversion
implicit conversion of data types
- Loading branch information
Showing
16 changed files
with
216 additions
and
56 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
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,41 @@ | ||
package operator | ||
|
||
import ( | ||
"github.com/sidhant92/bool-parser-go/internal/datatype" | ||
"github.com/sidhant92/bool-parser-go/pkg/constant" | ||
errors2 "github.com/sidhant92/bool-parser-go/pkg/error" | ||
"log" | ||
) | ||
|
||
func GetComparableDataType(leftOperandDataType constant.DataType, rightOperandDataType constant.DataType) constant.DataType { | ||
if (constant.DataTypeAttributes[leftOperandDataType].Numeric && !constant.DataTypeAttributes[rightOperandDataType].Numeric) || (!constant.DataTypeAttributes[leftOperandDataType].Numeric && constant.DataTypeAttributes[rightOperandDataType].Numeric) { | ||
if constant.DataTypeAttributes[leftOperandDataType].Numeric { | ||
return leftOperandDataType | ||
} | ||
return rightOperandDataType | ||
} | ||
if constant.DataTypeAttributes[leftOperandDataType].Priority > constant.DataTypeAttributes[rightOperandDataType].Priority { | ||
return leftOperandDataType | ||
} | ||
return rightOperandDataType | ||
} | ||
|
||
func Validate(leftOperand interface{}, leftOperandDataType constant.DataType, rightOperand interface{}, rightOperandDataType constant.DataType) error { | ||
if constant.DataTypeAttributes[leftOperandDataType].Numeric && constant.DataTypeAttributes[rightOperandDataType].Numeric { | ||
return nil | ||
} | ||
if !constant.DataTypeAttributes[leftOperandDataType].Numeric && !constant.DataTypeAttributes[rightOperandDataType].Numeric { | ||
return nil | ||
} | ||
rightDataType := datatype.GetDataType(rightOperandDataType) | ||
if !constant.DataTypeAttributes[leftOperandDataType].Numeric && !rightDataType.IsValid(leftOperand) { | ||
log.Printf("Incompatible data types %s and %s", leftOperandDataType, rightOperandDataType) | ||
return errors2.INCOMPATIBLE_DATA_TYPE | ||
} | ||
leftDataType := datatype.GetDataType(leftOperandDataType) | ||
if !constant.DataTypeAttributes[rightOperandDataType].Numeric && !leftDataType.IsValid(rightOperand) { | ||
log.Printf("Incompatible data types %s and %s", leftOperandDataType, rightOperandDataType) | ||
return errors2.INCOMPATIBLE_DATA_TYPE | ||
} | ||
return nil | ||
} |
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
Oops, something went wrong.