diff --git a/lang/core/concat_func.go b/lang/core/concat.go similarity index 100% rename from lang/core/concat_func.go rename to lang/core/concat.go diff --git a/lang/funcs/contains_func.go b/lang/core/contains.go similarity index 95% rename from lang/funcs/contains_func.go rename to lang/core/contains.go index 79f93d85..3b0e182b 100644 --- a/lang/funcs/contains_func.go +++ b/lang/core/contains.go @@ -27,21 +27,20 @@ // additional permission if he deems it necessary to achieve the goals of this // additional permission. -package funcs +package core import ( "context" "fmt" + "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" ) const ( - // ContainsFuncName is the name this function is registered as. This - // starts with an underscore so that it cannot be used from the lexer. - // XXX: change to _contains and add syntax in the lexer/parser - ContainsFuncName = "contains" + // ContainsFuncName is the name this function is registered as. + ContainsFuncName = funcs.ContainsFuncName // arg names... containsArgNameNeedle = "needle" @@ -49,7 +48,7 @@ const ( ) func init() { - Register(ContainsFuncName, func() interfaces.Func { return &ContainsFunc{} }) // must register the func and name + funcs.Register(ContainsFuncName, func() interfaces.Func { return &ContainsFunc{} }) // must register the func and name } var _ interfaces.BuildableFunc = &ContainsFunc{} // ensure it meets this expectation diff --git a/lang/funcs/history_func.go b/lang/core/history.go similarity index 96% rename from lang/funcs/history_func.go rename to lang/core/history.go index 5f035b8c..49ac22a5 100644 --- a/lang/funcs/history_func.go +++ b/lang/core/history.go @@ -27,12 +27,13 @@ // additional permission if he deems it necessary to achieve the goals of this // additional permission. -package funcs // TODO: should this be in its own individual package? +package core // TODO: should this be in its own individual package? import ( "context" "fmt" + "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" ) @@ -48,7 +49,7 @@ const ( ) func init() { - Register(HistoryFuncName, func() interfaces.Func { return &HistoryFunc{} }) // must register the func and name + funcs.Register(HistoryFuncName, func() interfaces.Func { return &HistoryFunc{} }) // must register the func and name } var _ interfaces.BuildableFunc = &HistoryFunc{} // ensure it meets this expectation diff --git a/lang/core/len_func.go b/lang/core/len.go similarity index 100% rename from lang/core/len_func.go rename to lang/core/len.go diff --git a/lang/funcs/list_lookup_func.go b/lang/core/list_lookup.go similarity index 97% rename from lang/funcs/list_lookup_func.go rename to lang/core/list_lookup.go index 6b91d61b..752eb99e 100644 --- a/lang/funcs/list_lookup_func.go +++ b/lang/core/list_lookup.go @@ -27,13 +27,14 @@ // additional permission if he deems it necessary to achieve the goals of this // additional permission. -package funcs +package core import ( "context" "fmt" "math" + "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" "github.com/purpleidea/mgmt/util/errwrap" @@ -49,7 +50,7 @@ const ( ) func init() { - Register(ListLookupFuncName, func() interfaces.Func { return &ListLookupFunc{} }) // must register the func and name + funcs.Register(ListLookupFuncName, func() interfaces.Func { return &ListLookupFunc{} }) // must register the func and name } var _ interfaces.BuildableFunc = &ListLookupFunc{} // ensure it meets this expectation diff --git a/lang/funcs/list_lookup_default_func.go b/lang/core/list_lookup_default.go similarity index 97% rename from lang/funcs/list_lookup_default_func.go rename to lang/core/list_lookup_default.go index 2680ed86..54fbca06 100644 --- a/lang/funcs/list_lookup_default_func.go +++ b/lang/core/list_lookup_default.go @@ -27,13 +27,14 @@ // additional permission if he deems it necessary to achieve the goals of this // additional permission. -package funcs +package core import ( "context" "fmt" "math" + "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" "github.com/purpleidea/mgmt/util/errwrap" @@ -50,7 +51,7 @@ const ( ) func init() { - Register(ListLookupDefaultFuncName, func() interfaces.Func { return &ListLookupDefaultFunc{} }) // must register the func and name + funcs.Register(ListLookupDefaultFuncName, func() interfaces.Func { return &ListLookupDefaultFunc{} }) // must register the func and name } var _ interfaces.BuildableFunc = &ListLookupDefaultFunc{} // ensure it meets this expectation diff --git a/lang/funcs/lookup_func.go b/lang/core/lookup.go similarity index 96% rename from lang/funcs/lookup_func.go rename to lang/core/lookup.go index 55c7678a..28d5304b 100644 --- a/lang/funcs/lookup_func.go +++ b/lang/core/lookup.go @@ -27,12 +27,13 @@ // additional permission if he deems it necessary to achieve the goals of this // additional permission. -package funcs +package core import ( "context" "fmt" + "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" ) @@ -41,7 +42,7 @@ const ( // LookupFuncName is the name this function is registered as. // This starts with an underscore so that it cannot be used from the // lexer. - LookupFuncName = "_lookup" + LookupFuncName = funcs.LookupFuncName // arg names... lookupArgNameListOrMap = "listormap" @@ -49,7 +50,7 @@ const ( ) func init() { - Register(LookupFuncName, func() interfaces.Func { return &LookupFunc{} }) // must register the func and name + funcs.Register(LookupFuncName, func() interfaces.Func { return &LookupFunc{} }) // must register the func and name } var _ interfaces.BuildableFunc = &LookupFunc{} // ensure it meets this expectation diff --git a/lang/funcs/lookup_default_func.go b/lang/core/lookup_default.go similarity index 96% rename from lang/funcs/lookup_default_func.go rename to lang/core/lookup_default.go index 9ea21e89..4a4c2bbb 100644 --- a/lang/funcs/lookup_default_func.go +++ b/lang/core/lookup_default.go @@ -27,12 +27,13 @@ // additional permission if he deems it necessary to achieve the goals of this // additional permission. -package funcs +package core import ( "context" "fmt" + "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" ) @@ -41,7 +42,7 @@ const ( // LookupDefaultFuncName is the name this function is registered as. // This starts with an underscore so that it cannot be used from the // lexer. - LookupDefaultFuncName = "_lookup_default" + LookupDefaultFuncName = funcs.LookupDefaultFuncName // arg names... lookupDefaultArgNameListOrMap = "listormap" @@ -50,7 +51,7 @@ const ( ) func init() { - Register(LookupDefaultFuncName, func() interfaces.Func { return &LookupDefaultFunc{} }) // must register the func and name + funcs.Register(LookupDefaultFuncName, func() interfaces.Func { return &LookupDefaultFunc{} }) // must register the func and name } var _ interfaces.BuildableFunc = &LookupDefaultFunc{} // ensure it meets this expectation diff --git a/lang/funcs/map_lookup_func.go b/lang/core/map_lookup.go similarity index 97% rename from lang/funcs/map_lookup_func.go rename to lang/core/map_lookup.go index d2ddf653..a2076615 100644 --- a/lang/funcs/map_lookup_func.go +++ b/lang/core/map_lookup.go @@ -27,12 +27,13 @@ // additional permission if he deems it necessary to achieve the goals of this // additional permission. -package funcs +package core import ( "context" "fmt" + "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" "github.com/purpleidea/mgmt/util/errwrap" @@ -48,7 +49,7 @@ const ( ) func init() { - Register(MapLookupFuncName, func() interfaces.Func { return &MapLookupFunc{} }) // must register the func and name + funcs.Register(MapLookupFuncName, func() interfaces.Func { return &MapLookupFunc{} }) // must register the func and name } var _ interfaces.BuildableFunc = &MapLookupFunc{} // ensure it meets this expectation diff --git a/lang/funcs/map_lookup_default_func.go b/lang/core/map_lookup_default.go similarity index 97% rename from lang/funcs/map_lookup_default_func.go rename to lang/core/map_lookup_default.go index d71c1cca..9eb34665 100644 --- a/lang/funcs/map_lookup_default_func.go +++ b/lang/core/map_lookup_default.go @@ -27,12 +27,13 @@ // additional permission if he deems it necessary to achieve the goals of this // additional permission. -package funcs +package core import ( "context" "fmt" + "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" "github.com/purpleidea/mgmt/util/errwrap" @@ -49,7 +50,7 @@ const ( ) func init() { - Register(MapLookupDefaultFuncName, func() interfaces.Func { return &MapLookupDefaultFunc{} }) // must register the func and name + funcs.Register(MapLookupDefaultFuncName, func() interfaces.Func { return &MapLookupDefaultFunc{} }) // must register the func and name } var _ interfaces.BuildableFunc = &MapLookupDefaultFunc{} // ensure it meets this expectation diff --git a/lang/core/panic_func.go b/lang/core/panic.go similarity index 100% rename from lang/core/panic_func.go rename to lang/core/panic.go diff --git a/lang/core/random1_func.go b/lang/core/random1.go similarity index 100% rename from lang/core/random1_func.go rename to lang/core/random1.go diff --git a/lang/funcs/struct_lookup_func.go b/lang/core/struct_lookup.go similarity index 97% rename from lang/funcs/struct_lookup_func.go rename to lang/core/struct_lookup.go index 359b18bc..d6fbd849 100644 --- a/lang/funcs/struct_lookup_func.go +++ b/lang/core/struct_lookup.go @@ -27,12 +27,13 @@ // additional permission if he deems it necessary to achieve the goals of this // additional permission. -package funcs +package core import ( "context" "fmt" + "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" "github.com/purpleidea/mgmt/util/errwrap" @@ -41,7 +42,7 @@ import ( const ( // StructLookupFuncName is the name this function is registered as. This // starts with an underscore so that it cannot be used from the lexer. - StructLookupFuncName = "_struct_lookup" + StructLookupFuncName = funcs.StructLookupFuncName // arg names... structLookupArgNameStruct = "struct" @@ -49,7 +50,7 @@ const ( ) func init() { - Register(StructLookupFuncName, func() interfaces.Func { return &StructLookupFunc{} }) // must register the func and name + funcs.Register(StructLookupFuncName, func() interfaces.Func { return &StructLookupFunc{} }) // must register the func and name } var _ interfaces.BuildableFunc = &StructLookupFunc{} // ensure it meets this expectation diff --git a/lang/funcs/struct_lookup_optional_func.go b/lang/core/struct_lookup_optional.go similarity index 97% rename from lang/funcs/struct_lookup_optional_func.go rename to lang/core/struct_lookup_optional.go index a1176dc4..26c75f19 100644 --- a/lang/funcs/struct_lookup_optional_func.go +++ b/lang/core/struct_lookup_optional.go @@ -27,12 +27,13 @@ // additional permission if he deems it necessary to achieve the goals of this // additional permission. -package funcs +package core import ( "context" "fmt" + "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" "github.com/purpleidea/mgmt/util/errwrap" @@ -42,7 +43,7 @@ const ( // StructLookupOptionalFuncName is the name this function is registered // as. This starts with an underscore so that it cannot be used from the // lexer. - StructLookupOptionalFuncName = "_struct_lookup_optional" + StructLookupOptionalFuncName = funcs.StructLookupOptionalFuncName // arg names... structLookupOptionalArgNameStruct = "struct" @@ -51,7 +52,7 @@ const ( ) func init() { - Register(StructLookupOptionalFuncName, func() interfaces.Func { return &StructLookupOptionalFunc{} }) // must register the func and name + funcs.Register(StructLookupOptionalFuncName, func() interfaces.Func { return &StructLookupOptionalFunc{} }) // must register the func and name } var _ interfaces.InferableFunc = &StructLookupOptionalFunc{} // ensure it meets this expectation diff --git a/lang/funcs/funcs.go b/lang/funcs/funcs.go index 31aceeb6..72a831ec 100644 --- a/lang/funcs/funcs.go +++ b/lang/funcs/funcs.go @@ -61,6 +61,28 @@ const ( // is listed here because it needs a well-known name that can be used by // the string interpolation code. ConcatFuncName = "concat" + + // ContainsFuncName is the name the contains function is registered as. + ContainsFuncName = "contains" + + // LookupDefaultFuncName is the name this function is registered as. + // This starts with an underscore so that it cannot be used from the + // lexer. + LookupDefaultFuncName = "_lookup_default" + + // LookupFuncName is the name this function is registered as. + // This starts with an underscore so that it cannot be used from the + // lexer. + LookupFuncName = "_lookup" + + // StructLookupFuncName is the name this function is registered as. This + // starts with an underscore so that it cannot be used from the lexer. + StructLookupFuncName = "_struct_lookup" + + // StructLookupOptionalFuncName is the name this function is registered + // as. This starts with an underscore so that it cannot be used from the + // lexer. + StructLookupOptionalFuncName = "_struct_lookup_optional" ) // registeredFuncs is a global map of all possible funcs which can be used. You