ast

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllNumberBinarySuffixNames added in v0.11.0

func AllNumberBinarySuffixNames() []string

AllNumberBinarySuffixNames returns all names of NumberBinarySuffix

func MarshalNumberLitValue added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for NumberLitValue

Types

type AnyType added in v0.11.0

type AnyType struct{}

AnyType represents a the any type

func (*AnyType) TypeName added in v0.11.0

func (n *AnyType) TypeName() string

type Arguments added in v0.11.0

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 added in v0.11.0

func NewArguments() *Arguments

NewArguments creates a new Arguments

func (*Arguments) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for Arguments

func (*Arguments) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for Arguments

type AssertStmt added in v0.11.0

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 added in v0.11.0

func NewAssertStmt() *AssertStmt

NewAssertStmt creates a new AssertStmt

func (*AssertStmt) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for AssertStmt

func (*AssertStmt) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for AssertStmt

type AssignStmt added in v0.11.0

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 added in v0.11.0

func NewAssignStmt() *AssignStmt

NewAssignStmt creates a new AssignStmt

func (*AssignStmt) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for AssignStmt

func (*AssignStmt) UnmarshalJSON added in v0.11.0

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 added in v0.11.0

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 added in v0.11.0

func NewAugAssignStmt() *AugAssignStmt

NewAugAssignStmt creates a new AugAssignStmt

func (*AugAssignStmt) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for AugAssignStmt

func (*AugAssignStmt) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for AugAssignStmt

type AugOp added in v0.11.0

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 added in v0.11.0

func (a AugOp) Symbol() string

Symbol returns the string representation of the AugOp

func (AugOp) ToBinOp added in v0.11.0

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

ToBinOp converts AugOp to BinOp, if possible

type BaseExpr added in v0.11.0

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 added in v0.11.0

func (b BaseExpr) Type() string

type BaseStmt added in v0.11.0

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 added in v0.11.0

func (b BaseStmt) Type() string

type BasicType added in v0.11.0

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

BasicType represents a basic type

func (*BasicType) TypeName added in v0.11.0

func (b *BasicType) TypeName() string

type BasicTypeEnum added in v0.11.0

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

type BinOp added in v0.11.0

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 added in v0.11.0

func AllBinOps() []BinOp

AllBinOps returns all possible BinOp values

func BinOpFromSymbol added in v0.11.0

func BinOpFromSymbol(symbol string) (BinOp, bool)

BinOpFromSymbol returns the BinOp corresponding to the given symbol

func (BinOp) Symbol added in v0.11.0

func (op BinOp) Symbol() string

Symbol returns the string representation of the binary operator

type BinaryExpr added in v0.11.0

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 added in v0.11.0

func NewBinaryExpr() *BinaryExpr

NewBinaryExpr creates a new BinaryExpr

type BoolLiteralType added in v0.11.0

type BoolLiteralType bool

BoolLiteralType represents a boolean literal type

func (*BoolLiteralType) LiteralTypeName added in v0.11.0

func (b *BoolLiteralType) LiteralTypeName() string

type CallExpr added in v0.11.0

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 added in v0.11.0

func NewCallExpr() *CallExpr

NewCallExpr creates a new CallExpr

func (*CallExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for CallExpr

func (*CallExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for CallExpr

type CheckExpr added in v0.11.0

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 added in v0.11.0

func NewCheckExpr() *CheckExpr

NewCheckExpr creates a new CheckExpr

func (*CheckExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for CheckExpr

func (*CheckExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for CheckExpr

type CmpOp added in v0.11.0

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 added in v0.11.0

func AllCmpOps() []CmpOp

AllCmpOps returns all possible CmpOp values

func CmpOpFromString added in v0.11.0

func CmpOpFromString(s string) (CmpOp, bool)

CmpOpFromString returns the CmpOp corresponding to the given string

func (CmpOp) Symbol added in v0.11.0

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 added in v0.11.0

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 added in v0.11.0

func NewCompClause() *CompClause

NewCompClause creates a new CompClause

func (*CompClause) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for CompClause

func (*CompClause) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for CompClause

type Compare added in v0.11.0

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 added in v0.11.0

func NewCompare() *Compare

NewCompare creates a new Compare

func (*Compare) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for Compare

func (*Compare) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for Compare

type ConfigEntry added in v0.11.0

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 added in v0.11.0

func NewConfigEntry() *ConfigEntry

NewConfigEntry creates a new ConfigEntry

func (*ConfigEntry) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for ConfigEntry

func (*ConfigEntry) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for ConfigEntry

type ConfigEntryOperation added in v0.11.0

type ConfigEntryOperation string

ConfigEntryOperation represents the operation of a configuration entry

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

func AllConfigEntryOperations added in v0.11.0

func AllConfigEntryOperations() []ConfigEntryOperation

AllConfigEntryOperations returns all possible ConfigEntryOperation values

func ConfigEntryOperationFromString added in v0.11.0

func ConfigEntryOperationFromString(s string) (ConfigEntryOperation, error)

ConfigEntryOperationFromString returns the ConfigEntryOperation corresponding to the given string

func (ConfigEntryOperation) String added in v0.11.0

func (c ConfigEntryOperation) String() string

String returns the string representation of the ConfigEntryOperation

func (ConfigEntryOperation) Symbol added in v0.11.0

func (c ConfigEntryOperation) Symbol() string

Symbol returns the symbol representation of the ConfigEntryOperation

func (ConfigEntryOperation) Value added in v0.11.0

func (c ConfigEntryOperation) Value() int

Value returns the integer value of the ConfigEntryOperation

type ConfigExpr added in v0.11.0

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 added in v0.11.0

func NewConfigExpr() *ConfigExpr

NewConfigExpr creates a new ConfigExpr

func (*ConfigExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for ConfigExpr

func (*ConfigExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for ConfigExpr

type ConfigIfEntryExpr added in v0.11.0

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 added in v0.11.0

func NewConfigIfEntryExpr() *ConfigIfEntryExpr

NewConfigIfEntryExpr creates a new ConfigIfEntryExpr

func (*ConfigIfEntryExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for ConfigIfEntryExpr

func (*ConfigIfEntryExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for ConfigIfEntryExpr

type Decorator added in v0.11.0

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 added in v0.11.0

func NewDecorator() *Decorator

NewDecorator creates a new Decorator

func (*Decorator) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for Decorator

func (*Decorator) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for Decorator

type DictComp added in v0.11.0

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 added in v0.11.0

func NewDictComp() *DictComp

NewDictComp creates a new DictComp

func (*DictComp) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for DictComp

func (*DictComp) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for DictComp

type DictType added in v0.11.0

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 added in v0.11.0

func (d *DictType) TypeName() string

type Expr added in v0.11.0

type Expr interface {
	Type() string
}

Expr is an interface for all expression types

func UnmarshalExpr added in v0.11.0

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

UnmarshalExprJSON implements custom JSON unmarshaling for Expr

type ExprContext added in v0.11.0

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 added in v0.11.0

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

MarshalJSON implements the json.Marshaler interface for ExprContext

func (ExprContext) String added in v0.11.0

func (e ExprContext) String() string

String returns the string representation of ExprContext

func (*ExprContext) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements the json.Unmarshaler interface for ExprContext

type ExprStmt added in v0.11.0

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

ExprStmt represents a expression statement, e.g.

1

"""A long string"""

'A string'

func NewExprStmt added in v0.11.0

func NewExprStmt() *ExprStmt

NewExprStmt creates a new ExprStmt

type FloatLiteralType added in v0.11.0

type FloatLiteralType float64

FloatLiteralType represents a float literal type

func (*FloatLiteralType) LiteralTypeName added in v0.11.0

func (f *FloatLiteralType) LiteralTypeName() string

type FloatNumberLitValue added in v0.11.0

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

FloatNumberLitValue represents a float number literal value

func (*FloatNumberLitValue) Type added in v0.11.0

func (f *FloatNumberLitValue) Type() string

Type returns the type of the number literal value

type FormattedValue added in v0.11.0

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 added in v0.11.0

func NewFormattedValue() *FormattedValue

NewFormattedValue creates a new FormattedValue

func (*FormattedValue) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for FormattedValue

func (*FormattedValue) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for FormattedValue

type FunctionType added in v0.11.0

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 added in v0.11.0

func (f *FunctionType) TypeName() string

type Identifier added in v0.11.0

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 added in v0.11.0

type IdentifierExpr struct {
	BaseExpr
	Identifier
}

IdentifierExpr represents an identifier expression, e.g.

a b _c pkg.a

func NewIdentifierExpr added in v0.11.0

func NewIdentifierExpr() *IdentifierExpr

NewIdentifierExpr creates a new IdentifierExpr

func (*IdentifierExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for IdentifierExpr

func (*IdentifierExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for IdentifierExpr

type IfExpr added in v0.11.0

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 added in v0.11.0

func NewIfExpr() *IfExpr

NewIfExpr creates a new IfExpr

func (*IfExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for IfExpr

func (*IfExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for IfExpr

type IfStmt added in v0.11.0

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 added in v0.11.0

func NewIfStmt() *IfStmt

NewIfStmt creates a new IfStmt

func (*IfStmt) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for IfStmt

func (*IfStmt) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for IfStmt

type ImportStmt added in v0.11.0

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 added in v0.11.0

func NewImportStmt() *ImportStmt

NewImportStmt creates a new ImportStmt

func (*ImportStmt) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for ImportStmt

func (*ImportStmt) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for ImportStmt

type Index added in v0.11.0

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

Index represents an index access

func (*Index) Type added in v0.11.0

func (i *Index) Type() string

Type returns the type of Index

type IntLiteralType added in v0.11.0

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

IntLiteralType represents an integer literal type

func (*IntLiteralType) LiteralTypeName added in v0.11.0

func (i *IntLiteralType) LiteralTypeName() string

type IntNumberLitValue added in v0.11.0

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

IntNumberLitValue represents an integer number literal value

func (*IntNumberLitValue) Type added in v0.11.0

func (i *IntNumberLitValue) Type() string

Type returns the type of the number literal value

type JoinedString added in v0.11.0

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 added in v0.11.0

func NewJoinedString() *JoinedString

NewJoinedString creates a new JoinedString

func (*JoinedString) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for JoinedString

func (*JoinedString) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for JoinedString

type Keyword added in v0.11.0

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 added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for Keyword

func (*Keyword) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for Keyword

type LambdaExpr added in v0.11.0

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 added in v0.11.0

func NewLambdaExpr() *LambdaExpr

NewLambdaExpr creates a new LambdaExpr

func (*LambdaExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for LambdaExpr

func (*LambdaExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for LambdaExpr

type ListComp added in v0.11.0

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 added in v0.11.0

func NewListComp() *ListComp

NewListComp creates a new ListComp

func (*ListComp) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for ListComp

func (*ListComp) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for ListComp

type ListExpr added in v0.11.0

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 added in v0.11.0

func NewListExpr() *ListExpr

NewListExpr creates a new ListExpr

func (*ListExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for ListExpr

func (*ListExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for ListExpr

type ListIfItemExpr added in v0.11.0

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 added in v0.11.0

func NewListIfItemExpr() *ListIfItemExpr

NewListIfItemExpr creates a new ListIfItemExpr

func (*ListIfItemExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for ListIfItemExpr

func (*ListIfItemExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for ListIfItemExpr

type ListType added in v0.11.0

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

ListType represents a list type

func (*ListType) TypeName added in v0.11.0

func (l *ListType) TypeName() string

type LiteralType added in v0.11.0

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

LiteralType represents a literal type

func (*LiteralType) TypeName added in v0.11.0

func (l *LiteralType) TypeName() string

type LiteralTypeValue added in v0.11.0

type LiteralTypeValue interface {
	LiteralTypeName() string
}

LiteralTypeValue is an interface for different literal types

type Member added in v0.11.0

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

Member represents a member access

func (*Member) Type added in v0.11.0

func (m *Member) Type() string

Type returns the type of Member

type MemberOrIndex added in v0.11.0

type MemberOrIndex interface {
	Type() string
}

MemberOrIndex is the base interface for member or index expression

a.<member> b[<index>]

func UnmarshalMemberOrIndex added in v0.11.0

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

UnmarshalMemberOrIndex is a helper function to unmarshal JSON into MemberOrIndex

type MissingExpr added in v0.11.0

type MissingExpr struct {
	BaseExpr
}

MissingExpr is a placeholder for error recovery

func NewMissingExpr added in v0.11.0

func NewMissingExpr() *MissingExpr

NewMissingExpr creates a new MissingExpr

func (*MissingExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for MissingExpr

func (*MissingExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for MissingExpr

type Module added in v0.11.0

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 added in v0.11.0

func NewModule() *Module

NewModule creates a new Module instance

type NameConstant added in v0.11.0

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 added in v0.11.0

func AllNameConstants() []NameConstant

AllNameConstants returns all possible NameConstant values

func (NameConstant) JSONValue added in v0.11.0

func (n NameConstant) JSONValue() string

JSONValue returns the JSON value for each constant

func (NameConstant) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for NameConstant

func (NameConstant) Symbol added in v0.11.0

func (n NameConstant) Symbol() string

Symbol returns the symbol for each constant

func (*NameConstant) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for NameConstant

type NameConstantLit added in v0.11.0

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

NameConstantLit represents a name constant literal, e.g.

True False None Undefined

func NewNameConstantLit added in v0.11.0

func NewNameConstantLit() *NameConstantLit

NewNameConstantLit creates a new NameConstantLit

func (*NameConstantLit) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for NameConstantLit

func (*NameConstantLit) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for NameConstantLit

type NamedType added in v0.11.0

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

NamedType represents a named type

func (*NamedType) TypeName added in v0.11.0

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 added in v0.11.0

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

MarshalJSON implements the json.Marshaler interface

func (*Node[T]) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements the json.Unmarshaler interface

type NumberBinarySuffix added in v0.11.0

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 added in v0.11.0

func AllNumberBinarySuffixes() []NumberBinarySuffix

AllNumberBinarySuffixes returns all possible NumberBinarySuffix values

func NumberBinarySuffixFromString added in v0.11.0

func NumberBinarySuffixFromString(s string) (NumberBinarySuffix, bool)

NumberBinarySuffixFromString returns the NumberBinarySuffix corresponding to the given string

func (NumberBinarySuffix) Value added in v0.11.0

func (n NumberBinarySuffix) Value() string

Value returns the string representation of the NumberBinarySuffix

type NumberLit added in v0.11.0

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 added in v0.11.0

func NewNumberLit() *NumberLit

NewNumberLit creates a new NumberLit

func (*NumberLit) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for NumberLit

func (*NumberLit) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for NumberLit

type NumberLitValue added in v0.11.0

type NumberLitValue interface {
	Type() string
}

NumberLitValue represents the value of a number literal

func UnmarshalNumberLitValue added in v0.11.0

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

UnmarshalNumberLitValue unmarshals JSON data into a NumberLitValue

type ParenExpr added in v0.11.0

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

ParenExpr represents a parenthesized expression, e.g.

1 + (2 - 3)

func NewParenExpr added in v0.11.0

func NewParenExpr() *ParenExpr

NewParenExpr creates a new ParenExpr

func (*ParenExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for ParenExpr

func (*ParenExpr) UnmarshalJSON added in v0.11.0

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 added in v0.11.0

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 added in v0.11.0

func NewQuantExpr() *QuantExpr

NewQuantExpr creates a new QuantExpr

func (*QuantExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for QuantExpr

func (*QuantExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for QuantExpr

type QuantOperation added in v0.11.0

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 added in v0.11.0

func AllQuantOperations() []QuantOperation

AllQuantOperations returns all possible QuantOperation values

func QuantOperationFromString added in v0.11.0

func QuantOperationFromString(s string) (QuantOperation, bool)

QuantOperationFromString returns the QuantOperation corresponding to the given string

func (QuantOperation) String added in v0.11.0

func (qo QuantOperation) String() string

String returns the string representation of the QuantOperation

type RuleStmt added in v0.11.0

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 added in v0.11.0

func NewRuleStmt() *RuleStmt

NewRuleStmt creates a new RuleStmt

func (*RuleStmt) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for RuleStmt

func (*RuleStmt) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for RuleStmt

type SchemaAttr added in v0.11.0

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 added in v0.11.0

func NewSchemaAttr() *SchemaAttr

NewSchemaAttr creates a new SchemaAttr

func (*SchemaAttr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for SchemaAttr

func (*SchemaAttr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for SchemaAttr

type SchemaConfig added in v0.11.0

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 added in v0.11.0

func NewSchemaConfig() *SchemaConfig

NewSchemaConfig creates a new SchemaConfig

func (*SchemaConfig) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for SchemaConfig

func (*SchemaConfig) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for SchemaConfig

type SchemaExpr added in v0.11.0

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 added in v0.11.0

func NewSchemaExpr() *SchemaExpr

NewSchemaExpr creates a new SchemaExpr

func (*SchemaExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for SchemaExpr

func (*SchemaExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for SchemaExpr

type SchemaIndexSignature added in v0.11.0

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 added in v0.11.0

func NewSchemaIndexSignature() *SchemaIndexSignature

NewSchemaIndexSignature creates a new SchemaIndexSignature

func (*SchemaIndexSignature) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for SchemaIndexSignature

func (*SchemaIndexSignature) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for SchemaIndexSignature

type SchemaStmt added in v0.11.0

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 added in v0.11.0

func NewSchemaStmt() *SchemaStmt

NewSchemaStmt creates a new SchemaStmt

func (*SchemaStmt) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for SchemaStmt

func (*SchemaStmt) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for SchemaStmt

type SelectorExpr added in v0.11.0

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 added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for SelectorExpr

func (*SelectorExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for SelectorExpr

type StarredExpr added in v0.11.0

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 added in v0.11.0

func NewStarredExpr() *StarredExpr

NewStarredExpr creates a new StarredExpr

func (*StarredExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for StarredExpr

func (*StarredExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for StarredExpr

type Stmt added in v0.11.0

type Stmt interface {
	Type() string
}

Stmt is an interface for all statement types

func UnmarshalStmt added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for Stmt

type StrLiteralType added in v0.11.0

type StrLiteralType string

StrLiteralType represents a string literal type

func (*StrLiteralType) LiteralTypeName added in v0.11.0

func (s *StrLiteralType) LiteralTypeName() string

type StringLit added in v0.11.0

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 added in v0.11.0

func NewStringLit() *StringLit

NewStringLit creates a new StringLit with default values

func (*StringLit) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for StringLit

func (*StringLit) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for StringLit

type Subscript added in v0.11.0

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 added in v0.11.0

func NewSubscript() *Subscript

NewSubscript creates a new Subscript

func (*Subscript) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for Subscript

func (*Subscript) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for Subscript

type Target added in v0.11.0

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 added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for Target

func (*Target) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for Target

type TargetExpr added in v0.11.0

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 added in v0.11.0

func NewTargetExpr() *TargetExpr

NewTargetExpr creates a new TargetExpr

func (*TargetExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for TargetExpr

func (*TargetExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for TargetExpr

type Type added in v0.11.0

type Type interface {
	TypeName() string
}

Type is the base interface for all AST types

func UnmarshalType added in v0.11.0

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

UnmarshalType is a helper function to unmarshal JSON into Type

type TypeAliasStmt added in v0.11.0

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 added in v0.11.0

func NewTypeAliasStmt() *TypeAliasStmt

NewTypeAliasStmt creates a new TypeAliasStmt

func (*TypeAliasStmt) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for TypeAliasStmt

func (*TypeAliasStmt) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for TypeAliasStmt

type UnaryExpr added in v0.11.0

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 added in v0.11.0

func NewUnaryExpr() *UnaryExpr

NewUnaryExpr creates a new UnaryExpr

func (*UnaryExpr) MarshalJSON added in v0.11.0

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

MarshalJSON implements custom JSON marshaling for UnaryExpr

func (*UnaryExpr) UnmarshalJSON added in v0.11.0

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

UnmarshalJSON implements custom JSON unmarshaling for UnaryExpr

type UnaryOp added in v0.11.0

type UnaryOp string

UnaryOp represents a unary operator

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

func AllUnaryOps added in v0.11.0

func AllUnaryOps() []UnaryOp

AllUnaryOps returns all possible UnaryOp values

func UnaryOpFromSymbol added in v0.11.0

func UnaryOpFromSymbol(symbol string) (UnaryOp, bool)

UnaryOpFromSymbol returns the UnaryOp corresponding to the given symbol

func (UnaryOp) Symbol added in v0.11.0

func (op UnaryOp) Symbol() string

Symbol returns the string representation of the unary operator

type UnificationStmt added in v0.11.0

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 added in v0.11.0

func NewUnificationStmt() *UnificationStmt

NewUnificationStmt creates a new UnificationStmt

type UnionType added in v0.11.0

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

UnionType represents a union type

func (*UnionType) TypeName added in v0.11.0

func (u *UnionType) TypeName() string

Jump to

Keyboard shortcuts

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