ast

package
v0.0.0-...-6c20dd6 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllNumberBinarySuffixNames

func AllNumberBinarySuffixNames() []string

AllNumberBinarySuffixNames returns all names of NumberBinarySuffix

func MarshalNumberLitValue

func MarshalNumberLitValue(v NumberLitValue) ([]byte, error)

MarshalJSON implements custom JSON marshaling for NumberLitValue

Types

type AnyType

type AnyType struct{}

AnyType represents a the any type

func (*AnyType) TypeName

func (n *AnyType) TypeName() string

type Arguments

type Arguments struct {
	Args     []*Node[Identifier] `json:"args"`
	Defaults []*Node[Expr]       `json:"defaults,omitempty"` // Slice can contain nil to represent Rust's Vec<Option<Node<Expr>>>
	TyList   []*Node[Type]       `json:"ty_list,omitempty"`  // Slice can contain nil to represent Rust's Vec<Option<Node<Type>>>
}

Arguments represents function arguments, e.g.

lambda x: int = 1, y: int = 1 {
    x + y
}

func NewArguments

func NewArguments() *Arguments

NewArguments creates a new Arguments

func (*Arguments) MarshalJSON

func (a *Arguments) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Arguments

func (*Arguments) UnmarshalJSON

func (a *Arguments) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Arguments

type AssertStmt

type AssertStmt struct {
	BaseStmt
	Test   *Node[Expr] `json:"test"`
	IfCond *Node[Expr] `json:"if_cond,omitempty"`
	Msg    *Node[Expr] `json:"msg,omitempty"`
}

AssertStmt represents an assert statement, e.g.

assert True if condition, "Assert failed message"

func NewAssertStmt

func NewAssertStmt() *AssertStmt

NewAssertStmt creates a new AssertStmt

func (*AssertStmt) MarshalJSON

func (a *AssertStmt) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for AssertStmt

func (*AssertStmt) UnmarshalJSON

func (a *AssertStmt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for AssertStmt

type AssignStmt

type AssignStmt struct {
	BaseStmt
	Targets []*Node[Target] `json:"targets"`
	Value   *Node[Expr]     `json:"value"`
	Ty      *Node[Type]     `json:"ty"`
}

AssignStmt represents an assignment, e.g.

a: int = 1

a = 1

a = b = 1

func NewAssignStmt

func NewAssignStmt() *AssignStmt

NewAssignStmt creates a new AssignStmt

func (*AssignStmt) MarshalJSON

func (a *AssignStmt) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for AssignStmt

func (*AssignStmt) UnmarshalJSON

func (a *AssignStmt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for AssignStmt

type AstIndex

type AstIndex string

AstIndex represents a unique identifier for AST nodes.

type AugAssignStmt

type AugAssignStmt struct {
	BaseStmt
	Target *Node[Target] `json:"target"`
	Value  *Node[Expr]   `json:"value"`
	Op     AugOp         `json:"op"`
}

AugAssignStmt represents an augmented assignment, e.g.

a += 1

a -= 1

func NewAugAssignStmt

func NewAugAssignStmt() *AugAssignStmt

NewAugAssignStmt creates a new AugAssignStmt

func (*AugAssignStmt) MarshalJSON

func (a *AugAssignStmt) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for AugAssignStmt

func (*AugAssignStmt) UnmarshalJSON

func (a *AugAssignStmt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for AugAssignStmt

type AugOp

type AugOp string

AugOp represents augmented assignment operations

const (
	AugOpAssign   AugOp = "="
	AugOpAdd      AugOp = "+="
	AugOpSub      AugOp = "-="
	AugOpMul      AugOp = "*="
	AugOpDiv      AugOp = "/="
	AugOpMod      AugOp = "%="
	AugOpPow      AugOp = "**="
	AugOpFloorDiv AugOp = "//="
	AugOpLShift   AugOp = "<<="
	AugOpRShift   AugOp = ">>="
	AugOpBitXor   AugOp = "^="
	AugOpBitAnd   AugOp = "&="
	AugOpBitOr    AugOp = "|="
)

func (AugOp) Symbol

func (a AugOp) Symbol() string

Symbol returns the string representation of the AugOp

func (AugOp) ToBinOp

func (a AugOp) ToBinOp() (BinOp, error)

ToBinOp converts AugOp to BinOp, if possible

type BaseExpr

type BaseExpr struct {
	ExprType string `json:"type"`
}

BaseExpr is a struct that all expression types can embed to implement the Expr interface

func (BaseExpr) Type

func (b BaseExpr) Type() string

type BaseStmt

type BaseStmt struct {
	StmtType string `json:"type"`
}

BaseStmt is a struct that all statement types can embed to implement the Stmt interface

func (BaseStmt) Type

func (b BaseStmt) Type() string

type BasicType

type BasicType struct {
	Value BasicTypeEnum `json:"value"`
}

BasicType represents a basic type

func (*BasicType) TypeName

func (b *BasicType) TypeName() string

type BasicTypeEnum

type BasicTypeEnum string
const (
	Bool  BasicTypeEnum = "Bool"
	Int   BasicTypeEnum = "Int"
	Float BasicTypeEnum = "Float"
	Str   BasicTypeEnum = "Str"
)

type BinOp

type BinOp string

BinOp represents a binary operator

const (
	BinOpAdd      BinOp = "+"
	BinOpSub      BinOp = "-"
	BinOpMul      BinOp = "*"
	BinOpDiv      BinOp = "/"
	BinOpMod      BinOp = "%"
	BinOpPow      BinOp = "**"
	BinOpFloorDiv BinOp = "//"
	BinOpLShift   BinOp = "<<"
	BinOpRShift   BinOp = ">>"
	BinOpBitXor   BinOp = "^"
	BinOpBitAnd   BinOp = "&"
	BinOpBitOr    BinOp = "|"
	BinOpAnd      BinOp = "and"
	BinOpOr       BinOp = "or"
	BinOpAs       BinOp = "as"
)

func AllBinOps

func AllBinOps() []BinOp

AllBinOps returns all possible BinOp values

func BinOpFromSymbol

func BinOpFromSymbol(symbol string) (BinOp, bool)

BinOpFromSymbol returns the BinOp corresponding to the given symbol

func (BinOp) Symbol

func (op BinOp) Symbol() string

Symbol returns the string representation of the binary operator

type BinaryExpr

type BinaryExpr struct {
	BaseExpr
	Left  *Node[Expr] `json:"left"`
	Op    BinOp       `json:"op"`
	Right *Node[Expr] `json:"right"`
}

BinaryExpr represents a binary expression, e.g.

1 + 1 3 - 2 5 / 2 a is None

func NewBinaryExpr

func NewBinaryExpr() *BinaryExpr

NewBinaryExpr creates a new BinaryExpr

type BoolLiteralType

type BoolLiteralType bool

BoolLiteralType represents a boolean literal type

func (*BoolLiteralType) LiteralTypeName

func (b *BoolLiteralType) LiteralTypeName() string

type CallExpr

type CallExpr struct {
	BaseExpr
	Func     *Node[Expr]      `json:"func"`
	Args     []*Node[Expr]    `json:"args"`
	Keywords []*Node[Keyword] `json:"keywords"`
}

CallExpr represents a function call expression, e.g.

func1() func2(1) func3(x=2)

func NewCallExpr

func NewCallExpr() *CallExpr

NewCallExpr creates a new CallExpr

func (*CallExpr) MarshalJSON

func (c *CallExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for CallExpr

func (*CallExpr) UnmarshalJSON

func (c *CallExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for CallExpr

type CheckExpr

type CheckExpr struct {
	Test   *Node[Expr] `json:"test"`
	IfCond *Node[Expr] `json:"if_cond,omitempty"`
	Msg    *Node[Expr] `json:"msg,omitempty"`
}

CheckExpr represents a check expression, e.g.

len(attr) > 3 if attr, "Check failed message"

func NewCheckExpr

func NewCheckExpr() *CheckExpr

NewCheckExpr creates a new CheckExpr

func (*CheckExpr) MarshalJSON

func (c *CheckExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for CheckExpr

func (*CheckExpr) UnmarshalJSON

func (c *CheckExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for CheckExpr

type CmpOp

type CmpOp string

CmpOp represents a comparison operator

const (
	CmpOpEq    CmpOp = "=="
	CmpOpNotEq CmpOp = "!="
	CmpOpLt    CmpOp = "<"
	CmpOpLtE   CmpOp = "<="
	CmpOpGt    CmpOp = ">"
	CmpOpGtE   CmpOp = ">="
	CmpOpIs    CmpOp = "is"
	CmpOpIn    CmpOp = "in"
	CmpOpNotIn CmpOp = "not in"
	CmpOpNot   CmpOp = "not"
	CmpOpIsNot CmpOp = "is not"
)

func AllCmpOps

func AllCmpOps() []CmpOp

AllCmpOps returns all possible CmpOp values

func CmpOpFromString

func CmpOpFromString(s string) (CmpOp, bool)

CmpOpFromString returns the CmpOp corresponding to the given string

func (CmpOp) Symbol

func (c CmpOp) Symbol() string

Symbol returns the string representation of the comparison operator

type Comment

type Comment struct {
	Text string
}

Comment node.

type CompClause

type CompClause struct {
	BaseExpr
	Targets []*Node[Identifier] `json:"targets"`
	Iter    *Node[Expr]         `json:"iter"`
	Ifs     []*Node[Expr]       `json:"ifs"`
}

CompClause represents a comprehension clause, e.g.

i, a in [1, 2, 3] if i > 1 and a > 1

func NewCompClause

func NewCompClause() *CompClause

NewCompClause creates a new CompClause

func (*CompClause) MarshalJSON

func (c *CompClause) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for CompClause

func (*CompClause) UnmarshalJSON

func (c *CompClause) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for CompClause

type Compare

type Compare struct {
	BaseExpr
	Left        *Node[Expr]   `json:"left"`
	Ops         []CmpOp       `json:"ops"`
	Comparators []*Node[Expr] `json:"comparators"`
}

Compare represents a comparison expression, e.g.

0 < a < 10 b is not None c != d

func NewCompare

func NewCompare() *Compare

NewCompare creates a new Compare

func (*Compare) MarshalJSON

func (c *Compare) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Compare

func (*Compare) UnmarshalJSON

func (c *Compare) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Compare

type ConfigEntry

type ConfigEntry struct {
	Key       *Node[Expr]          `json:"key"`
	Value     *Node[Expr]          `json:"value"`
	Operation ConfigEntryOperation `json:"operation"`
}

ConfigEntry represents a configuration entry, e.g.

{
  attr1 = 1
  attr2 += [0, 1]
  attr3: {key = value}
}

func NewConfigEntry

func NewConfigEntry() *ConfigEntry

NewConfigEntry creates a new ConfigEntry

func (*ConfigEntry) MarshalJSON

func (c *ConfigEntry) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ConfigEntry

func (*ConfigEntry) UnmarshalJSON

func (c *ConfigEntry) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ConfigEntry

type ConfigEntryOperation

type ConfigEntryOperation string

ConfigEntryOperation represents the operation of a configuration entry

const (
	ConfigEntryOperationUnion    ConfigEntryOperation = "Union"
	ConfigEntryOperationOverride ConfigEntryOperation = "Override"
	ConfigEntryOperationInsert   ConfigEntryOperation = "Insert"
)

func AllConfigEntryOperations

func AllConfigEntryOperations() []ConfigEntryOperation

AllConfigEntryOperations returns all possible ConfigEntryOperation values

func ConfigEntryOperationFromString

func ConfigEntryOperationFromString(s string) (ConfigEntryOperation, error)

ConfigEntryOperationFromString returns the ConfigEntryOperation corresponding to the given string

func (ConfigEntryOperation) String

func (c ConfigEntryOperation) String() string

String returns the string representation of the ConfigEntryOperation

func (ConfigEntryOperation) Symbol

func (c ConfigEntryOperation) Symbol() string

Symbol returns the symbol representation of the ConfigEntryOperation

func (ConfigEntryOperation) Value

func (c ConfigEntryOperation) Value() int

Value returns the integer value of the ConfigEntryOperation

type ConfigExpr

type ConfigExpr struct {
	BaseExpr
	Items []*Node[ConfigEntry] `json:"items"`
}

ConfigExpr represents a configuration expression, e.g.

{
  attr1 = 1
  attr2 += [0, 1]
  attr3: {key = value}
}

func NewConfigExpr

func NewConfigExpr() *ConfigExpr

NewConfigExpr creates a new ConfigExpr

func (*ConfigExpr) MarshalJSON

func (c *ConfigExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ConfigExpr

func (*ConfigExpr) UnmarshalJSON

func (c *ConfigExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ConfigExpr

type ConfigIfEntryExpr

type ConfigIfEntryExpr struct {
	BaseExpr
	IfCond *Node[Expr]          `json:"if_cond"`
	Items  []*Node[ConfigEntry] `json:"items"`
	Orelse *Node[Expr]          `json:"orelse"`
}

ConfigIfEntryExpr represents a conditional configuration entry, e.g.

{
  k1 = 1
  if condition:
    k2 = 2
}

func NewConfigIfEntryExpr

func NewConfigIfEntryExpr() *ConfigIfEntryExpr

NewConfigIfEntryExpr creates a new ConfigIfEntryExpr

func (*ConfigIfEntryExpr) MarshalJSON

func (c *ConfigIfEntryExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ConfigIfEntryExpr

func (*ConfigIfEntryExpr) UnmarshalJSON

func (c *ConfigIfEntryExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ConfigIfEntryExpr

type Decorator

type Decorator struct {
	Func     *Node[Expr]      `json:"func"`
	Args     []*Node[Expr]    `json:"args,omitempty"`
	Keywords []*Node[Keyword] `json:"keywords,omitempty"`
}

Decorator represents a decorator, e.g.

deprecated(strict=True)

func NewDecorator

func NewDecorator() *Decorator

NewDecorator creates a new Decorator

func (*Decorator) MarshalJSON

func (d *Decorator) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Decorator

func (*Decorator) UnmarshalJSON

func (d *Decorator) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Decorator

type DictComp

type DictComp struct {
	BaseExpr
	Entry      ConfigEntry         `json:"entry"`
	Generators []*Node[CompClause] `json:"generators"`
}

DictComp represents a dictionary comprehension expression, e.g.

{k: v + 1 for k, v in {k1 = 1, k2 = 2}}

func NewDictComp

func NewDictComp() *DictComp

NewDictComp creates a new DictComp

func (*DictComp) MarshalJSON

func (d *DictComp) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for DictComp

func (*DictComp) UnmarshalJSON

func (d *DictComp) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for DictComp

type DictType

type DictType struct {
	Value struct {
		KeyType   *Node[Type] `json:"key_type,omitempty"`
		ValueType *Node[Type] `json:"value_type,omitempty"`
	} `json:"value"`
}

DictType represents a dictionary type

func (*DictType) TypeName

func (d *DictType) TypeName() string

type Expr

type Expr interface {
	Type() string
}

Expr is an interface for all expression types

func UnmarshalExpr

func UnmarshalExpr(data []byte) (Expr, error)

UnmarshalExprJSON implements custom JSON unmarshaling for Expr

type ExprContext

type ExprContext int

ExprContext denotes the value context in the expression. e.g.,

The context of 'a' in 'a = b' is Store

The context of 'b' in 'a = b' is Load

const (
	Load ExprContext = iota
	Store
)

func (ExprContext) MarshalJSON

func (e ExprContext) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ExprContext

func (ExprContext) String

func (e ExprContext) String() string

String returns the string representation of ExprContext

func (*ExprContext) UnmarshalJSON

func (e *ExprContext) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ExprContext

type ExprStmt

type ExprStmt struct {
	BaseStmt
	Exprs []*Node[Expr] `json:"exprs"`
}

ExprStmt represents a expression statement, e.g.

1

"""A long string"""

'A string'

func NewExprStmt

func NewExprStmt() *ExprStmt

NewExprStmt creates a new ExprStmt

type FloatLiteralType

type FloatLiteralType float64

FloatLiteralType represents a float literal type

func (*FloatLiteralType) LiteralTypeName

func (f *FloatLiteralType) LiteralTypeName() string

type FloatNumberLitValue

type FloatNumberLitValue struct {
	Value float64 `json:"value"`
}

FloatNumberLitValue represents a float number literal value

func (*FloatNumberLitValue) Type

func (f *FloatNumberLitValue) Type() string

Type returns the type of the number literal value

type FormattedValue

type FormattedValue struct {
	BaseExpr
	IsLongString bool        `json:"is_long_string"`
	Value        *Node[Expr] `json:"value"`
	FormatSpec   string      `json:"format_spec"`
}

FormattedValue represents a formatted value, e.g. var1 and var2 in the string interpolation "${var1} abc ${var2}"

func NewFormattedValue

func NewFormattedValue() *FormattedValue

NewFormattedValue creates a new FormattedValue

func (*FormattedValue) MarshalJSON

func (f *FormattedValue) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for FormattedValue

func (*FormattedValue) UnmarshalJSON

func (f *FormattedValue) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for FormattedValue

type FunctionType

type FunctionType struct {
	Value struct {
		ParamsTy []*Node[Type] `json:"params_ty,omitempty"`
		RetTy    *Node[Type]   `json:"ret_ty,omitempty"`
	} `json:"value"`
}

FunctionType represents a function type

func (*FunctionType) TypeName

func (f *FunctionType) TypeName() string

type Identifier

type Identifier struct {
	Names   []*Node[string] `json:"names"`
	Pkgpath string          `json:"pkgpath"`
	Ctx     ExprContext     `json:"ctx"`
}

Identifier represents an identifier, e.g.

a b _c pkg.a

type IdentifierExpr

type IdentifierExpr struct {
	BaseExpr
	Identifier
}

IdentifierExpr represents an identifier expression, e.g.

a b _c pkg.a

func NewIdentifierExpr

func NewIdentifierExpr() *IdentifierExpr

NewIdentifierExpr creates a new IdentifierExpr

func (*IdentifierExpr) MarshalJSON

func (i *IdentifierExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for IdentifierExpr

func (*IdentifierExpr) UnmarshalJSON

func (i *IdentifierExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for IdentifierExpr

type IfExpr

type IfExpr struct {
	BaseExpr
	Body   *Node[Expr] `json:"body"`
	Cond   *Node[Expr] `json:"cond"`
	Orelse *Node[Expr] `json:"orelse"`
}

IfExpr represents an if expression, e.g.

1 if condition else 2

func NewIfExpr

func NewIfExpr() *IfExpr

NewIfExpr creates a new IfExpr

func (*IfExpr) MarshalJSON

func (i *IfExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for IfExpr

func (*IfExpr) UnmarshalJSON

func (i *IfExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for IfExpr

type IfStmt

type IfStmt struct {
	BaseStmt
	Body   []*Node[Stmt] `json:"body"`
	Cond   *Node[Expr]   `json:"cond"`
	Orelse []*Node[Stmt] `json:"orelse,omitempty"`
}

IfStmt represents an if statement, e.g.

if condition1:

if condition2:
    a = 1

elif condition3:

b = 2

else:

c = 3

func NewIfStmt

func NewIfStmt() *IfStmt

NewIfStmt creates a new IfStmt

func (*IfStmt) MarshalJSON

func (i *IfStmt) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for IfStmt

func (*IfStmt) UnmarshalJSON

func (i *IfStmt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for IfStmt

type ImportStmt

type ImportStmt struct {
	BaseStmt
	Path    *Node[string] `json:"path"`
	Rawpath string        `json:"rawpath"`
	Name    string        `json:"name"`
	Asname  *Node[string] `json:"asname,omitempty"`
	PkgName string        `json:"pkg_name"`
}

ImportStmt represents an import statement, e.g.

import pkg as pkg_alias

func NewImportStmt

func NewImportStmt() *ImportStmt

NewImportStmt creates a new ImportStmt

func (*ImportStmt) MarshalJSON

func (i *ImportStmt) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ImportStmt

func (*ImportStmt) UnmarshalJSON

func (i *ImportStmt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ImportStmt

type Index

type Index struct {
	Value *Node[Expr] `json:"value"`
}

Index represents an index access

func (*Index) Type

func (i *Index) Type() string

Type returns the type of Index

type IntLiteralType

type IntLiteralType struct {
	Value  int                 `json:"value"`
	Suffix *NumberBinarySuffix `json:"binary_suffix,omitempty"`
}

IntLiteralType represents an integer literal type

func (*IntLiteralType) LiteralTypeName

func (i *IntLiteralType) LiteralTypeName() string

type IntNumberLitValue

type IntNumberLitValue struct {
	Value int64 `json:"value"`
}

IntNumberLitValue represents an integer number literal value

func (*IntNumberLitValue) Type

func (i *IntNumberLitValue) Type() string

Type returns the type of the number literal value

type JoinedString

type JoinedString struct {
	BaseExpr
	IsLongString bool          `json:"is_long_string"`
	Values       []*Node[Expr] `json:"values"`
	RawValue     string        `json:"raw_value"`
}

JoinedString represents a joined string, e.g. abc in the string interpolation "${var1} abc ${var2}"

func NewJoinedString

func NewJoinedString() *JoinedString

NewJoinedString creates a new JoinedString

func (*JoinedString) MarshalJSON

func (j *JoinedString) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for JoinedString

func (*JoinedString) UnmarshalJSON

func (j *JoinedString) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for JoinedString

type Keyword

type Keyword struct {
	Arg   *Node[Identifier] `json:"arg"`
	Value *Node[Expr]       `json:"value"`
}

Keyword represents a keyword argument, e.g.

arg = value

func (*Keyword) MarshalJSON

func (k *Keyword) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Keyword

func (*Keyword) UnmarshalJSON

func (k *Keyword) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Keyword

type LambdaExpr

type LambdaExpr struct {
	BaseExpr
	Args     *Node[Arguments] `json:"args"`
	Body     []*Node[Stmt]    `json:"body"`
	ReturnTy *Node[Type]      `json:"return_ty"`
}

LambdaExpr represents a lambda expression, e.g.

lambda x, y {
  z = 2 * x
  z + y
}

func NewLambdaExpr

func NewLambdaExpr() *LambdaExpr

NewLambdaExpr creates a new LambdaExpr

func (*LambdaExpr) MarshalJSON

func (l *LambdaExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for LambdaExpr

func (*LambdaExpr) UnmarshalJSON

func (l *LambdaExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for LambdaExpr

type ListComp

type ListComp struct {
	BaseExpr
	Elt        *Node[Expr]         `json:"elt"`
	Generators []*Node[CompClause] `json:"generators"`
}

ListComp represents a list comprehension expression, e.g.

[x ** 2 for x in [1, 2, 3]]

func NewListComp

func NewListComp() *ListComp

NewListComp creates a new ListComp

func (*ListComp) MarshalJSON

func (l *ListComp) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ListComp

func (*ListComp) UnmarshalJSON

func (l *ListComp) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ListComp

type ListExpr

type ListExpr struct {
	BaseExpr
	Elts []*Node[Expr] `json:"elts"`
	Ctx  ExprContext   `json:"ctx"`
}

ListExpr represents a list expression, e.g.

[1, 2, 3] [1, if True: 2, 3]

func NewListExpr

func NewListExpr() *ListExpr

NewListExpr creates a new ListExpr

func (*ListExpr) MarshalJSON

func (l *ListExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ListExpr

func (*ListExpr) UnmarshalJSON

func (l *ListExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ListExpr

type ListIfItemExpr

type ListIfItemExpr struct {
	BaseExpr
	IfCond *Node[Expr]   `json:"if_cond"`
	Exprs  []*Node[Expr] `json:"exprs"`
	Orelse *Node[Expr]   `json:"orelse"`
}

ListIfItemExpr represents a list if-item expression, e.g.

[1, if True: 2, 3]

func NewListIfItemExpr

func NewListIfItemExpr() *ListIfItemExpr

NewListIfItemExpr creates a new ListIfItemExpr

func (*ListIfItemExpr) MarshalJSON

func (l *ListIfItemExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ListIfItemExpr

func (*ListIfItemExpr) UnmarshalJSON

func (l *ListIfItemExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ListIfItemExpr

type ListType

type ListType struct {
	Value struct {
		InnerType *Node[Type] `json:"inner_type,omitempty"`
	} `json:"value"`
}

ListType represents a list type

func (*ListType) TypeName

func (l *ListType) TypeName() string

type LiteralType

type LiteralType struct {
	Value LiteralTypeValue `json:"value"`
}

LiteralType represents a literal type

func (*LiteralType) TypeName

func (l *LiteralType) TypeName() string

type LiteralTypeValue

type LiteralTypeValue interface {
	LiteralTypeName() string
}

LiteralTypeValue is an interface for different literal types

type Member

type Member struct {
	Value *Node[string] `json:"value"`
}

Member represents a member access

func (*Member) Type

func (m *Member) Type() string

Type returns the type of Member

type MemberOrIndex

type MemberOrIndex interface {
	Type() string
}

MemberOrIndex is the base interface for member or index expression

a.<member> b[<index>]

func UnmarshalMemberOrIndex

func UnmarshalMemberOrIndex(data []byte) (MemberOrIndex, error)

UnmarshalMemberOrIndex is a helper function to unmarshal JSON into MemberOrIndex

type MissingExpr

type MissingExpr struct {
	BaseExpr
}

MissingExpr is a placeholder for error recovery

func NewMissingExpr

func NewMissingExpr() *MissingExpr

NewMissingExpr creates a new MissingExpr

func (*MissingExpr) MarshalJSON

func (m *MissingExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for MissingExpr

func (*MissingExpr) UnmarshalJSON

func (m *MissingExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for MissingExpr

type Module

type Module struct {
	Filename string           `json:"filename"`
	Pkg      string           `json:"pkg"`
	Doc      *Node[string]    `json:"doc"`
	Body     []*Node[Stmt]    `json:"body"`
	Comments []*Node[Comment] `json:"comments"`
}

Module is an abstract syntax tree for a single KCL file.

func NewModule

func NewModule() *Module

NewModule creates a new Module instance

type NameConstant

type NameConstant string

NameConstant represents a name constant, e.g.

True False None Undefined

const (
	NameConstantTrue      NameConstant = "True"
	NameConstantFalse     NameConstant = "False"
	NameConstantNone      NameConstant = "None"
	NameConstantUndefined NameConstant = "Undefined"
)

func AllNameConstants

func AllNameConstants() []NameConstant

AllNameConstants returns all possible NameConstant values

func (NameConstant) JSONValue

func (n NameConstant) JSONValue() string

JSONValue returns the JSON value for each constant

func (NameConstant) MarshalJSON

func (n NameConstant) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for NameConstant

func (NameConstant) Symbol

func (n NameConstant) Symbol() string

Symbol returns the symbol for each constant

func (*NameConstant) UnmarshalJSON

func (n *NameConstant) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for NameConstant

type NameConstantLit

type NameConstantLit struct {
	BaseExpr
	Value NameConstant `json:"value"`
}

NameConstantLit represents a name constant literal, e.g.

True False None Undefined

func NewNameConstantLit

func NewNameConstantLit() *NameConstantLit

NewNameConstantLit creates a new NameConstantLit

func (*NameConstantLit) MarshalJSON

func (n *NameConstantLit) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for NameConstantLit

func (*NameConstantLit) UnmarshalJSON

func (n *NameConstantLit) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for NameConstantLit

type NamedType

type NamedType struct {
	Value struct {
		Identifier *Identifier `json:"identifier"`
	} `json:"value"`
}

NamedType represents a named type

func (*NamedType) TypeName

func (n *NamedType) TypeName() string

type Node

type Node[T any] struct {
	ID   AstIndex `json:"id,omitempty"`
	Node T        `json:"node,omitempty"`
	Pos
}

Node is the file, line and column number information that all AST nodes need to contain. In fact, column and end_column are the counts of character. For example, `\t` is counted as 1 character, so it is recorded as 1 here, but generally col is 4.

func (*Node[Stmt]) MarshalJSON

func (n *Node[Stmt]) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*Node[T]) UnmarshalJSON

func (n *Node[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type NumberBinarySuffix

type NumberBinarySuffix string

NumberBinarySuffix represents the binary suffix of a number

const (
	NumberBinarySuffixN  NumberBinarySuffix = "n"
	NumberBinarySuffixU  NumberBinarySuffix = "u"
	NumberBinarySuffixM  NumberBinarySuffix = "m"
	NumberBinarySuffixK  NumberBinarySuffix = "k"
	NumberBinarySuffixKU NumberBinarySuffix = "K"
	NumberBinarySuffixMU NumberBinarySuffix = "M"
	NumberBinarySuffixG  NumberBinarySuffix = "G"
	NumberBinarySuffixT  NumberBinarySuffix = "T"
	NumberBinarySuffixP  NumberBinarySuffix = "P"
	NumberBinarySuffixKi NumberBinarySuffix = "Ki"
	NumberBinarySuffixMi NumberBinarySuffix = "Mi"
	NumberBinarySuffixGi NumberBinarySuffix = "Gi"
	NumberBinarySuffixTi NumberBinarySuffix = "Ti"
	NumberBinarySuffixPi NumberBinarySuffix = "Pi"
)

func AllNumberBinarySuffixes

func AllNumberBinarySuffixes() []NumberBinarySuffix

AllNumberBinarySuffixes returns all possible NumberBinarySuffix values

func NumberBinarySuffixFromString

func NumberBinarySuffixFromString(s string) (NumberBinarySuffix, bool)

NumberBinarySuffixFromString returns the NumberBinarySuffix corresponding to the given string

func (NumberBinarySuffix) Value

func (n NumberBinarySuffix) Value() string

Value returns the string representation of the NumberBinarySuffix

type NumberLit

type NumberLit struct {
	BaseExpr
	BinarySuffix *NumberBinarySuffix `json:"binary_suffix,omitempty"`
	Value        NumberLitValue      `json:"value"`
}

NumberLit represents a number literal, e.g.

1 2.0 1m 1K 1Mi

func NewNumberLit

func NewNumberLit() *NumberLit

NewNumberLit creates a new NumberLit

func (*NumberLit) MarshalJSON

func (n *NumberLit) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for NumberLit

func (*NumberLit) UnmarshalJSON

func (n *NumberLit) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for NumberLit

type NumberLitValue

type NumberLitValue interface {
	Type() string
}

NumberLitValue represents the value of a number literal

func UnmarshalNumberLitValue

func UnmarshalNumberLitValue(data []byte) (NumberLitValue, error)

UnmarshalNumberLitValue unmarshals JSON data into a NumberLitValue

type ParenExpr

type ParenExpr struct {
	BaseExpr
	Expr *Node[Expr] `json:"expr"`
}

ParenExpr represents a parenthesized expression, e.g.

1 + (2 - 3)

func NewParenExpr

func NewParenExpr() *ParenExpr

NewParenExpr creates a new ParenExpr

func (*ParenExpr) MarshalJSON

func (p *ParenExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for ParenExpr

func (*ParenExpr) UnmarshalJSON

func (p *ParenExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ParenExpr

type Pos

type Pos struct {
	Filename  string `json:"filename,omitempty"`
	Line      int64  `json:"line,omitempty"`
	Column    int64  `json:"column,omitempty"`
	EndLine   int64  `json:"end_line,omitempty"`
	EndColumn int64  `json:"end_column,omitempty"`
}

Pos denotes the struct tuple (filename, line, column, end_line, end_column).

type QuantExpr

type QuantExpr struct {
	BaseExpr
	Target    *Node[Expr]         `json:"target"`
	Variables []*Node[Identifier] `json:"variables"`
	Op        QuantOperation      `json:"op"`
	Test      *Node[Expr]         `json:"test"`
	IfCond    *Node[Expr]         `json:"if_cond"`
	Ctx       ExprContext         `json:"ctx"`
}

QuantExpr represents a quantifier expression, e.g.

all x in collection {x > 0} any y in collection {y < 0} map x in collection {x + 1} filter x in collection {x > 1}

func NewQuantExpr

func NewQuantExpr() *QuantExpr

NewQuantExpr creates a new QuantExpr

func (*QuantExpr) MarshalJSON

func (q *QuantExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for QuantExpr

func (*QuantExpr) UnmarshalJSON

func (q *QuantExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for QuantExpr

type QuantOperation

type QuantOperation string

QuantOperation represents the operation of a quantifier expression

const (
	QuantOperationAll    QuantOperation = "All"
	QuantOperationAny    QuantOperation = "Any"
	QuantOperationFilter QuantOperation = "Filter"
	QuantOperationMap    QuantOperation = "Map"
)

func AllQuantOperations

func AllQuantOperations() []QuantOperation

AllQuantOperations returns all possible QuantOperation values

func QuantOperationFromString

func QuantOperationFromString(s string) (QuantOperation, bool)

QuantOperationFromString returns the QuantOperation corresponding to the given string

func (QuantOperation) String

func (qo QuantOperation) String() string

String returns the string representation of the QuantOperation

type RuleStmt

type RuleStmt struct {
	BaseStmt
	Doc         *Node[string]       `json:"doc,omitempty"`
	Name        *Node[string]       `json:"name"`
	ParentRules []*Node[Identifier] `json:"parent_rules,omitempty"`
	Decorators  []*Node[Decorator]  `json:"decorators,omitempty"`
	Checks      []*Node[CheckExpr]  `json:"checks,omitempty"`
	Args        *Node[Arguments]    `json:"args,omitempty"`
	ForHostName *Node[Identifier]   `json:"for_host_name,omitempty"`
}

RuleStmt represents a rule statement, e.g.

rule RuleExample:

a > 1
b < 0

func NewRuleStmt

func NewRuleStmt() *RuleStmt

NewRuleStmt creates a new RuleStmt

func (*RuleStmt) MarshalJSON

func (r *RuleStmt) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for RuleStmt

func (*RuleStmt) UnmarshalJSON

func (r *RuleStmt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for RuleStmt

type SchemaAttr

type SchemaAttr struct {
	BaseStmt
	Doc        string             `json:"doc,omitempty"`
	Name       *Node[string]      `json:"name"`
	Op         AugOp              `json:"op,omitempty"`
	Value      *Node[Expr]        `json:"value,omitempty"`
	IsOptional bool               `json:"is_optional"`
	Decorators []*Node[Decorator] `json:"decorators,omitempty"`
	Ty         *Node[Type]        `json:"ty,omitempty"`
}

SchemaAttr represents schema attribute definitions, e.g.

schema SchemaAttrExample:

x: int
y: str

func NewSchemaAttr

func NewSchemaAttr() *SchemaAttr

NewSchemaAttr creates a new SchemaAttr

func (*SchemaAttr) MarshalJSON

func (s *SchemaAttr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for SchemaAttr

func (*SchemaAttr) UnmarshalJSON

func (s *SchemaAttr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for SchemaAttr

type SchemaConfig

type SchemaConfig struct {
	Name   *Node[Identifier] `json:"name"`
	Args   []*Node[Expr]     `json:"args"`
	Kwargs []*Node[Keyword]  `json:"kwargs"`
	Config *Node[Expr]       `json:"config"`
}

SchemaConfig represents a schema configuration, e.g.

ASchema(arguments) {
  attr1 = 1
  attr2 = BSchema {attr3 = 2}
}

func NewSchemaConfig

func NewSchemaConfig() *SchemaConfig

NewSchemaConfig creates a new SchemaConfig

func (*SchemaConfig) MarshalJSON

func (s *SchemaConfig) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for SchemaConfig

func (*SchemaConfig) UnmarshalJSON

func (s *SchemaConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for SchemaConfig

type SchemaExpr

type SchemaExpr struct {
	BaseExpr
	Name   *Node[Identifier] `json:"name"`
	Args   []*Node[Expr]     `json:"args"`
	Kwargs []*Node[Keyword]  `json:"kwargs"`
	Config *Node[Expr]       `json:"config"`
}

SchemaExpr represents a schema expression, e.g.

ASchema(arguments) {
  attr1 = 1
  attr2 = BSchema {attr3 = 2}
}

func NewSchemaExpr

func NewSchemaExpr() *SchemaExpr

NewSchemaExpr creates a new SchemaExpr

func (*SchemaExpr) MarshalJSON

func (s *SchemaExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for SchemaExpr

func (*SchemaExpr) UnmarshalJSON

func (s *SchemaExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for SchemaExpr

type SchemaIndexSignature

type SchemaIndexSignature struct {
	KeyName  *Node[string] `json:"key_name,omitempty"`
	Value    *Node[Expr]   `json:"value,omitempty"`
	AnyOther bool          `json:"any_other"`
	KeyTy    *Node[Type]   `json:"key_ty,omitempty"`
	ValueTy  *Node[Type]   `json:"value_ty,omitempty"`
}

SchemaIndexSignature represents a schema index signature, e.g.

schema SchemaIndexSignatureExample:

[str]: int

func NewSchemaIndexSignature

func NewSchemaIndexSignature() *SchemaIndexSignature

NewSchemaIndexSignature creates a new SchemaIndexSignature

func (*SchemaIndexSignature) MarshalJSON

func (s *SchemaIndexSignature) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for SchemaIndexSignature

func (*SchemaIndexSignature) UnmarshalJSON

func (s *SchemaIndexSignature) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for SchemaIndexSignature

type SchemaStmt

type SchemaStmt struct {
	BaseStmt
	Doc            *Node[string]               `json:"doc,omitempty"`
	Name           *Node[string]               `json:"name"`
	ParentName     *Node[Identifier]           `json:"parent_name,omitempty"`
	ForHostName    *Node[Identifier]           `json:"for_host_name,omitempty"`
	IsMixin        bool                        `json:"is_mixin"`
	IsProtocol     bool                        `json:"is_protocol"`
	Args           *Node[Arguments]            `json:"args,omitempty"`
	Mixins         []*Node[Identifier]         `json:"mixins,omitempty"`
	Body           []*Node[Stmt]               `json:"body,omitempty"`
	Decorators     []*Node[Decorator]          `json:"decorators,omitempty"`
	Checks         []*Node[CheckExpr]          `json:"checks,omitempty"`
	IndexSignature *Node[SchemaIndexSignature] `json:"index_signature,omitempty"`
}

SchemaStmt represents a schema statement, e.g.

schema BaseSchema:

schema SchemaExample(BaseSchema)[arg: str]:

"""Schema documents"""
attr?: str = arg
check:
    len(attr) > 3 if attr, "Check failed message"

mixin MixinExample for ProtocolExample:

attr: int

protocol ProtocolExample:

attr: int

func NewSchemaStmt

func NewSchemaStmt() *SchemaStmt

NewSchemaStmt creates a new SchemaStmt

func (*SchemaStmt) MarshalJSON

func (s *SchemaStmt) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for SchemaStmt

func (*SchemaStmt) UnmarshalJSON

func (s *SchemaStmt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for SchemaStmt

type SelectorExpr

type SelectorExpr struct {
	BaseExpr
	Value       *Node[Expr]       `json:"value"`
	Attr        *Node[Identifier] `json:"attr"`
	Ctx         ExprContext       `json:"ctx"`
	HasQuestion bool              `json:"has_question"`
}

SelectorExpr represents a selector expression, e.g.

x.y x?.y

func (*SelectorExpr) MarshalJSON

func (s *SelectorExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for SelectorExpr

func (*SelectorExpr) UnmarshalJSON

func (s *SelectorExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for SelectorExpr

type StarredExpr

type StarredExpr struct {
	BaseExpr
	Value *Node[Expr] `json:"value"`
	Ctx   ExprContext `json:"ctx"`
}

StarredExpr represents a starred expression, e.g.

[1, 2, *[3, 4]]

func NewStarredExpr

func NewStarredExpr() *StarredExpr

NewStarredExpr creates a new StarredExpr

func (*StarredExpr) MarshalJSON

func (s *StarredExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for StarredExpr

func (*StarredExpr) UnmarshalJSON

func (s *StarredExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for StarredExpr

type Stmt

type Stmt interface {
	Type() string
}

Stmt is an interface for all statement types

func UnmarshalStmt

func UnmarshalStmt(data []byte) (Stmt, error)

UnmarshalJSON implements custom JSON unmarshaling for Stmt

type StrLiteralType

type StrLiteralType string

StrLiteralType represents a string literal type

func (*StrLiteralType) LiteralTypeName

func (s *StrLiteralType) LiteralTypeName() string

type StringLit

type StringLit struct {
	BaseExpr
	IsLongString bool   `json:"is_long_string"`
	RawValue     string `json:"raw_value"`
	Value        string `json:"value"`
}

StringLit represents a string literal, e.g.

"string literal" """long string literal"""

func NewStringLit

func NewStringLit() *StringLit

NewStringLit creates a new StringLit with default values

func (*StringLit) MarshalJSON

func (s *StringLit) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for StringLit

func (*StringLit) UnmarshalJSON

func (s *StringLit) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for StringLit

type Subscript

type Subscript struct {
	BaseExpr
	Value       *Node[Expr] `json:"value"`
	Index       *Node[Expr] `json:"index"`
	Lower       *Node[Expr] `json:"lower"`
	Upper       *Node[Expr] `json:"upper"`
	Step        *Node[Expr] `json:"step"`
	Ctx         ExprContext `json:"ctx"`
	HasQuestion bool        `json:"has_question"`
}

Subscript represents a subscript expression, e.g.

a[0] b["k"] c?[1] d[1:2:n]

func NewSubscript

func NewSubscript() *Subscript

NewSubscript creates a new Subscript

func (*Subscript) MarshalJSON

func (s *Subscript) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Subscript

func (*Subscript) UnmarshalJSON

func (s *Subscript) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Subscript

type Target

type Target struct {
	Name    *Node[string]    `json:"name"`
	Pkgpath string           `json:"pkgpath"`
	Paths   []*MemberOrIndex `json:"paths"`
}

Target represents a target in an assignment, e.g.

a b _c a["b"][0].c

func (*Target) MarshalJSON

func (t *Target) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Target

func (*Target) UnmarshalJSON

func (t *Target) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Target

type TargetExpr

type TargetExpr struct {
	BaseExpr
	Name    *Node[string]   `json:"name"`
	Pkgpath string          `json:"pkgpath,omitempty"`
	Paths   []MemberOrIndex `json:"paths,omitempty"`
}

TargetExpr represents a target expression, e.g.

a b _c a["b"][0].c

func NewTargetExpr

func NewTargetExpr() *TargetExpr

NewTargetExpr creates a new TargetExpr

func (*TargetExpr) MarshalJSON

func (t *TargetExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for TargetExpr

func (*TargetExpr) UnmarshalJSON

func (t *TargetExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for TargetExpr

type Type

type Type interface {
	TypeName() string
}

Type is the base interface for all AST types

func UnmarshalType

func UnmarshalType(data []byte) (Type, error)

UnmarshalType is a helper function to unmarshal JSON into Type

type TypeAliasStmt

type TypeAliasStmt struct {
	BaseStmt
	TypeName  *Node[Identifier] `json:"type_name"`
	TypeValue *Node[string]     `json:"type_value"`
	Ty        *Node[Type]       `json:"ty"`
}

TypeAliasStmt represents a type alias statement, e.g.

type StrOrInt = str | int

func NewTypeAliasStmt

func NewTypeAliasStmt() *TypeAliasStmt

NewTypeAliasStmt creates a new TypeAliasStmt

func (*TypeAliasStmt) MarshalJSON

func (t *TypeAliasStmt) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for TypeAliasStmt

func (*TypeAliasStmt) UnmarshalJSON

func (t *TypeAliasStmt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for TypeAliasStmt

type UnaryExpr

type UnaryExpr struct {
	BaseExpr
	Op      UnaryOp     `json:"op"`
	Operand *Node[Expr] `json:"operand"`
}

UnaryExpr represents a unary expression, e.g.

+1 -2 ~3 not True

func NewUnaryExpr

func NewUnaryExpr() *UnaryExpr

NewUnaryExpr creates a new UnaryExpr

func (*UnaryExpr) MarshalJSON

func (u *UnaryExpr) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for UnaryExpr

func (*UnaryExpr) UnmarshalJSON

func (u *UnaryExpr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for UnaryExpr

type UnaryOp

type UnaryOp string

UnaryOp represents a unary operator

const (
	UnaryOpUAdd   UnaryOp = "+"
	UnaryOpUSub   UnaryOp = "-"
	UnaryOpInvert UnaryOp = "~"
	UnaryOpNot    UnaryOp = "not"
)

func AllUnaryOps

func AllUnaryOps() []UnaryOp

AllUnaryOps returns all possible UnaryOp values

func UnaryOpFromSymbol

func UnaryOpFromSymbol(symbol string) (UnaryOp, bool)

UnaryOpFromSymbol returns the UnaryOp corresponding to the given symbol

func (UnaryOp) Symbol

func (op UnaryOp) Symbol() string

Symbol returns the string representation of the unary operator

type UnificationStmt

type UnificationStmt struct {
	BaseStmt
	Target *Node[Identifier]   `json:"target"`
	Value  *Node[SchemaConfig] `json:"value"`
}

UnificationStmt represents a declare statement with the union operator, e.g.

data: ASchema {}

func NewUnificationStmt

func NewUnificationStmt() *UnificationStmt

NewUnificationStmt creates a new UnificationStmt

type UnionType

type UnionType struct {
	Value struct {
		TypeElements []*Node[Type] `json:"type_elements"`
	} `json:"value"`
}

UnionType represents a union type

func (*UnionType) TypeName

func (u *UnionType) TypeName() string

Jump to

Keyboard shortcuts

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