mlrval

package
v6.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2024 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSON_SINGLE_LINE = 1
	JSON_MULTILINE   = 2
)
View Source
const ABSENT_PRINTREP = "(absent)"
View Source
const ERROR_PRINTREP = "(error)"
View Source
const INVALID_PRINTREP = "(bug-if-you-see-this:case-2)"
View Source
const JSON_INDENT_STRING string = "  "
View Source
const MT_TYPE_MASK_ANY = (1 << MT_ERROR) | (1 << MT_ABSENT) | MT_TYPE_MASK_VAR | MT_TYPE_MASK_FUNC

Not exposed in userspace

View Source
const MT_TYPE_MASK_ARRAY = 1 << MT_ARRAY
View Source
const MT_TYPE_MASK_BOOL = 1 << MT_BOOL
View Source
const MT_TYPE_MASK_FLOAT = 1 << MT_FLOAT
View Source
const MT_TYPE_MASK_FUNC = 1 << MT_FUNC
View Source
const MT_TYPE_MASK_INT = 1 << MT_INT

TODO: comment more re typedecls

View Source
const MT_TYPE_MASK_MAP = 1 << MT_MAP
View Source
const MT_TYPE_MASK_NUM = (1 << MT_INT) | (1 << MT_FLOAT)
View Source
const MT_TYPE_MASK_STRING = (1 << MT_STRING) | (1 << MT_VOID)
View Source
const MT_TYPE_MASK_VAR = (1 << MT_INT) |
	(1 << MT_FLOAT) |
	(1 << MT_BOOL) |
	(1 << MT_VOID) |
	(1 << MT_NULL) |
	(1 << MT_STRING) |
	(1 << MT_ARRAY) |
	(1 << MT_MAP)

Variables

View Source
var ABSENT = &Mlrval{
	mvtype:        MT_ABSENT,
	printrep:      ABSENT_PRINTREP,
	printrepValid: true,
}
View Source
var FALSE = &Mlrval{
	mvtype:        MT_BOOL,
	printrep:      "false",
	printrepValid: true,
	intf:          false,
}
View Source
var MINUS_ONE = &Mlrval{
	mvtype:        MT_INT,
	printrep:      "-1",
	printrepValid: true,
	intf:          int64(-1),
}

For malloc-avoidance in the spaceship operator

View Source
var NULL = &Mlrval{
	mvtype:        MT_NULL,
	printrep:      "null",
	printrepValid: true,
}
View Source
var ONE = &Mlrval{
	mvtype:        MT_INT,
	printrep:      "1",
	printrepValid: true,
	intf:          int64(1),
}
View Source
var TRUE = &Mlrval{
	mvtype:        MT_BOOL,
	printrep:      "true",
	printrepValid: true,
	intf:          true,
}
View Source
var TYPE_NAMES = [MT_DIM]string{
	"int",
	"float",
	"bool",
	"empty",
	"string",
	"array",
	"map",
	"funct",
	"error",
	"null",
	"absent",
}
View Source
var VOID = &Mlrval{
	mvtype:        MT_VOID,
	printrep:      "",
	printrepValid: true,
}
View Source
var ZERO = &Mlrval{
	mvtype:        MT_INT,
	printrep:      "0",
	printrepValid: true,
	intf:          int64(0),
}

Functions

func BsearchMlrvalArrayForAscendingInsert

func BsearchMlrvalArrayForAscendingInsert(
	array *[]*Mlrval,
	size int64,
	value *Mlrval,
) int64

func BsearchMlrvalArrayForDescendingInsert

func BsearchMlrvalArrayForDescendingInsert(
	array *[]*Mlrval,
	size int64,
	value *Mlrval,
) int64

func CaseFoldAscendingComparator

func CaseFoldAscendingComparator(input1 *Mlrval, input2 *Mlrval) int

CaseFoldAscendingComparator is for case-folded lexical sort: it stringifies everything.

func CaseFoldDescendingComparator

func CaseFoldDescendingComparator(input1 *Mlrval, input2 *Mlrval) int

CaseFoldDescendingComparator is for case-folded lexical sort: it stringifies everything.

func Cmp

func Cmp(input1, input2 *Mlrval) int

func Equals

func Equals(input1, input2 *Mlrval) bool

func GetTypeName

func GetTypeName(mvtype MVType) string

func GreaterThan

func GreaterThan(input1, input2 *Mlrval) bool

func GreaterThanOrEquals

func GreaterThanOrEquals(input1, input2 *Mlrval) bool

func HashRecords

func HashRecords(onOff bool)

func LengthenMlrvalArray

func LengthenMlrvalArray(array *[]*Mlrval, newLength64 int)

func LessThan

func LessThan(input1, input2 *Mlrval) bool

func LessThanOrEquals

func LessThanOrEquals(input1, input2 *Mlrval) bool

func LexicalAscendingComparator

func LexicalAscendingComparator(input1 *Mlrval, input2 *Mlrval) int

LexicalAscendingComparator is for lexical sort: it stringifies everything.

func LexicalDescendingComparator

func LexicalDescendingComparator(input1 *Mlrval, input2 *Mlrval) int

LexicalDescendingComparator is for reverse-lexical sort: it stringifies everything.

func NaturalAscendingComparator

func NaturalAscendingComparator(input1, input2 *Mlrval) int

func NaturalDescendingComparator

func NaturalDescendingComparator(input1, input2 *Mlrval) int

func NotEquals

func NotEquals(input1, input2 *Mlrval) bool

func NumericAscendingComparator

func NumericAscendingComparator(input1 *Mlrval, input2 *Mlrval) int

func NumericDescendingComparator

func NumericDescendingComparator(input1 *Mlrval, input2 *Mlrval) int

NumericDescendingComparator is for "numerical" sort: it uses Mlrval sorting rules by type, including numeric sort for numeric types.

func SetFloatOutputFormat

func SetFloatOutputFormat(formatString string) error

func SetInferNormally

func SetInferNormally()

SetInferNormally is the default behavior.

func SetInferrerIntAsFloat

func SetInferrerIntAsFloat()

SetInferrerIntAsFloat is for mlr -F.

func SetInferrerOctalAsInt

func SetInferrerOctalAsInt()

SetInferrerOctalAsInt is for mlr -O.

func SetInferrerStringOnly

func SetInferrerStringOnly()

SetInferrerStringOnly is for mlr -S.

func TypeNameToMask

func TypeNameToMask(typeName string) (mask int, present bool)

func UnaliasArrayIndex

func UnaliasArrayIndex(array *[]*Mlrval, mindex int) (int, bool)

func UnaliasArrayLengthIndex

func UnaliasArrayLengthIndex(n int, mindex int) (int, bool)

Types

type BsearchMlrvalArrayFunc

type BsearchMlrvalArrayFunc func(
	array *[]*Mlrval,
	size int64,
	value *Mlrval,
) int64

type CmpFuncBool

type CmpFuncBool func(input1, input2 *Mlrval) bool

type CmpFuncInt

type CmpFuncInt func(input1, input2 *Mlrval) int // -1, 0, 1 for <=>

The Go sort API is just a bool a<b, not triple a<b, a==b, a>b. Miller does the latter since when we sort primarily on field 1, then secondarily on field 2, etc., we need to be able to detect ties on field 1 so we can know whether to compare on field 2 or not.

type IFormatter

type IFormatter interface {
	Format(mlrval *Mlrval) *Mlrval
	FormatFloat(floatValue float64) string // for --ofmt
}

func GetFormatter

func GetFormatter(
	userLevelFormatString string,
) (IFormatter, error)

type MVType

type MVType int8
const (
	// Type not yet determined: during JSON decode, or for JIT-data from file
	// data whose type doesn't need to be determined yet. For example, when we
	// operate only on columns 15 & 17 of a 20-column CSV file, those two
	// columns get type-inferred during processing but the rest keep their
	// printrep and type MT_PENDING. This is a significant performance
	// optimization.
	MT_PENDING MVType = -1

	// intf is int64
	MT_INT MVType = 0

	// intf is float64
	MT_FLOAT MVType = 1

	// intf is bool
	MT_BOOL MVType = 2

	// Key present in input record with empty value, e.g. input data '$x=,$y=2'
	MT_VOID MVType = 3

	MT_STRING MVType = 4

	// intf is []*Mlrval
	MT_ARRAY MVType = 5

	// intf is *Mlrmap
	MT_MAP MVType = 6

	// intf is interface{} -- resolved in the cst package to avoid circular dependencies
	MT_FUNC MVType = 7

	// E.g. error encountered in one eval & it propagates up the AST at
	// evaluation time.  Various runtime errors, such as file-not-found, result
	// in a message to stderr and os.Exit(1). But errors in user-provided data
	// are intended to result in "(error)"-valued output rather than a crash.
	// This is analogous to the way that IEEE-754 arithmetic carries around
	// Inf and NaN through computation chains.
	MT_ERROR MVType = 8

	// Used only for JSON null, and for 'empty' slots when an array is
	// auto-extended by assigning to an index having a gap from the last index.
	// E.g. x=[1,2,3] then x[5]=5; now x[4] is null
	MT_NULL MVType = 9

	// Key not present in input record, e.g. 'foo = $nosuchkey'
	MT_ABSENT MVType = 10

	// Not a type -- this is a dimension for disposition vectors and
	// disposition matrices. For example, when we want to add two mlrvals,
	// instead of if/elsing or switching on the types of both operands, we
	// instead jump directly to a type-specific function in a matrix of
	// function pointers which is MT_DIM x MT_DIM.
	MT_DIM MVType = 11
)

Important: the values of these enums are used to index into disposition matrices. If they are changed, it will break the disposition matrices, or they will all need manual re-indexing.

Also note the ordering of types reflects the sort order for mixed types, with the exception that ints and floats sort numerically. So 1 < "abc" and 1 < "1", and 7 < true; but 1 < 1.1 < 2 < 2.2.

type Mlrmap

type Mlrmap struct {
	FieldCount int64
	Head       *MlrmapEntry
	Tail       *MlrmapEntry
	// contains filtered or unexported fields
}

----------------------------------------------------------------

func MlrmapFromPairsArray

func MlrmapFromPairsArray(pairsArray []MlrmapPair) *Mlrmap

MlrmapFromPairsArray is used for sorting maps by key/value/etc, e.g. the sortmf DSL function.

func NewMlrmap

func NewMlrmap() *Mlrmap

func NewMlrmapAsRecord

func NewMlrmapAsRecord() *Mlrmap

----------------------------------------------------------------

func NewMlrmapMaybeHashed

func NewMlrmapMaybeHashed(wantHashing bool) *Mlrmap

func (*Mlrmap) Clear

func (mlrmap *Mlrmap) Clear()

func (*Mlrmap) Contains

func (mlrmap *Mlrmap) Contains(other *Mlrmap) bool

True if this contains other, i.e. if other is contained by mlrmap. * If any key of other is not a key of this, return false. * If any key of other has a value unequal to this' value at the same key, return false. * Else return true

func (*Mlrmap) Copy

func (mlrmap *Mlrmap) Copy() *Mlrmap

----------------------------------------------------------------

func (*Mlrmap) CopyUnflattenFields

func (mlrmap *Mlrmap) CopyUnflattenFields(
	fieldNameSet map[string]bool,
	separator string,
) *Mlrmap

func (*Mlrmap) CopyUnflattened

func (mlrmap *Mlrmap) CopyUnflattened(
	separator string,
) *Mlrmap

func (*Mlrmap) Dump

func (mlrmap *Mlrmap) Dump()

----------------------------------------------------------------

func (*Mlrmap) Equals

func (mlrmap *Mlrmap) Equals(other *Mlrmap) bool

----------------------------------------------------------------

func (*Mlrmap) Flatten

func (mlrmap *Mlrmap) Flatten(separator string)

func (*Mlrmap) FlattenFields

func (mlrmap *Mlrmap) FlattenFields(
	fieldNameSet map[string]bool,
	separator string,
)

func (*Mlrmap) Fprint

func (mlrmap *Mlrmap) Fprint(file *os.File)

func (*Mlrmap) Get

func (mlrmap *Mlrmap) Get(key string) *Mlrval

func (*Mlrmap) GetEntry

func (mlrmap *Mlrmap) GetEntry(key string) *MlrmapEntry

---------------------------------------------------------------- Exposed for the 'nest' verb

func (*Mlrmap) GetFirstPair

func (mlrmap *Mlrmap) GetFirstPair() *Mlrmap

GetFirstPair returns the first key-value pair as its own map. If the map is empty (i.e. there is no first pair) it returns nil.

func (*Mlrmap) GetKeys

func (mlrmap *Mlrmap) GetKeys() []string

func (*Mlrmap) GetKeysExcept

func (mlrmap *Mlrmap) GetKeysExcept(exceptions map[string]bool) []string

Returns an array of keys, not including the ones specified. The ones specified are to be passed in as a map from string to bool, as Go doesn't have hash-sets.

func (*Mlrmap) GetKeysJoined

func (mlrmap *Mlrmap) GetKeysJoined() string

----------------------------------------------------------------

func (*Mlrmap) GetKeysJoinedExcept

func (mlrmap *Mlrmap) GetKeysJoinedExcept(px *MlrmapEntry) string

---------------------------------------------------------------- For mlr nest implode across records.

func (*Mlrmap) GetNameAtPositionalIndex

func (mlrmap *Mlrmap) GetNameAtPositionalIndex(position int64) (string, bool)

func (*Mlrmap) GetSelectedValues

func (mlrmap *Mlrmap) GetSelectedValues(selectedFieldNames []string) ([]*Mlrval, bool)

TODO: rename to CopySelectedValues As previous but with copying. For stats1.

func (*Mlrmap) GetSelectedValuesAndJoined

func (mlrmap *Mlrmap) GetSelectedValuesAndJoined(selectedFieldNames []string) (
	string,
	[]*Mlrval,
	bool,
)

As with GetSelectedValuesJoined but also returning the array of mlrvals. For sort. TODO: put 'Copy' into the method name

func (*Mlrmap) GetSelectedValuesJoined

func (mlrmap *Mlrmap) GetSelectedValuesJoined(selectedFieldNames []string) (string, bool)

func (*Mlrmap) GetValuesJoined

func (mlrmap *Mlrmap) GetValuesJoined() string

For mlr reshape

func (*Mlrmap) GetValuesJoinedExcept

func (mlrmap *Mlrmap) GetValuesJoinedExcept(px *MlrmapEntry) string

For mlr nest implode across records.

func (*Mlrmap) GetWithMlrvalIndex

func (mlrmap *Mlrmap) GetWithMlrvalIndex(index *Mlrval) (*Mlrval, error)

func (*Mlrmap) GetWithPositionalIndex

func (mlrmap *Mlrmap) GetWithPositionalIndex(position int64) *Mlrval

func (*Mlrmap) Has

func (mlrmap *Mlrmap) Has(key string) bool

func (*Mlrmap) HasSelectedKeys

func (mlrmap *Mlrmap) HasSelectedKeys(selectedFieldNames []string) bool

Similar to the above but only checks availability. For join.

func (*Mlrmap) IsEmpty

func (mlrmap *Mlrmap) IsEmpty() bool

IsEmpty determines if a map is empty.

func (*Mlrmap) IsNested

func (mlrmap *Mlrmap) IsNested() bool

---------------------------------------------------------------- Only checks to see if the first entry is a map. For emit/emitp.

func (*Mlrmap) IsSinglePair

func (mlrmap *Mlrmap) IsSinglePair() bool

func (*Mlrmap) Label

func (mlrmap *Mlrmap) Label(newNames []string)

----------------------------------------------------------------

func (*Mlrmap) MarshalJSON

func (mlrmap *Mlrmap) MarshalJSON(
	jsonFormatting TJSONFormatting,
	outputIsStdout bool,
) (string, error)

----------------------------------------------------------------

func (*Mlrmap) Merge

func (mlrmap *Mlrmap) Merge(other *Mlrmap)

---------------------------------------------------------------- Merges that into mlrmap.

func (*Mlrmap) MoveToHead

func (mlrmap *Mlrmap) MoveToHead(key string)

func (*Mlrmap) MoveToTail

func (mlrmap *Mlrmap) MoveToTail(key string)

func (*Mlrmap) PrependCopy

func (mlrmap *Mlrmap) PrependCopy(key string, value *Mlrval)

----------------------------------------------------------------

func (*Mlrmap) PrependReference

func (mlrmap *Mlrmap) PrependReference(key string, value *Mlrval)

PrependReference is the same as PutReference, but puts a new entry first, not last.

func (*Mlrmap) Print

func (mlrmap *Mlrmap) Print()

----------------------------------------------------------------

func (*Mlrmap) PutCopy

func (mlrmap *Mlrmap) PutCopy(key string, value *Mlrval)

PutCopy copies the key and value (deep-copying in case the value is array/map). This is safe for DSL use. See also PutReference.

func (*Mlrmap) PutCopyWithMlrvalIndex

func (mlrmap *Mlrmap) PutCopyWithMlrvalIndex(key *Mlrval, value *Mlrval) error

func (*Mlrmap) PutCopyWithPositionalIndex

func (mlrmap *Mlrmap) PutCopyWithPositionalIndex(position int64, value *Mlrval)

TODO: put error-return into this API

func (*Mlrmap) PutIndexed

func (mlrmap *Mlrmap) PutIndexed(indices []*Mlrval, rvalue *Mlrval) error

func (*Mlrmap) PutNameWithPositionalIndex

func (mlrmap *Mlrmap) PutNameWithPositionalIndex(position int64, name *Mlrval)

---------------------------------------------------------------- TODO: put error-return into this API

func (*Mlrmap) PutReference

func (mlrmap *Mlrmap) PutReference(key string, value *Mlrval)

PutReference copies the key but not the value. This is not safe for DSL use, where we could create undesired references between different objects. Only intended to be used at callsites which allocate a mlrval on the spot, solely for the purpose of putting into the map.

func (*Mlrmap) PutReferenceAfter

func (mlrmap *Mlrmap) PutReferenceAfter(
	pe *MlrmapEntry,
	key string,
	value *Mlrval,
) *MlrmapEntry

TODO: COMMENT

func (*Mlrmap) PutReferenceMaybeDedupe

func (mlrmap *Mlrmap) PutReferenceMaybeDedupe(key string, value *Mlrval, dedupe bool) (string, error)

PutReferenceMaybeDedupe is the default inserter for key-value pairs in input records -- if the input is 'x=8,x=9` then we make a record with x=8 and x_2=9. This can be suppressed via a command-line flag which this method's dedupe flag respects.

func (*Mlrmap) ReferenceSelectedValues

func (mlrmap *Mlrmap) ReferenceSelectedValues(selectedFieldNames []string) ([]*Mlrval, bool)

As above but only returns the array. Also, these are references, NOT copies. For step and join.

func (*Mlrmap) Remove

func (mlrmap *Mlrmap) Remove(key string) bool

Returns true if it was found and removed

func (*Mlrmap) RemoveIndexed

func (mlrmap *Mlrmap) RemoveIndexed(indices []*Mlrval) error

func (*Mlrmap) RemoveWithPositionalIndex

func (mlrmap *Mlrmap) RemoveWithPositionalIndex(position int64)

func (*Mlrmap) Rename

func (mlrmap *Mlrmap) Rename(oldKey string, newKey string) bool

----------------------------------------------------------------

func (*Mlrmap) SortByKey

func (mlrmap *Mlrmap) SortByKey()

----------------------------------------------------------------

func (*Mlrmap) SortByKeyRecursively

func (mlrmap *Mlrmap) SortByKeyRecursively()

----------------------------------------------------------------

func (Mlrmap) String

func (mlrmap Mlrmap) String() string

---------------------------------------------------------------- Must have non-pointer receiver in order to implement the fmt.Stringer interface to make mlrmap printable via fmt.Println et al.

func (*Mlrmap) StringifyValuesRecursively

func (mlrmap *Mlrmap) StringifyValuesRecursively()

StringifyValuesRecursively is nominally for the `--jvquoteall` flag.

func (*Mlrmap) ToDKVPString

func (mlrmap *Mlrmap) ToDKVPString() string

func (*Mlrmap) ToNIDXString

func (mlrmap *Mlrmap) ToNIDXString() string

func (*Mlrmap) ToPairsArray

func (mlrmap *Mlrmap) ToPairsArray() []MlrmapPair

ToPairsArray is used for sorting maps by key/value/etc, e.g. the sortmf DSL function.

func (*Mlrmap) Unflatten

func (mlrmap *Mlrmap) Unflatten(
	separator string,
)

Special case: if the resulting string keys are string representations of 1, 2, 3, etc -- without gaps -- then the map is converted to an array.

Examples:

  • The three fields x.a = 7, x.b = 8, x.c = 9 become the single field x = {"a": 7, "b": 8, "c": 9}.

  • The three fields x.1 = 7, x.2 = 8, x.3 = 9 become the single field x = [7,8,9].

  • The two fields x.1 = 7, x.3 = 9 become the single field x = {"1": 7, "3": 9}

func (*Mlrmap) UnflattenFields

func (mlrmap *Mlrmap) UnflattenFields(
	fieldNameSet map[string]bool,
	separator string,
)

---------------------------------------------------------------- For mlr unflatten -f. See comments on Unflatten. Largely copypasta of Unflatten, but split out separately since Flatten needn't check a fieldNameSet.

func (mlrmap *Mlrmap) Unlink(pe *MlrmapEntry)

type MlrmapEntry

type MlrmapEntry struct {
	Key   string
	Value *Mlrval
	Prev  *MlrmapEntry
	Next  *MlrmapEntry
}

func (*MlrmapEntry) JSONParseInPlace

func (entry *MlrmapEntry) JSONParseInPlace()

---------------------------------------------------------------- JSON-parses a single field of a record

func (*MlrmapEntry) JSONStringifyInPlace

func (entry *MlrmapEntry) JSONStringifyInPlace(
	jsonFormatting TJSONFormatting,
)

---------------------------------------------------------------- JSON-stringifies a single field of a record

func (*MlrmapEntry) JSONTryParseInPlace

func (entry *MlrmapEntry) JSONTryParseInPlace()

type MlrmapEntryForArray

type MlrmapEntryForArray struct {
	Key   string
	Value *Mlrval
}

MlrmapEntryForArray is for use by sorting routines where the Prev/Next pointers are irrelevant as well as ephemeral

type MlrmapPair

type MlrmapPair struct {
	Key   string
	Value *Mlrval
}

Only used for sorting, map-to-pairs-array and pairs-array-to-map contexts.

type Mlrval

type Mlrval struct {
	// contains filtered or unexported fields
}

func ArrayFold

func ArrayFold(
	a []*Mlrval,
	initval *Mlrval,
	f func(a, b *Mlrval) *Mlrval,
) *Mlrval

ArrayFold reduces an array to a single value, with a user-supplied starting value and pairwise element-reducer function. Canonical example: start value is 0 and reducer f(a,b) is a+b: this will sum up the values in the array.

func CollectionFold

func CollectionFold(
	c *Mlrval,
	initval *Mlrval,
	f func(a, b *Mlrval) *Mlrval,
) *Mlrval

CollectionFold multiplexes ArrayFold or MapFold. The panic here is not robust, but is done to avoid adding an error-return that would frictionalize the API. The idea is that the caller (internal/library functions, not directly user-facing) must have pre-validated that the argument is an array or map. The panic here is merely a fallback, not the primary check.

func CopyMlrvalArray

func CopyMlrvalArray(input []*Mlrval) []*Mlrval

func FromAnonymousError

func FromAnonymousError() *Mlrval

func FromArray

func FromArray(arrayval []*Mlrval) *Mlrval

func FromBool

func FromBool(input bool) *Mlrval

func FromBoolString

func FromBoolString(input string) *Mlrval

func FromDeferredType

func FromDeferredType(input string) *Mlrval

TODO: comment JIT context. Some things we already know are typed -- DSL things, or JSON contents. Others are deferred, e.g. items from any file format except JSON. TODO: comment re inferBool.

func FromEmptyArray

func FromEmptyArray() *Mlrval

func FromEmptyMap

func FromEmptyMap() *Mlrval

func FromError

func FromError(err error) *Mlrval

func FromErrorString

func FromErrorString(err string) *Mlrval

func FromFloat

func FromFloat(input float64) *Mlrval

func FromFunction

func FromFunction(funcval interface{}, name string) *Mlrval

func FromInferredType

func FromInferredType(input string) *Mlrval

TODO: comment non-JIT context like mlr put -s. TODO: comment re inferBool.

func FromInt

func FromInt(input int64) *Mlrval

func FromIntShowingOctal

func FromIntShowingOctal(input int64) *Mlrval

func FromMap

func FromMap(mapval *Mlrmap) *Mlrval

func FromNotArrayError

func FromNotArrayError(funcname string, v *Mlrval) *Mlrval

func FromNotBooleanError

func FromNotBooleanError(funcname string, v *Mlrval) *Mlrval

func FromNotCollectionError

func FromNotCollectionError(funcname string, v *Mlrval) *Mlrval

func FromNotFunctionError

func FromNotFunctionError(funcname string, v *Mlrval) *Mlrval

func FromNotIntError

func FromNotIntError(funcname string, v *Mlrval) *Mlrval

func FromNotMapError

func FromNotMapError(funcname string, v *Mlrval) *Mlrval

func FromNotNamedTypeError

func FromNotNamedTypeError(funcname string, v *Mlrval, expected_type_name string) *Mlrval

func FromNotNumericError

func FromNotNumericError(funcname string, v *Mlrval) *Mlrval

func FromNotStringError

func FromNotStringError(funcname string, v *Mlrval) *Mlrval

func FromPending

func FromPending() *Mlrval

TODO: comment for JSON-scanner context.

func FromPrevalidatedFloatString

func FromPrevalidatedFloatString(input string, floatval float64) *Mlrval

TODO: comment

func FromPrevalidatedIntString

func FromPrevalidatedIntString(input string, intval int64) *Mlrval

TODO: comment

func FromSingletonArray

func FromSingletonArray(element *Mlrval) *Mlrval

func FromString

func FromString(input string) *Mlrval

func FromTypeErrorBinary

func FromTypeErrorBinary(funcname string, v, input2 *Mlrval) *Mlrval

func FromTypeErrorTernary

func FromTypeErrorTernary(funcname string, v, input2, input3 *Mlrval) *Mlrval

func FromTypeErrorUnary

func FromTypeErrorUnary(funcname string, v *Mlrval) *Mlrval

func MapFold

func MapFold(
	m *Mlrmap,
	initval *Mlrval,
	f func(a, b *Mlrval) *Mlrval,
) *Mlrval

MapFold reduces a map's values to a single value, with a user-supplied starting value and pairwise element-reducer function. Canonical example: start value is 0 and reducer f(a,b) is a+b: this will sum up the values in the map. Nothing here accesses map keys.

func MlrvalDecodeFromJSON

func MlrvalDecodeFromJSON(decoder *json.Decoder) (
	mlrval *Mlrval,
	eof bool,
	err error,
)

----------------------------------------------------------------

func MlrvalFromPending

func MlrvalFromPending() Mlrval

func NewMlrvalForAutoDeepen

func NewMlrvalForAutoDeepen(mvtype MVType) (*Mlrval, error)

NewMlrvalForAutoDeepen is for auto-deepen of nested maps in things like

$foo[1]["a"][2]["b"] = 3

Autocreated levels are maps. Array levels can be explicitly created e.g.

$foo[1]["a"] ??= []
$foo[1]["a"][2]["b"] = 3

func SplitAXHelper

func SplitAXHelper(input string, separator string) *Mlrval

SplitAXHelper is split out for the benefit of BIF_splitax and BIF_unflatten.

func TryFromFloatString

func TryFromFloatString(input string) *Mlrval

TryFromFloatString is used by the mlrval Formatter (fmtnum DSL function, format-values verb, etc). Each mlrval has printrep and a printrepValid for its original string, then a type-code like MT_INT or MT_FLOAT, and type-specific storage like intval or floatval.

If the user has taken a mlrval with original string "3.14" and formatted it with "%.4f" then its printrep will be "3.1400" but its type should still be MT_FLOAT.

If on the other hand the user has formatted the same mlrval with "[[%.4f]]" then its printrep will be "[[3.1400]]" and it will be MT_STRING. This function supports that.

func TryFromIntString

func TryFromIntString(input string) *Mlrval

TryFromIntString is used by the mlrval Formatter (fmtnum DSL function, format-values verb, etc). Each mlrval has printrep and a printrepValid for its original string, then a type-code like MT_INT or MT_FLOAT, and type-specific storage like intval or floatval.

If the user has taken a mlrval with original string "314" and formatted it with "0x%04x" then its printrep will be "0x013a" but its type should still be MT_INT.

If on the other hand the user has formatted the same mlrval with "[[%0x04x]]" then its printrep will be "[[0x013a]]" and it will be MT_STRING. This function supports that.

func TryUnmarshalJSON

func TryUnmarshalJSON(inputBytes []byte) (pmv *Mlrval, err error)

----------------------------------------------------------------

func (*Mlrval) AcquireArrayValue

func (mv *Mlrval) AcquireArrayValue() []*Mlrval

func (*Mlrval) AcquireBoolValue

func (mv *Mlrval) AcquireBoolValue() bool

func (*Mlrval) AcquireFloatValue

func (mv *Mlrval) AcquireFloatValue() float64

func (*Mlrval) AcquireIntValue

func (mv *Mlrval) AcquireIntValue() int64

func (*Mlrval) AcquireMapValue

func (mv *Mlrval) AcquireMapValue() *Mlrmap

func (*Mlrval) AcquireStringValue

func (mv *Mlrval) AcquireStringValue() string

func (*Mlrval) ArrayAppend

func (mv *Mlrval) ArrayAppend(value *Mlrval)

---------------------------------------------------------------- TODO: thinking about capacity-resizing

func (*Mlrval) ArrayGet

func (mv *Mlrval) ArrayGet(mindex *Mlrval) Mlrval

================================================================ TODO: copy-reduction refactor

func (*Mlrval) ArrayPut

func (mv *Mlrval) ArrayPut(mindex *Mlrval, value *Mlrval)

---------------------------------------------------------------- TODO: make this return error so caller can do 'if err == nil { ... }'

func (*Mlrval) Arrayify

func (mv *Mlrval) Arrayify() *Mlrval

func (*Mlrval) AssertNumeric

func (mv *Mlrval) AssertNumeric()

func (*Mlrval) Copy

func (mv *Mlrval) Copy() *Mlrval

TODO: comment about mvtype; deferrence; copying of deferrence.

func (*Mlrval) FlattenToMap

func (mv *Mlrval) FlattenToMap(prefix string, delimiter string) Mlrval

func (*Mlrval) GetArray

func (mv *Mlrval) GetArray() []*Mlrval

func (*Mlrval) GetArrayLength

func (mv *Mlrval) GetArrayLength() (int, bool)

func (*Mlrval) GetArrayValueOrError

func (mv *Mlrval) GetArrayValueOrError(funcname string) (ok []*Mlrval, errValue *Mlrval)

func (*Mlrval) GetBoolValue

func (mv *Mlrval) GetBoolValue() (boolValue bool, isBool bool)

func (*Mlrval) GetError

func (mv *Mlrval) GetError() (bool, error)

func (*Mlrval) GetFloatValue

func (mv *Mlrval) GetFloatValue() (floatValue float64, isFloat bool)

func (*Mlrval) GetFunction

func (mv *Mlrval) GetFunction() interface{}

func (*Mlrval) GetIntValue

func (mv *Mlrval) GetIntValue() (intValue int64, isInt bool)

func (*Mlrval) GetIntValueOrError

func (mv *Mlrval) GetIntValueOrError(funcname string) (intValue int64, errValue *Mlrval)

func (*Mlrval) GetMap

func (mv *Mlrval) GetMap() *Mlrmap

func (*Mlrval) GetMapValueOrError

func (mv *Mlrval) GetMapValueOrError(funcname string) (ok *Mlrmap, errValue *Mlrval)

func (*Mlrval) GetNumericNegativeorDie

func (mv *Mlrval) GetNumericNegativeorDie() bool

func (*Mlrval) GetNumericToFloatValue

func (mv *Mlrval) GetNumericToFloatValue() (floatValue float64, isFloat bool)

func (*Mlrval) GetNumericToFloatValueOrDie

func (mv *Mlrval) GetNumericToFloatValueOrDie() (floatValue float64)

func (*Mlrval) GetNumericToFloatValueOrError

func (mv *Mlrval) GetNumericToFloatValueOrError(funcname string) (floatValue float64, errValue *Mlrval)

func (*Mlrval) GetStringValue

func (mv *Mlrval) GetStringValue() (stringValue string, isString bool)

func (*Mlrval) GetStringValueOrError

func (mv *Mlrval) GetStringValueOrError(funcname string) (stringValue string, errValue *Mlrval)

func (*Mlrval) GetTypeBit

func (mv *Mlrval) GetTypeBit() int

func (*Mlrval) GetTypeName

func (mv *Mlrval) GetTypeName() string

func (*Mlrval) Increment

func (mv *Mlrval) Increment()

Increment is used by stats1.

func (*Mlrval) IsAbsent

func (mv *Mlrval) IsAbsent() bool

TODO: comment no JIT-infer here -- absent is non-inferrable and we needn't take the expense of JIT.

func (*Mlrval) IsArray

func (mv *Mlrval) IsArray() bool

func (*Mlrval) IsArrayOrMap

func (mv *Mlrval) IsArrayOrMap() bool

func (*Mlrval) IsBool

func (mv *Mlrval) IsBool() bool

func (*Mlrval) IsEmptyString

func (mv *Mlrval) IsEmptyString() bool

* Error is non-empty * Absent is non-empty (shouldn't have been assigned in the first place; error should be surfaced) * Void is empty * Empty string is empty * Int/float/bool/array/map are all non-empty

func (*Mlrval) IsError

func (mv *Mlrval) IsError() bool

func (*Mlrval) IsErrorOrAbsent

func (mv *Mlrval) IsErrorOrAbsent() bool

TODO: comment no JIT-infer here -- absent is non-inferrable and we needn't take the expense of JIT.

func (*Mlrval) IsErrorOrVoid

func (mv *Mlrval) IsErrorOrVoid() bool

func (*Mlrval) IsFalse

func (mv *Mlrval) IsFalse() bool

func (*Mlrval) IsFloat

func (mv *Mlrval) IsFloat() bool

func (*Mlrval) IsFunction

func (mv *Mlrval) IsFunction() bool

func (*Mlrval) IsInt

func (mv *Mlrval) IsInt() bool

func (*Mlrval) IsIntZero

func (mv *Mlrval) IsIntZero() bool

func (*Mlrval) IsLegit

func (mv *Mlrval) IsLegit() bool

func (*Mlrval) IsMap

func (mv *Mlrval) IsMap() bool

func (*Mlrval) IsNull

func (mv *Mlrval) IsNull() bool

TODO: comment no JIT-infer here -- NULL is non-inferrable and we needn't take the expense of JIT. This is a literal in JSON files, or else explicitly set to NULL.

func (*Mlrval) IsNumeric

func (mv *Mlrval) IsNumeric() bool

func (*Mlrval) IsString

func (mv *Mlrval) IsString() bool

func (*Mlrval) IsStringOrInt

func (mv *Mlrval) IsStringOrInt() bool

func (*Mlrval) IsStringOrVoid

func (mv *Mlrval) IsStringOrVoid() bool

func (*Mlrval) IsTrue

func (mv *Mlrval) IsTrue() bool

func (*Mlrval) IsVoid

func (mv *Mlrval) IsVoid() bool

func (*Mlrval) MapGet

func (mv *Mlrval) MapGet(key *Mlrval) Mlrval

================================================================

func (*Mlrval) MapPut

func (mv *Mlrval) MapPut(key *Mlrval, value *Mlrval)

----------------------------------------------------------------

func (*Mlrval) MarshalJSON

func (mv *Mlrval) MarshalJSON(
	jsonFormatting TJSONFormatting,
	outputIsStdout bool,
) (string, error)

================================================================

func (*Mlrval) OriginalString

func (mv *Mlrval) OriginalString() string

OriginalString gets the field value as a string regardless of --ofmt specification. E.g if the ofmt is "%.4f" and input is 3.1415926535, OriginalString() will return "3.1415926535" while String() will return "3.1416".

func (*Mlrval) PutIndexed

func (mv *Mlrval) PutIndexed(indices []*Mlrval, rvalue *Mlrval) error

func (*Mlrval) RemoveIndexed

func (mv *Mlrval) RemoveIndexed(indices []*Mlrval) error

----------------------------------------------------------------

func (*Mlrval) SetFromPrevalidatedBoolString

func (mv *Mlrval) SetFromPrevalidatedBoolString(input string, boolval bool) *Mlrval

TODO: comment

func (*Mlrval) SetFromPrevalidatedFloatString

func (mv *Mlrval) SetFromPrevalidatedFloatString(input string, floatval float64) *Mlrval

TODO: comment

func (*Mlrval) SetFromPrevalidatedIntString

func (mv *Mlrval) SetFromPrevalidatedIntString(input string, intval int64) *Mlrval

TODO: comment

func (*Mlrval) SetFromString

func (mv *Mlrval) SetFromString(input string) *Mlrval

func (*Mlrval) SetFromVoid

func (mv *Mlrval) SetFromVoid() *Mlrval

func (*Mlrval) ShowSizes

func (mv *Mlrval) ShowSizes()

func (*Mlrval) StrictModeCheck

func (mv *Mlrval) StrictModeCheck(strictMode bool, description string) *Mlrval

func (*Mlrval) String

func (mv *Mlrval) String() string

Must have non-pointer receiver in order to implement the fmt.Stringer interface to make this printable via fmt.Println et al. However, that results in a needless copy of the Mlrval. So, we intentionally use pointer receiver, and if we need to print to stdout, we can fmt.Printf with "%s" and mv.String().

func (*Mlrval) StringMaybeQuoted

func (mv *Mlrval) StringMaybeQuoted() string

StringMaybeQuoted Returns strings double-quoted; all else not.

func (*Mlrval) StringifyValuesRecursively

func (mv *Mlrval) StringifyValuesRecursively()

StringifyValuesRecursively is nominally for the `--jvquoteall` flag.

func (*Mlrval) Type

func (mv *Mlrval) Type() MVType

func (*Mlrval) UnmarshalJSON

func (mv *Mlrval) UnmarshalJSON(inputBytes []byte) error

----------------------------------------------------------------

type TJSONFormatting

type TJSONFormatting int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL