From 521215992d8726893e7bf2751f4183a511f6cabb Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Wed, 19 Jan 2022 02:51:53 +0100 Subject: [PATCH] Specify constant types except with iota (#884) Constant types need to be repeated, unless iota is used or the constants are declared in the same expression (const A, B, C Type = 1, 2, 3). See https://go.dev/ref/spec#Constant_declarations for details. Signed-off-by: Stephen Kitt --- internal/pkg/dsl/ast_types.go | 156 +++++++++--------- .../pkg/dsl/cst/builtin_function_manager.go | 20 +-- internal/pkg/dsl/cst/hofs.go | 6 +- internal/pkg/dsl/cst/types.go | 6 +- 4 files changed, 94 insertions(+), 94 deletions(-) diff --git a/internal/pkg/dsl/ast_types.go b/internal/pkg/dsl/ast_types.go index 9be481019..825b338e9 100644 --- a/internal/pkg/dsl/ast_types.go +++ b/internal/pkg/dsl/ast_types.go @@ -25,106 +25,106 @@ type TNodeType string const ( NodeTypeStringLiteral TNodeType = "string literal" - NodeTypeRegex = "regular expression" // not in the BNF -- written during CST pre-build pass - NodeTypeRegexCaseInsensitive = "case-insensitive regular expression" // E.g. "a.*b"i -- note the trailing 'i' - NodeTypeIntLiteral = "int literal" - NodeTypeFloatLiteral = "float literal" - NodeTypeBoolLiteral = "bool literal" - NodeTypeNullLiteral = "null literal" - NodeTypeArrayLiteral = "array literal" - NodeTypeMapLiteral = "map literal" - NodeTypeMapLiteralKeyValuePair = "map-literal key-value pair" - NodeTypeArrayOrMapIndexAccess = "array or map index access" - NodeTypeArraySliceAccess = "array-slice access" - NodeTypeArraySliceEmptyLowerIndex = "array-slice empty lower index" - NodeTypeArraySliceEmptyUpperIndex = "array-slice empty upper index" + NodeTypeRegex TNodeType = "regular expression" // not in the BNF -- written during CST pre-build pass + NodeTypeRegexCaseInsensitive TNodeType = "case-insensitive regular expression" // E.g. "a.*b"i -- note the trailing 'i' + NodeTypeIntLiteral TNodeType = "int literal" + NodeTypeFloatLiteral TNodeType = "float literal" + NodeTypeBoolLiteral TNodeType = "bool literal" + NodeTypeNullLiteral TNodeType = "null literal" + NodeTypeArrayLiteral TNodeType = "array literal" + NodeTypeMapLiteral TNodeType = "map literal" + NodeTypeMapLiteralKeyValuePair TNodeType = "map-literal key-value pair" + NodeTypeArrayOrMapIndexAccess TNodeType = "array or map index access" + NodeTypeArraySliceAccess TNodeType = "array-slice access" + NodeTypeArraySliceEmptyLowerIndex TNodeType = "array-slice empty lower index" + NodeTypeArraySliceEmptyUpperIndex TNodeType = "array-slice empty upper index" - NodeTypePositionalFieldName = "positionally-indexed field name" - NodeTypePositionalFieldValue = "positionally-indexed field value" - NodeTypeArrayOrMapPositionalNameAccess = "positionally-indexed map key" - NodeTypeArrayOrMapPositionalValueAccess = "positionally-indexed map value" + NodeTypePositionalFieldName TNodeType = "positionally-indexed field name" + NodeTypePositionalFieldValue TNodeType = "positionally-indexed field value" + NodeTypeArrayOrMapPositionalNameAccess TNodeType = "positionally-indexed map key" + NodeTypeArrayOrMapPositionalValueAccess TNodeType = "positionally-indexed map value" - NodeTypeContextVariable = "context variable" - NodeTypeConstant = "mathematical constant" - NodeTypeEnvironmentVariable = "environment variable" + NodeTypeContextVariable TNodeType = "context variable" + NodeTypeConstant TNodeType = "mathematical constant" + NodeTypeEnvironmentVariable TNodeType = "environment variable" - NodeTypeDirectFieldValue = "direct field value" - NodeTypeIndirectFieldValue = "indirect field value" - NodeTypeFullSrec = "full record" - NodeTypeDirectOosvarValue = "direct oosvar value" - NodeTypeIndirectOosvarValue = "indirect oosvar value" - NodeTypeFullOosvar = "full oosvar" - NodeTypeLocalVariable = "local variable" - NodeTypeTypedecl = "type declaration" + NodeTypeDirectFieldValue TNodeType = "direct field value" + NodeTypeIndirectFieldValue TNodeType = "indirect field value" + NodeTypeFullSrec TNodeType = "full record" + NodeTypeDirectOosvarValue TNodeType = "direct oosvar value" + NodeTypeIndirectOosvarValue TNodeType = "indirect oosvar value" + NodeTypeFullOosvar TNodeType = "full oosvar" + NodeTypeLocalVariable TNodeType = "local variable" + NodeTypeTypedecl TNodeType = "type declaration" - NodeTypeStatementBlock = "statement block" - NodeTypeAssignment = "assignment" - NodeTypeUnset = "unset" + NodeTypeStatementBlock TNodeType = "statement block" + NodeTypeAssignment TNodeType = "assignment" + NodeTypeUnset TNodeType = "unset" - NodeTypeBareBoolean = "bare boolean" - NodeTypeFilterStatement = "filter statement" + NodeTypeBareBoolean TNodeType = "bare boolean" + NodeTypeFilterStatement TNodeType = "filter statement" - NodeTypeTeeStatement = "tee statement" - NodeTypeEmit1Statement = "emit1 statement" - NodeTypeEmitStatement = "emit statement" - NodeTypeEmitPStatement = "emitp statement" - NodeTypeEmitFStatement = "emitf statement" - NodeTypeEmittableList = "emittable list" - NodeTypeEmitKeys = "emit keys" - NodeTypeDumpStatement = "dump statement" - NodeTypeEdumpStatement = "edump statement" - NodeTypePrintStatement = "print statement" - NodeTypeEprintStatement = "eprint statement" - NodeTypePrintnStatement = "printn statement" - NodeTypeEprintnStatement = "eprintn statement" + NodeTypeTeeStatement TNodeType = "tee statement" + NodeTypeEmit1Statement TNodeType = "emit1 statement" + NodeTypeEmitStatement TNodeType = "emit statement" + NodeTypeEmitPStatement TNodeType = "emitp statement" + NodeTypeEmitFStatement TNodeType = "emitf statement" + NodeTypeEmittableList TNodeType = "emittable list" + NodeTypeEmitKeys TNodeType = "emit keys" + NodeTypeDumpStatement TNodeType = "dump statement" + NodeTypeEdumpStatement TNodeType = "edump statement" + NodeTypePrintStatement TNodeType = "print statement" + NodeTypeEprintStatement TNodeType = "eprint statement" + NodeTypePrintnStatement TNodeType = "printn statement" + NodeTypeEprintnStatement TNodeType = "eprintn statement" // For 'print > filename, "string"' et al. - NodeTypeRedirectWrite = "redirect write" - NodeTypeRedirectAppend = "redirect append" - NodeTypeRedirectPipe = "redirect pipe" - NodeTypeRedirectTargetStdout = "stdout redirect target" - NodeTypeRedirectTargetStderr = "stderr redirect target" - NodeTypeRedirectTarget = "redirect target" + NodeTypeRedirectWrite TNodeType = "redirect write" + NodeTypeRedirectAppend TNodeType = "redirect append" + NodeTypeRedirectPipe TNodeType = "redirect pipe" + NodeTypeRedirectTargetStdout TNodeType = "stdout redirect target" + NodeTypeRedirectTargetStderr TNodeType = "stderr redirect target" + NodeTypeRedirectTarget TNodeType = "redirect target" // This helps various emit-variant sub-ASTs have the same shape. For // example, in 'emit > "foo.txt", @v' and 'emit @v', the latter has a no-op // for its redirect target. - NodeTypeNoOp = "no-op" + NodeTypeNoOp TNodeType = "no-op" // The dot operator is a little different from other operators since it's // type-dependent: for strings/int/bools etc it's just concatenation of // string representations, but if the left-hand side is a map, it's a // key-lookup with an unquoted literal on the right. E.g. mymap.foo is the // same as mymap["foo"]. - NodeTypeOperator = "operator" - NodeTypeDotOperator = "dot operator" - NodeTypeFunctionCallsite = "function callsite" - NodeTypeSubroutineCallsite = "subroutine callsite" + NodeTypeOperator TNodeType = "operator" + NodeTypeDotOperator TNodeType = "dot operator" + NodeTypeFunctionCallsite TNodeType = "function callsite" + NodeTypeSubroutineCallsite TNodeType = "subroutine callsite" - NodeTypeBeginBlock = "begin block" - NodeTypeEndBlock = "end block" - NodeTypeIfChain = "if-chain" - NodeTypeIfItem = "if-item" - NodeTypeCondBlock = "cond block" - NodeTypeWhileLoop = "while loop" - NodeTypeDoWhileLoop = "do-while`loop" - NodeTypeForLoopOneVariable = "single-variable for-loop" - NodeTypeForLoopTwoVariable = "double-variable for-loop" - NodeTypeForLoopMultivariable = "multi-variable for-loop" - NodeTypeTripleForLoop = "triple-for loop" - NodeTypeBreak = "break" - NodeTypeContinue = "continue" + NodeTypeBeginBlock TNodeType = "begin block" + NodeTypeEndBlock TNodeType = "end block" + NodeTypeIfChain TNodeType = "if-chain" + NodeTypeIfItem TNodeType = "if-item" + NodeTypeCondBlock TNodeType = "cond block" + NodeTypeWhileLoop TNodeType = "while loop" + NodeTypeDoWhileLoop TNodeType = "do-while`loop" + NodeTypeForLoopOneVariable TNodeType = "single-variable for-loop" + NodeTypeForLoopTwoVariable TNodeType = "double-variable for-loop" + NodeTypeForLoopMultivariable TNodeType = "multi-variable for-loop" + NodeTypeTripleForLoop TNodeType = "triple-for loop" + NodeTypeBreak TNodeType = "break" + NodeTypeContinue TNodeType = "continue" - NodeTypeNamedFunctionDefinition = "function definition" - NodeTypeUnnamedFunctionDefinition = "function literal" - NodeTypeSubroutineDefinition = "subroutine definition" - NodeTypeParameterList = "parameter list" - NodeTypeParameter = "parameter" - NodeTypeParameterName = "parameter name" - NodeTypeReturn = "return" + NodeTypeNamedFunctionDefinition TNodeType = "function definition" + NodeTypeUnnamedFunctionDefinition TNodeType = "function literal" + NodeTypeSubroutineDefinition TNodeType = "subroutine definition" + NodeTypeParameterList TNodeType = "parameter list" + NodeTypeParameter TNodeType = "parameter" + NodeTypeParameterName TNodeType = "parameter name" + NodeTypeReturn TNodeType = "return" // A special token which causes a panic when evaluated. This is for // testing that AND/OR short-circuiting is implemented correctly: output = // input1 || panic should NOT panic the process when input1 is true. - NodeTypePanic = "panic token" + NodeTypePanic TNodeType = "panic token" ) diff --git a/internal/pkg/dsl/cst/builtin_function_manager.go b/internal/pkg/dsl/cst/builtin_function_manager.go index 2b37c0286..4d4a97c1c 100644 --- a/internal/pkg/dsl/cst/builtin_function_manager.go +++ b/internal/pkg/dsl/cst/builtin_function_manager.go @@ -28,16 +28,16 @@ type TFunctionClass string const ( FUNC_CLASS_ARITHMETIC TFunctionClass = "arithmetic" - FUNC_CLASS_MATH = "math" - FUNC_CLASS_BOOLEAN = "boolean" - FUNC_CLASS_STRING = "string" - FUNC_CLASS_HASHING = "hashing" - FUNC_CLASS_CONVERSION = "conversion" - FUNC_CLASS_TYPING = "typing" - FUNC_CLASS_COLLECTIONS = "collections" - FUNC_CLASS_HOFS = "higher-order-functions" - FUNC_CLASS_SYSTEM = "system" - FUNC_CLASS_TIME = "time" + FUNC_CLASS_MATH TFunctionClass = "math" + FUNC_CLASS_BOOLEAN TFunctionClass = "boolean" + FUNC_CLASS_STRING TFunctionClass = "string" + FUNC_CLASS_HASHING TFunctionClass = "hashing" + FUNC_CLASS_CONVERSION TFunctionClass = "conversion" + FUNC_CLASS_TYPING TFunctionClass = "typing" + FUNC_CLASS_COLLECTIONS TFunctionClass = "collections" + FUNC_CLASS_HOFS TFunctionClass = "higher-order-functions" + FUNC_CLASS_SYSTEM TFunctionClass = "system" + FUNC_CLASS_TIME TFunctionClass = "time" ) // ================================================================ diff --git a/internal/pkg/dsl/cst/hofs.go b/internal/pkg/dsl/cst/hofs.go index 82af75e89..0116c0c6e 100644 --- a/internal/pkg/dsl/cst/hofs.go +++ b/internal/pkg/dsl/cst/hofs.go @@ -562,9 +562,9 @@ func SortHOF( type tSortType int const ( - sortTypeLexical tSortType = 1 - sortTypeCaseFold = 2 - sortTypeNumerical = 3 + sortTypeLexical tSortType = iota + sortTypeCaseFold + sortTypeNumerical ) // decodeSortFlags maps strings like "cr" in the second argument to sort diff --git a/internal/pkg/dsl/cst/types.go b/internal/pkg/dsl/cst/types.go index 85dd7e52a..39b1d121b 100644 --- a/internal/pkg/dsl/cst/types.go +++ b/internal/pkg/dsl/cst/types.go @@ -110,9 +110,9 @@ type BlockExitStatus int const ( // BLOCK_EXIT_RUN_TO_END is implemented as *BlockExitPayload being nil BLOCK_EXIT_BREAK BlockExitStatus = 1 - BLOCK_EXIT_CONTINUE = 2 - BLOCK_EXIT_RETURN_VOID = 3 - BLOCK_EXIT_RETURN_VALUE = 4 + BLOCK_EXIT_CONTINUE BlockExitStatus = 2 + BLOCK_EXIT_RETURN_VOID BlockExitStatus = 3 + BLOCK_EXIT_RETURN_VALUE BlockExitStatus = 4 ) type BlockExitPayload struct {