ast

package
v0.0.0-...-89dfc66 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(f func(interface{}) interface{}, x interface{}) interface{}

Convert converts an AST with a given function. This function visits all expressions and statements at least.

Types

type AnonymousFunction

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

AnonymousFunction represents a anonymous function as an expression.

func NewAnonymousFunction

func NewAnonymousFunction(s Signature, ls []interface{}, b interface{}) AnonymousFunction

NewAnonymousFunction creates a anonymous function.

func (AnonymousFunction) Body

func (f AnonymousFunction) Body() interface{}

Body returns a body expression of an anonymous function.

func (AnonymousFunction) Lets

func (f AnonymousFunction) Lets() []interface{}

Lets returns let statements contained in an anonymous function.

func (AnonymousFunction) Signature

func (f AnonymousFunction) Signature() Signature

Signature returns a signature of an anonymous function.

func (AnonymousFunction) String

func (f AnonymousFunction) String() string

type App

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

App represents an application of a function to arguments.

func NewApp

func NewApp(f interface{}, args Arguments, info *debug.Info) App

NewApp creates an App from a function and arguments with debug information.

func NewPApp

func NewPApp(f interface{}, args []interface{}, info *debug.Info) App

NewPApp don't creates PPap but PApp.

func (App) Arguments

func (a App) Arguments() Arguments

Arguments returns arguments of an application.

func (App) DebugInfo

func (a App) DebugInfo() *debug.Info

DebugInfo returns debug information of an application.

func (App) Function

func (a App) Function() interface{}

Function returns a function of an application.

func (App) String

func (a App) String() string

type Arguments

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

Arguments represents arguments passed to a function.

func NewArguments

func NewArguments(ps []PositionalArgument, ks []KeywordArgument) Arguments

NewArguments creates arguments.

func (Arguments) Keywords

func (a Arguments) Keywords() []KeywordArgument

Keywords returns keyword arguments contained in arguments.

func (Arguments) Positionals

func (a Arguments) Positionals() []PositionalArgument

Positionals returns positional arguments contained in arguments.

func (Arguments) String

func (a Arguments) String() string

type DefFunction

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

DefFunction represents a def-function statement node in ASTs.

func NewDefFunction

func NewDefFunction(name string, sig Signature, lets []interface{}, expr interface{}, i *debug.Info) DefFunction

NewDefFunction creates a DefFunction from its function name, signature, internal let statements, and a body expression.

func (DefFunction) Body

func (f DefFunction) Body() interface{}

Body returns a body expression of a function defined by the def-function statement.

func (DefFunction) DebugInfo

func (f DefFunction) DebugInfo() *debug.Info

DebugInfo returns debug information of a function defined by the def-function statement.

func (DefFunction) Lets

func (f DefFunction) Lets() []interface{}

Lets returns let statements contained in the def-function statement. Returned values should be LetVar or DefFunction.

func (DefFunction) Name

func (f DefFunction) Name() string

Name returns a name of a function defined by the def-function statement.

func (DefFunction) Signature

func (f DefFunction) Signature() Signature

Signature returns a signature of a function defined by the def-function statement.

func (DefFunction) String

func (f DefFunction) String() string

type Effect

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

Effect represents effects of programs.

func NewEffect

func NewEffect(expr interface{}, expanded bool) Effect

NewEffect creates an Effect.

func (Effect) Expanded

func (o Effect) Expanded() bool

Expanded returns true when the effect is expanded.

func (Effect) Expr

func (o Effect) Expr() interface{}

Expr returns an expression of the effect.

func (Effect) String

func (o Effect) String() string

type Import

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

Import represents an import of a sub module.

func NewImport

func NewImport(path, prefix string, info *debug.Info) Import

NewImport creates an Import.

func (Import) Path

func (i Import) Path() string

Path returns a path to an imported sub module.

func (Import) Prefix

func (i Import) Prefix() string

Prefix returns a prefix apppended to members' names in the imported module.

func (Import) String

func (i Import) String() string

type KeywordArgument

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

KeywordArgument represents a keyword argument passed to a function.

func NewKeywordArgument

func NewKeywordArgument(name string, value interface{}) KeywordArgument

NewKeywordArgument creates a keyword argument from a bound name and its value.

func (KeywordArgument) Name

func (k KeywordArgument) Name() string

Name returns a bound name of a keyword argument.

func (KeywordArgument) String

func (k KeywordArgument) String() string

func (KeywordArgument) Value

func (k KeywordArgument) Value() interface{}

Value returns a value of a keyword argument.

type LetExpression

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

LetExpression represents a let expression node in ASTs.

func NewLetExpression

func NewLetExpression(lets []interface{}, expr interface{}) LetExpression

NewLetExpression creates a let expression.

func (LetExpression) Expr

func (l LetExpression) Expr() interface{}

Expr returns an expression of the let expression.

func (LetExpression) Lets

func (l LetExpression) Lets() []interface{}

Lets returns let-match statements used in the let expression.

func (LetExpression) String

func (l LetExpression) String() string

type LetMatch

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

LetMatch represents a let-match statement in ASTs.

func NewLetMatch

func NewLetMatch(pattern interface{}, expr interface{}) LetMatch

NewLetMatch creates a let-match statement from a pattern and an expression.

func (LetMatch) Expr

func (m LetMatch) Expr() interface{}

Expr returns an expression of a variable value""

func (LetMatch) Pattern

func (m LetMatch) Pattern() interface{}

Pattern returns a pattern matched with a value of the let-match statement.

func (LetMatch) String

func (m LetMatch) String() string

type LetVar

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

LetVar represents a let-variable statement node in ASTs.

func NewLetVar

func NewLetVar(name string, expr interface{}) LetVar

NewLetVar creates a LetVar from a variable name and its value of an expression.

func (LetVar) Expr

func (v LetVar) Expr() interface{}

Expr returns an expression of a variable value""

func (LetVar) Name

func (v LetVar) Name() string

Name returns a variable name defined by the let-variable statement.

func (LetVar) String

func (v LetVar) String() string

type Match

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

Match represents a match expression.

func NewMatch

func NewMatch(v interface{}, cs []MatchCase) Match

NewMatch creates a match expression.

func (Match) Cases

func (m Match) Cases() []MatchCase

Cases returns pairs of a pattern and corrensponding value in a match expression.

func (Match) String

func (m Match) String() string

func (Match) Value

func (m Match) Value() interface{}

Value returns a value which will be matched with patterns in a match expression.

type MatchCase

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

MatchCase represents a case of a pattern and corrensponding value.

func NewMatchCase

func NewMatchCase(p interface{}, v interface{}) MatchCase

NewMatchCase creates a case in a match expression.

func (MatchCase) Pattern

func (c MatchCase) Pattern() interface{}

Pattern returns a pattern of a case in a match expression.

func (MatchCase) String

func (c MatchCase) String() string

func (MatchCase) Value

func (c MatchCase) Value() interface{}

Value returns a value corrensponding to a pattern in a match expression.

type MutualRecursion

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

MutualRecursion represents a definition of mutually-recursive functions.

func NewMutualRecursion

func NewMutualRecursion(fs []DefFunction, i *debug.Info) MutualRecursion

NewMutualRecursion creates a mutual recursion node from mutually-recursive functions.

func (MutualRecursion) DebugInfo

func (mr MutualRecursion) DebugInfo() *debug.Info

DebugInfo returns debug information of mutually-recursive function definition.

func (MutualRecursion) DefFunctions

func (mr MutualRecursion) DefFunctions() []DefFunction

DefFunctions returns let-function statements in a mutual recursion definition.

func (MutualRecursion) String

func (mr MutualRecursion) String() string

type OptionalParameter

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

OptionalParameter represents an optional argument defined in a function.

func NewOptionalParameter

func NewOptionalParameter(n string, v interface{}) OptionalParameter

NewOptionalParameter creates an optional argument.

func (OptionalParameter) DefaultValue

func (o OptionalParameter) DefaultValue() interface{}

DefaultValue returns a default value of an optional argument.

func (OptionalParameter) Name

func (o OptionalParameter) Name() string

Name returns a name of an optional argument.

func (OptionalParameter) String

func (o OptionalParameter) String() string

type PositionalArgument

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

PositionalArgument represents a positional argument passed to a function.

func NewPositionalArgument

func NewPositionalArgument(value interface{}, expanded bool) PositionalArgument

NewPositionalArgument creates a positional argument.

func (PositionalArgument) Expanded

func (p PositionalArgument) Expanded() bool

Expanded returns true if a positional argument is an expanded list or false otherwise.

func (PositionalArgument) String

func (p PositionalArgument) String() string

func (PositionalArgument) Value

func (p PositionalArgument) Value() interface{}

Value returns a value of a positional argument.

type Signature

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

Signature represents a signature of a function.

func NewSignature

func NewSignature(ps []string, pr string, ks []OptionalParameter, kr string) Signature

NewSignature creates a Signature from {positional, keyword} x {required, optional} arguments and a positional rest argument and a keyword rest argument.

func (Signature) Keywords

func (s Signature) Keywords() []OptionalParameter

Keywords returns keyword optional arguments of a signature.

func (Signature) NameToIndex

func (s Signature) NameToIndex() map[string]int

NameToIndex converts an argument name into an index in arguments inside a signature.

func (Signature) Positionals

func (s Signature) Positionals() []string

Positionals returns positional required arguments of a signature.

func (Signature) RestKeywords

func (s Signature) RestKeywords() string

RestKeywords returns a keyword rest argument of a signature.

func (Signature) RestPositionals

func (s Signature) RestPositionals() string

RestPositionals returns a positional rest argument of a signature.

func (Signature) String

func (s Signature) String() string

type Switch

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

Switch represents a switch expression.

func NewSwitch

func NewSwitch(v interface{}, cs []SwitchCase, d interface{}) Switch

NewSwitch creates a match expression.

func (Switch) Cases

func (s Switch) Cases() []SwitchCase

Cases returns pairs of a pattern and corrensponding value in a match expression.

func (Switch) DefaultCase

func (s Switch) DefaultCase() interface{}

DefaultCase returns a default case in a switch expression.

func (Switch) String

func (s Switch) String() string

func (Switch) Value

func (s Switch) Value() interface{}

Value returns a value which will be matched with patterns in a match expression.

type SwitchCase

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

SwitchCase represents a case of a pattern and corrensponding value.

func NewSwitchCase

func NewSwitchCase(p string, v interface{}) SwitchCase

NewSwitchCase creates a case in a switch expression.

func (SwitchCase) Pattern

func (c SwitchCase) Pattern() string

Pattern returns a pattern of a case in a switch expression.

func (SwitchCase) String

func (c SwitchCase) String() string

func (SwitchCase) Value

func (c SwitchCase) Value() interface{}

Value returns a value corrensponding to a pattern in a switch expression.

Jump to

Keyboard shortcuts

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