Documentation
¶
Overview ¶
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidRule is returned when the rule is invalid. ErrInvalidRule = errors.New("invalid rule") )
Functions ¶
This section is empty.
Types ¶
type Allocator ¶
type Allocator struct {
// contains filtered or unexported fields
}
Allocator manages variable name allocation and mapping
It provides a way to generate unique variable names and maintain a mapping between original names and generated names. This is useful for code generation where you need to ensure variable names don't conflict and potentially obfuscate the original names.
Example:
allocator := NewAllocator( WithLock(&util.NoOpLocker{}), WithPrefix("_var_"), WithInitialCounter(100), ) name := allocator.AllocName("userCount") // might return "_var_101"
func NewAllocator ¶
func NewAllocator(opts ...AllocatorOption) *Allocator
NewAllocator creates a new Allocator with the given options
Example:
allocator := NewAllocator( WithLock(&util.NoOpLocker{}), WithPrefix("_var_"), WithInitialCounter(100), )
func (*Allocator) AllocName ¶
AllocName allocates a new unique name for the given original name
If the original name has already been allocated, it returns the previously generated name. Otherwise, it generates a new unique name.
Example:
name := allocator.AllocName("count") // might return "_v1" name2 := allocator.AllocName("count") // returns the same "_v1"
func (*Allocator) GetGeneratedName ¶
GetGeneratedName returns the generated name for an original name
Returns empty string if the original name is not found.
Example:
genName := allocator.GetGeneratedName("count") // returns "_v1"
func (*Allocator) GetOriginalName ¶
GetOriginalName returns the original name for a generated name
Returns empty string if the generated name is not found.
Example:
origName := allocator.GetOriginalName("_v1") // returns "count"
type AllocatorOption ¶
type AllocatorOption func(*Allocator)
AllocatorOption defines a function that configures an Allocator
func WithInitialCounter ¶
func WithInitialCounter(counter uint64) AllocatorOption
WithInitialCounter sets the initial counter value
Example:
allocator := NewAllocator(WithInitialCounter(100))
func WithLock ¶
func WithLock(lock sync.Locker) AllocatorOption
WithLock sets the lock implementation for the Allocator
Example:
allocator := NewAllocator(WithLock(&util.NoOpLocker{}))
func WithPrefix ¶
func WithPrefix(prefix string) AllocatorOption
WithPrefix sets the prefix for generated variable names
Example:
allocator := NewAllocator(WithPrefix("_var_"))
type HuloCompilerRule ¶
type HuloCompilerRule struct {
// contains filtered or unexported fields
}
func ParseRule ¶
func ParseRule(fullRule string) (hcr *HuloCompilerRule, err error)
ParseRule parses the rule and returns the HuloCompilerRule.
The rule is in the format of "name&version". If the version is not provided, the rule is parsed as the latest version.
func (*HuloCompilerRule) Name ¶
func (r *HuloCompilerRule) Name() string
func (*HuloCompilerRule) Raw ¶
func (r *HuloCompilerRule) Raw() string
func (*HuloCompilerRule) Version ¶
func (r *HuloCompilerRule) Version() *semver.Version