analysis

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Statemetn fns
	FnSetTxMeta      = "set_tx_meta"
	FnSetAccountMeta = "set_account_meta"

	// Expr fns
	FnVarOriginMeta      = "meta"
	FnVarOriginBalance   = "balance"
	FnVarOriginOverdraft = "overdraft"
	FnVarOriginGetAsset  = "get_asset"
	FnVarOriginGetAmount = "get_amount"
	FnVarOriginScoped    = "scoped"
)
View Source
const TypeAccount = "account"
View Source
const TypeAny = "any"
View Source
const TypeAsset = "asset"
View Source
const TypeMonetary = "monetary"
View Source
const TypeNumber = "number"
View Source
const TypePortion = "portion"
View Source
const TypeString = "string"

Variables

View Source
var Builtins = map[string]FnCallResolution{
	FnSetTxMeta: StatementFnCallResolution{
		Params: []string{TypeString, TypeAny},
		Docs:   "set transaction metadata",
	},
	FnSetAccountMeta: StatementFnCallResolution{
		Params: []string{TypeAccount, TypeString, TypeAny},
		Docs:   "set account metadata",
	},
	FnVarOriginMeta: VarOriginFnCallResolution{
		Params: []string{TypeAccount, TypeString},
		Return: TypeAny,
		Docs:   "fetch account metadata",
	},
	FnVarOriginBalance: VarOriginFnCallResolution{
		Params: []string{TypeAccount, TypeAsset},
		Return: TypeMonetary,
		Docs:   "fetch account balance",
	},
	FnVarOriginOverdraft: VarOriginFnCallResolution{
		Params: []string{TypeAccount, TypeAsset},
		Return: TypeMonetary,
		Docs:   "get absolute amount of the overdraft of an account. Returns zero if balance is not negative",
		VersionConstraints: []VersionClause{
			{
				Version:     parser.NewVersionInterpreter(0, 0, 15),
				FeatureFlag: flags.ExperimentalOverdraftFunctionFeatureFlag,
			},
		},
	},
	FnVarOriginGetAsset: VarOriginFnCallResolution{
		Params: []string{TypeMonetary},
		Return: TypeAsset,
		Docs:   "get the asset of the given monetary",
		VersionConstraints: []VersionClause{
			{
				Version:     parser.NewVersionInterpreter(0, 0, 16),
				FeatureFlag: flags.ExperimentalGetAssetFunctionFeatureFlag,
			},
		},
	},
	FnVarOriginGetAmount: VarOriginFnCallResolution{
		Params: []string{TypeMonetary},
		Return: TypeNumber,
		Docs:   "get the amount of the given monetary",
		VersionConstraints: []VersionClause{
			{
				Version:     parser.NewVersionInterpreter(0, 0, 16),
				FeatureFlag: flags.ExperimentalGetAmountFunctionFeatureFlag,
			},
		},
	},
	FnVarOriginScoped: VarOriginFnCallResolution{
		Params: []string{TypeAccount, TypeString},
		Return: TypeAccount,
		Docs:   "returns the scoped version of that account. Empty string means no scope. Overwrites the previous scope",
		VersionConstraints: []VersionClause{
			{
				Version:     parser.NewVersionInterpreter(0, 0, 25),
				FeatureFlag: flags.ExperimentalScopedFunction,
			},
		},
	},
}

Functions

func SeverityToAnsiString

func SeverityToAnsiString(s Severity) string

func SeverityToString

func SeverityToString(s Severity) string

func TypeToString

func TypeToString(r Type) string

func Unify

func Unify(t1 Type, t2 Type) (ok bool)

Types

type AssetMismatch

type AssetMismatch struct {
	Expected string
	Got      string
}

func (AssetMismatch) Message

func (e AssetMismatch) Message() string

func (AssetMismatch) Severity

func (AssetMismatch) Severity() Severity

type BadAllotmentSum

type BadAllotmentSum struct {
	Sum big.Rat
}

func (BadAllotmentSum) Message

func (e BadAllotmentSum) Message() string

func (BadAllotmentSum) Severity

func (BadAllotmentSum) Severity() Severity

type BadArity

type BadArity struct {
	Expected int
	Actual   int
}

func (BadArity) Message

func (e BadArity) Message() string

func (BadArity) Severity

func (BadArity) Severity() Severity

type BoundAsset

type BoundAsset struct {
	BoundAssetType BoundAssetType
	InferredAsset  string
}

func (BoundAsset) Message

func (e BoundAsset) Message() string

func (BoundAsset) Severity

func (BoundAsset) Severity() Severity

type BoundAssetType

type BoundAssetType = uint
const (
	BoundAssetTypeMonetary BoundAssetType = iota
	BoundAssetTypeAsset
)

type BuiltinFnHover

type BuiltinFnHover struct {
	Range   parser.Range
	Node    *parser.FnCall
	Context BuiltinFnHoverContext
}

type BuiltinFnHoverContext

type BuiltinFnHoverContext = uint
const (
	OriginContext BuiltinFnHoverContext = iota
	StatementContext
)

type CheckResult

type CheckResult struct {
	DeclaredVars map[string]parser.VarDeclaration

	Diagnostics []Diagnostic
	Program     parser.Program
	// contains filtered or unexported fields
}

func CheckProgram

func CheckProgram(program parser.Program) CheckResult

func CheckSource

func CheckSource(source string) CheckResult

func (CheckResult) GetErrorsCount

func (r CheckResult) GetErrorsCount() int

func (*CheckResult) GetExprType

func (r *CheckResult) GetExprType(expr parser.ValueExpr) Type

func (*CheckResult) GetSymbols

func (r *CheckResult) GetSymbols() []DocumentSymbol

results are sorted by start position

func (*CheckResult) GetVarDeclType

func (r *CheckResult) GetVarDeclType(decl parser.VarDeclaration) Type

func (CheckResult) GetWarningsCount

func (r CheckResult) GetWarningsCount() int

func (CheckResult) ResolveBuiltinFn

func (r CheckResult) ResolveBuiltinFn(v *parser.FnCallIdentifier) FnCallResolution

func (CheckResult) ResolveVar

func (r CheckResult) ResolveVar(v *parser.Variable) *parser.VarDeclaration

type Diagnostic

type Diagnostic struct {
	Range parser.Range
	Kind  DiagnosticKind
	Id    int32
}

type DiagnosticKind

type DiagnosticKind interface {
	Message() string
	Severity() Severity
}

type DivByZero

type DivByZero struct {
	Sum big.Rat
}

func (DivByZero) Message

func (e DivByZero) Message() string

func (DivByZero) Severity

func (DivByZero) Severity() Severity

type DocumentSymbol

type DocumentSymbol struct {
	Name           string
	Detail         string
	Range          parser.Range
	SelectionRange parser.Range
	Kind           DocumentSymbolKind
}

type DuplicateVariable

type DuplicateVariable struct {
	Name string
}

func (DuplicateVariable) Message

func (e DuplicateVariable) Message() string

func (DuplicateVariable) Severity

func (DuplicateVariable) Severity() Severity

type EmptiedAccount

type EmptiedAccount struct {
	Name string
}

func (EmptiedAccount) Message

func (e EmptiedAccount) Message() string

func (EmptiedAccount) Severity

func (EmptiedAccount) Severity() Severity

type ExperimentalFeature

type ExperimentalFeature struct {
	Name string
}

func (ExperimentalFeature) Message

func (e ExperimentalFeature) Message() string

func (ExperimentalFeature) Severity

func (ExperimentalFeature) Severity() Severity

type FixedPortionVariable

type FixedPortionVariable struct {
	Value big.Rat
}

func (FixedPortionVariable) Message

func (e FixedPortionVariable) Message() string

func (FixedPortionVariable) Severity

func (FixedPortionVariable) Severity() Severity

type FnCallResolution

type FnCallResolution interface {
	ContextName() string
	GetParams() []string
	// contains filtered or unexported methods
}

type GotoDefinitionResult

type GotoDefinitionResult struct {
	Range parser.Range
}

func GotoDefinition

func GotoDefinition(program parser.Program, position parser.Position, checkResult CheckResult) *GotoDefinitionResult

type Hover

type Hover interface {
	// contains filtered or unexported methods
}

func HoverOn

func HoverOn(program parser.Program, position parser.Position) Hover

type InvalidFeature

type InvalidFeature struct {
	Feature string
}

func (InvalidFeature) Message

func (e InvalidFeature) Message() string

func (InvalidFeature) Severity

func (InvalidFeature) Severity() Severity

type InvalidType

type InvalidType struct {
	Name string
}

func (InvalidType) Message

func (e InvalidType) Message() string

TODO evaluate suggestion using Levenshtein distance

func (InvalidType) Severity

func (InvalidType) Severity() Severity

type InvalidUnboundedAccount

type InvalidUnboundedAccount struct{}

func (InvalidUnboundedAccount) Message

func (e InvalidUnboundedAccount) Message() string

func (InvalidUnboundedAccount) Severity

func (InvalidUnboundedAccount) Severity() Severity

type InvalidWorldOverdraft

type InvalidWorldOverdraft struct{}

func (InvalidWorldOverdraft) Message

func (e InvalidWorldOverdraft) Message() string

func (InvalidWorldOverdraft) Severity

func (InvalidWorldOverdraft) Severity() Severity

type NoAllotmentInSendAll

type NoAllotmentInSendAll struct{}

func (NoAllotmentInSendAll) Message

func (e NoAllotmentInSendAll) Message() string

func (NoAllotmentInSendAll) Severity

func (NoAllotmentInSendAll) Severity() Severity

type Parsing

type Parsing struct {
	Description string
}

func (Parsing) Message

func (e Parsing) Message() string

func (Parsing) Severity

func (Parsing) Severity() Severity

type RedundantRemaining

type RedundantRemaining struct{}

func (RedundantRemaining) Message

func (e RedundantRemaining) Message() string

func (RedundantRemaining) Severity

func (RedundantRemaining) Severity() Severity

type RemainingIsNotLast

type RemainingIsNotLast struct{}

func (RemainingIsNotLast) Message

func (e RemainingIsNotLast) Message() string

func (RemainingIsNotLast) Severity

func (RemainingIsNotLast) Severity() Severity

type Severity

type Severity = byte
const (
	ErrorSeverity Severity
	WarningSeverity
	Information
	Hint
)

!important! keep in sync with LSP specs https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnosticSeverity

type StatementFnCallResolution

type StatementFnCallResolution struct {
	Params []string
	Docs   string
}

func (StatementFnCallResolution) ContextName

func (StatementFnCallResolution) ContextName() string

func (StatementFnCallResolution) GetParams

func (r StatementFnCallResolution) GetParams() []string

type TAsset

type TAsset string

func (*TAsset) Resolve

func (a *TAsset) Resolve() Type

type TVar

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

func (*TVar) Resolve

func (t *TVar) Resolve() Type

type Type

type Type interface {
	Resolve() Type
}

type TypeMismatch

type TypeMismatch struct {
	Expected string
	Got      string
}

func (TypeMismatch) Message

func (e TypeMismatch) Message() string

func (TypeMismatch) Severity

func (TypeMismatch) Severity() Severity

type UnboundVariable

type UnboundVariable struct {
	Name string
	Type string
}

func (UnboundVariable) Message

func (e UnboundVariable) Message() string

TODO evaluate suggestion using Levenshtein distance

func (UnboundVariable) Severity

func (UnboundVariable) Severity() Severity

type UnboundedAccountIsNotLast

type UnboundedAccountIsNotLast struct{}

func (UnboundedAccountIsNotLast) Message

func (e UnboundedAccountIsNotLast) Message() string

func (UnboundedAccountIsNotLast) Severity

type UnknownFunction

type UnknownFunction struct {
	Name string
}

func (UnknownFunction) Message

func (e UnknownFunction) Message() string

func (UnknownFunction) Severity

func (UnknownFunction) Severity() Severity

type UnusedVar

type UnusedVar struct {
	Name string
}

func (UnusedVar) Message

func (e UnusedVar) Message() string

func (UnusedVar) Severity

func (UnusedVar) Severity() Severity

type VarOriginFnCallResolution

type VarOriginFnCallResolution struct {
	Params             []string
	Docs               string
	Return             string
	VersionConstraints []VersionClause
}

func (VarOriginFnCallResolution) ContextName

func (VarOriginFnCallResolution) ContextName() string

func (VarOriginFnCallResolution) GetParams

func (r VarOriginFnCallResolution) GetParams() []string

type VariableHover

type VariableHover struct {
	parser.Range
	Node *parser.Variable
}

type VersionClause

type VersionClause struct {
	Version     parser.Version
	FeatureFlag flags.FeatureFlag
}

type VersionMismatch

type VersionMismatch struct {
	RequiredVersion parser.Version
	GotVersion      parser.Version
}

func (VersionMismatch) Message

func (e VersionMismatch) Message() string

func (VersionMismatch) Severity

func (VersionMismatch) Severity() Severity

Jump to

Keyboard shortcuts

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