Documentation
¶
Index ¶
- func AllNumberBinarySuffixNames() []string
- func MarshalNumberLitValue(v NumberLitValue) ([]byte, error)
- type AnyType
- type Arguments
- type AssertStmt
- type AssignStmt
- type AstIndex
- type AugAssignStmt
- type AugOp
- type BaseExpr
- type BaseStmt
- type BasicType
- type BasicTypeEnum
- type BinOp
- type BinaryExpr
- type BoolLiteralType
- type CallExpr
- type CheckExpr
- type CmpOp
- type Comment
- type CompClause
- type Compare
- type ConfigEntry
- type ConfigEntryOperation
- type ConfigExpr
- type ConfigIfEntryExpr
- type Decorator
- type DictComp
- type DictType
- type Expr
- type ExprContext
- type ExprStmt
- type FloatLiteralType
- type FloatNumberLitValue
- type FormattedValue
- type FunctionType
- type Identifier
- type IdentifierExpr
- type IfExpr
- type IfStmt
- type ImportStmt
- type Index
- type IntLiteralType
- type IntNumberLitValue
- type JoinedString
- type Keyword
- type LambdaExpr
- type ListComp
- type ListExpr
- type ListIfItemExpr
- type ListType
- type LiteralType
- type LiteralTypeValue
- type Member
- type MemberOrIndex
- type MissingExpr
- type Module
- type NameConstant
- type NameConstantLit
- type NamedType
- type Node
- type NumberBinarySuffix
- type NumberLit
- type NumberLitValue
- type ParenExpr
- type Pos
- type QuantExpr
- type QuantOperation
- type RuleStmt
- type SchemaAttr
- type SchemaConfig
- type SchemaExpr
- type SchemaIndexSignature
- type SchemaStmt
- type SelectorExpr
- type StarredExpr
- type Stmt
- type StrLiteralType
- type StringLit
- type Subscript
- type Target
- type TargetExpr
- type Type
- type TypeAliasStmt
- type UnaryExpr
- type UnaryOp
- type UnificationStmt
- type UnionType
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 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 (*Arguments) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for Arguments
func (*Arguments) UnmarshalJSON ¶
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 (*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 (*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 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 = "|=" )
type BaseExpr ¶
type BaseExpr struct {
ExprType string `json:"type"`
}
BaseExpr is a struct that all expression types can embed to implement the Expr interface
type BaseStmt ¶
type BaseStmt struct {
StmtType string `json:"type"`
}
BaseStmt is a struct that all statement types can embed to implement the Stmt interface
type BasicType ¶
type BasicType struct {
Value BasicTypeEnum `json:"value"`
}
BasicType represents a basic type
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 BinOpFromSymbol ¶
BinOpFromSymbol returns the BinOp corresponding to the given symbol
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
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 (*CallExpr) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for CallExpr
func (*CallExpr) UnmarshalJSON ¶
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 (*CheckExpr) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for CheckExpr
func (*CheckExpr) UnmarshalJSON ¶
UnmarshalJSON implements custom JSON unmarshaling for CheckExpr
type CmpOp ¶
type CmpOp string
CmpOp represents a comparison operator
func CmpOpFromString ¶
CmpOpFromString returns the CmpOp corresponding to the given string
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 (*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 (*Compare) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for Compare
func (*Compare) UnmarshalJSON ¶
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 (*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 (*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 (*Decorator) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for Decorator
func (*Decorator) UnmarshalJSON ¶
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 (*DictComp) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for DictComp
func (*DictComp) UnmarshalJSON ¶
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
type Expr ¶
type Expr interface {
Type() string
}
Expr is an interface for all expression types
func UnmarshalExpr ¶
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 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 (*IfExpr) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for IfExpr
func (*IfExpr) UnmarshalJSON ¶
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 (*IfStmt) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for IfStmt
func (*IfStmt) UnmarshalJSON ¶
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 (*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 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 ¶
MarshalJSON implements custom JSON marshaling for Keyword
func (*Keyword) UnmarshalJSON ¶
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 (*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 (*ListComp) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for ListComp
func (*ListComp) UnmarshalJSON ¶
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 (*ListExpr) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for ListExpr
func (*ListExpr) UnmarshalJSON ¶
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
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 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 (*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.
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
type Node ¶
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 ¶
MarshalJSON implements the json.Marshaler interface
func (*Node[T]) UnmarshalJSON ¶
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 (*NumberLit) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for NumberLit
func (*NumberLit) UnmarshalJSON ¶
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 ¶
ParenExpr represents a parenthesized expression, e.g.
1 + (2 - 3)
func (*ParenExpr) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for ParenExpr
func (*ParenExpr) UnmarshalJSON ¶
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 (*QuantExpr) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for QuantExpr
func (*QuantExpr) UnmarshalJSON ¶
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 (*RuleStmt) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for RuleStmt
func (*RuleStmt) UnmarshalJSON ¶
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 (*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 (*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 (*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 (*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 ¶
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 ¶
MarshalJSON implements custom JSON marshaling for StringLit
func (*StringLit) UnmarshalJSON ¶
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 (*Subscript) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for Subscript
func (*Subscript) UnmarshalJSON ¶
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 ¶
MarshalJSON implements custom JSON marshaling for Target
func (*Target) UnmarshalJSON ¶
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 (*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 ¶
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 ¶
UnaryExpr represents a unary expression, e.g.
+1 -2 ~3 not True
func (*UnaryExpr) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling for UnaryExpr
func (*UnaryExpr) UnmarshalJSON ¶
UnmarshalJSON implements custom JSON unmarshaling for UnaryExpr
type UnaryOp ¶
type UnaryOp string
UnaryOp represents a unary operator
func UnaryOpFromSymbol ¶
UnaryOpFromSymbol returns the UnaryOp corresponding to the given symbol
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