cssx

package
v1.0.0-rc.13 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cssx compiles and validates CSSX expressions for HTML drivers.

CSSX pseudo-functions operate on normalized selections. Maps preserve one slot per input, traversals flat-map nodes without implicit deduplication, filters retain matching nodes, and selection operators keep selection shape. Only reducers and cardinality operations collapse a selection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectCallArgs

func CollectCallArgs(step cssx.Op) ([]any, error)

func Compile

func Compile(input string) (cssx.Pipeline, error)

func ValidateCallArgs

func ValidateCallArgs(exp Expression, step cssx.Op) error

Types

type CompiledOp

type CompiledOp struct {
	Kind     OpKind          `json:"kind"`
	Family   OperationFamily `json:"family,omitempty"`
	Selector string          `json:"selector,omitempty"`
	Name     string          `json:"name,omitempty"`
	Args     []any           `json:"args,omitempty"`
	Arity    int             `json:"arity,omitempty"`
	Index    int             `json:"index"`
}

func CompileOps

func CompileOps(input string) ([]CompiledOp, error)

func CompilePipeline

func CompilePipeline(pipeline cssxpipeline.Pipeline) ([]CompiledOp, error)

type Expression

type Expression string

Expression is a CSSX pseudo-function.

const (
	ExpressionFirst Expression = ":first"
	ExpressionLast  Expression = ":last"
	ExpressionNth   Expression = ":nth"

	ExpressionTake         Expression = ":take"
	ExpressionSkip         Expression = ":skip"
	ExpressionSlice        Expression = ":slice"
	ExpressionCompact      Expression = ":compact"
	ExpressionDistinct     Expression = ":distinct"
	ExpressionDedupeByAttr Expression = ":dedupeByAttr"
	ExpressionDedupeByText Expression = ":dedupeByText"

	ExpressionWithin   Expression = ":within"
	ExpressionHas      Expression = ":has"
	ExpressionMatches  Expression = ":matches"
	ExpressionNot      Expression = ":not"
	ExpressionWithAttr Expression = ":withAttr"
	ExpressionWithText Expression = ":withText"

	ExpressionParent   Expression = ":parent"
	ExpressionClosest  Expression = ":closest"
	ExpressionChildren Expression = ":children"
	ExpressionNext     Expression = ":next"
	ExpressionPrev     Expression = ":prev"
	ExpressionSiblings Expression = ":siblings"

	ExpressionText      Expression = ":text"
	ExpressionOwnText   Expression = ":ownText"
	ExpressionNormalize Expression = ":normalize"
	ExpressionTrim      Expression = ":trim"
	ExpressionAttr      Expression = ":attr"
	ExpressionProp      Expression = ":prop"
	ExpressionHTML      Expression = ":html"
	ExpressionOuterHTML Expression = ":outerHtml"
	ExpressionValue     Expression = ":value"
	ExpressionAbsURL    Expression = ":absUrl"
	ExpressionURL       Expression = ":url"
	ExpressionParseURL  Expression = ":parseUrl"
	ExpressionReplace   Expression = ":replace"
	ExpressionRegex     Expression = ":regex"
	ExpressionToNumber  Expression = ":toNumber"
	ExpressionToDate    Expression = ":toDate"

	ExpressionExists  Expression = ":exists"
	ExpressionEmpty   Expression = ":empty"
	ExpressionCount   Expression = ":count"
	ExpressionOne     Expression = ":one"
	ExpressionIndexOf Expression = ":indexOf"
	ExpressionLen     Expression = ":len"
	ExpressionJoin    Expression = ":join"
)

func ResolveSelector

func ResolveSelector(selector string) (Expression, error)

type OpKind

type OpKind string
const (
	OpSelect OpKind = "select"
	OpCall   OpKind = "call"
)

type Operation

type Operation struct {
	Expression Expression
	Family     OperationFamily
}

Operation describes the selection behavior of a CSSX pseudo-function.

func ResolveOperation

func ResolveOperation(selector string) (Operation, error)

type OperationFamily

type OperationFamily string

OperationFamily defines how a CSSX pseudo-function treats its input selection.

const (
	FamilyMap         OperationFamily = "map"
	FamilyTraversal   OperationFamily = "traversal"
	FamilyFilter      OperationFamily = "filter"
	FamilySelection   OperationFamily = "selection"
	FamilyReducer     OperationFamily = "reducer"
	FamilyCardinality OperationFamily = "cardinality"
)

Jump to

Keyboard shortcuts

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