Skip to content

Commit

Permalink
Move ValueTypeMap to types package
Browse files Browse the repository at this point in the history
  • Loading branch information
richardmarshall committed Dec 21, 2023
1 parent f3bc026 commit 072af7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
12 changes: 0 additions & 12 deletions linter/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,6 @@ var DirectorPropertyTypes = map[string]DirectorProps{
},
}

var ValueTypeMap = map[string]types.Type{
"INTEGER": types.IntegerType,
"FLOAT": types.FloatType,
"BOOL": types.BoolType,
"ACL": types.AclType,
"BACKEND": types.BackendType,
"IP": types.IPType,
"STRING": types.StringType,
"RTIME": types.RTimeType,
"TIME": types.TimeType,
}

func isAlphaNumeric(r rune) bool {
return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_'
}
Expand Down
10 changes: 5 additions & 5 deletions linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func (l *Linter) factoryRootDeclarations(statements []ast.Statement, ctx *contex
if t.ValueType == nil {
table.ValueType = types.StringType // default as STRING (e.g. Edge Dictionary)
} else {
v, ok := ValueTypeMap[t.ValueType.Value]
v, ok := types.ValueTypeMap[t.ValueType.Value]
if !ok {
l.Error(UndefinedTableType(
t.ValueType.GetMeta(), t.Name.Value, t.ValueType.Value,
Expand Down Expand Up @@ -473,7 +473,7 @@ func (l *Linter) factoryRootDeclarations(statements []ast.Statement, ctx *contex
l.Error(err.Match(SUBROUTINE_INVALID_RETURN_TYPE))
}

returnType, ok := ValueTypeMap[t.ReturnType.Value]
returnType, ok := types.ValueTypeMap[t.ReturnType.Value]
if !ok {
err := &LintError{
Severity: ERROR,
Expand Down Expand Up @@ -760,7 +760,7 @@ func (l *Linter) lintTableDeclaration(decl *ast.TableDeclaration, ctx *context.C
var valueType types.Type
if decl.ValueType == nil {
valueType = types.StringType
} else if v, ok := ValueTypeMap[decl.ValueType.Value]; ok {
} else if v, ok := types.ValueTypeMap[decl.ValueType.Value]; ok {
valueType = v
}

Expand Down Expand Up @@ -813,7 +813,7 @@ func (l *Linter) lintSubRoutineDeclaration(decl *ast.SubroutineDeclaration, ctx
scope := getSubroutineCallScope(decl)
var cc *context.Context
if decl.ReturnType != nil {
returnType := ValueTypeMap[decl.ReturnType.Value]
returnType := types.ValueTypeMap[decl.ReturnType.Value]
cc = ctx.UserDefinedFunctionScope(decl.Name.Value, scope, returnType)
} else {
cc = ctx.Scope(scope)
Expand Down Expand Up @@ -987,7 +987,7 @@ func (l *Linter) lintDeclareStatement(stmt *ast.DeclareStatement, ctx *context.C
l.Error(err.Match(DECLARE_STATEMENT_SYNTAX))
}

vt, ok := ValueTypeMap[stmt.ValueType.Value]
vt, ok := types.ValueTypeMap[stmt.ValueType.Value]
if !ok {
err := &LintError{
Severity: ERROR,
Expand Down
12 changes: 12 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ const (
ReqBackendType Type = 0x100000000010000
)

var ValueTypeMap = map[string]Type{
"INTEGER": IntegerType,
"FLOAT": FloatType,
"BOOL": BoolType,
"ACL": AclType,
"BACKEND": BackendType,
"IP": IPType,
"STRING": StringType,
"RTIME": RTimeType,
"TIME": TimeType,
}

func (t Type) String() string {
switch t {
case NeverType:
Expand Down

0 comments on commit 072af7c

Please sign in to comment.