ast

package
v0.0.0-...-69549a0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StringType     = types.StringType
	NumberType     = types.NumberType
	DurationType   = types.DurationType
	IdentifierType = types.IdentifierType
	BooleanType    = types.BooleanType
)

Variables

This section is empty.

Functions

func GetBoolParam

func GetBoolParam(params []NamedParameter, name string, defaultValue bool) bool

GetBoolParam retrieves a boolean parameter value with default fallback

func GetDurationParam

func GetDurationParam(params []NamedParameter, name string, defaultValue time.Duration) time.Duration

GetDurationParam retrieves a duration parameter value with default fallback

func GetIntParam

func GetIntParam(params []NamedParameter, name string, defaultValue int) int

GetIntParam retrieves an integer parameter value with default fallback

func GetStringParam

func GetStringParam(params []NamedParameter, name string, defaultValue string) string

GetStringParam retrieves a string parameter value with default fallback

func IsPatternDecorator

func IsPatternDecorator(decoratorName string) bool

IsPatternDecorator checks if a decorator is a pattern-matching decorator

func ValidatePatternDecorator

func ValidatePatternDecorator(pattern *PatternDecorator) []error

ValidatePatternDecorator validates pattern-matching decorator content

func ValidatePatternDecorators

func ValidatePatternDecorators(program *Program) []error

ValidatePatternDecorators validates all pattern decorators in the program

func ValidateVariableReferences

func ValidateVariableReferences(program *Program) []error

ValidateVariableReferences checks that all @var() decorator references are defined

func Walk

func Walk(node Node, fn func(Node) bool)

Walk traverses the CST and calls fn for each node

Types

type ActionDecorator

type ActionDecorator struct {
	Name   string
	Args   []NamedParameter
	Pos    Position
	Tokens TokenRange

	// Concrete syntax tokens for precise formatting and LSP
	AtToken    types.Token  // The "@" symbol
	NameToken  types.Token  // The decorator name token
	OpenParen  *types.Token // The "(" token (nil if no args)
	CloseParen *types.Token // The ")" token (nil if no args)
}

ActionDecorator represents standalone decorators that execute commands Examples: @cmd(helper) - these appear as standalone CommandContent

func (*ActionDecorator) IsCommandContent

func (a *ActionDecorator) IsCommandContent() bool

func (*ActionDecorator) IsShellPart

func (a *ActionDecorator) IsShellPart() bool

func (*ActionDecorator) Position

func (a *ActionDecorator) Position() Position

func (*ActionDecorator) SemanticTokens

func (a *ActionDecorator) SemanticTokens() []types.Token

func (*ActionDecorator) String

func (a *ActionDecorator) String() string

func (*ActionDecorator) TokenRange

func (a *ActionDecorator) TokenRange() TokenRange

type BlockDecorator

type BlockDecorator struct {
	Name    string           // Decorator name: "parallel", "timeout", "retry"
	Args    []NamedParameter // Arguments within parentheses
	Content []CommandContent // The commands inside the decorator block
	Pos     Position
	Tokens  TokenRange

	// LSP support
	AtToken   types.Token
	NameToken types.Token
}

BlockDecorator represents block decorators like @parallel, @timeout, @retry This handles cases like: @parallel { cmd1; cmd2 } or @timeout(30s) { npm start }

func NewBlockDecorator

func NewBlockDecorator(name string, args []NamedParameter, content []CommandContent) *BlockDecorator

NewBlockDecorator creates a block decorator node

func (*BlockDecorator) IsCommandContent

func (d *BlockDecorator) IsCommandContent() bool

func (*BlockDecorator) Position

func (d *BlockDecorator) Position() Position

func (*BlockDecorator) SemanticTokens

func (d *BlockDecorator) SemanticTokens() []types.Token

func (*BlockDecorator) String

func (d *BlockDecorator) String() string

func (*BlockDecorator) TokenRange

func (d *BlockDecorator) TokenRange() TokenRange

type BooleanLiteral

type BooleanLiteral struct {
	Value  bool   // The boolean value
	Raw    string // The raw string ("true" or "false")
	Pos    Position
	Tokens TokenRange
	Token  types.Token
}

BooleanLiteral represents boolean values (true/false)

func Bool

func Bool(value bool) *BooleanLiteral

Bool creates a boolean literal expression

func (*BooleanLiteral) GetType

func (b *BooleanLiteral) GetType() ExpressionType

func (*BooleanLiteral) IsExpression

func (b *BooleanLiteral) IsExpression() bool

func (*BooleanLiteral) Position

func (b *BooleanLiteral) Position() Position

func (*BooleanLiteral) SemanticTokens

func (b *BooleanLiteral) SemanticTokens() []types.Token

func (*BooleanLiteral) String

func (b *BooleanLiteral) String() string

func (*BooleanLiteral) TokenRange

func (b *BooleanLiteral) TokenRange() TokenRange

type CommandBody

type CommandBody struct {
	Content []CommandContent // Multiple content items within the command body
	Pos     Position
	Tokens  TokenRange

	// Concrete syntax tokens for precise formatting
	OpenBrace  *types.Token // The "{" token (nil for simple commands)
	CloseBrace *types.Token // The "}" token (nil for simple commands)
}

CommandBody represents the unified body of a command with concrete syntax preservation Now supports multiple content items for complex command structures

func (*CommandBody) GetAllPatternContent

func (b *CommandBody) GetAllPatternContent() []*PatternContent

GetAllPatternContent returns all pattern content from the command body

func (*CommandBody) GetAllShellContent

func (b *CommandBody) GetAllShellContent() []*ShellContent

GetAllShellContent returns all shell content from the command body

func (*CommandBody) GetInlineDecorators

func (b *CommandBody) GetInlineDecorators() []*ValueDecorator

GetInlineDecorators returns all inline value decorators within shell content

func (*CommandBody) GetShellText

func (b *CommandBody) GetShellText() string

GetShellText returns the shell text if this is a simple shell command

func (*CommandBody) IsSimpleCommand

func (b *CommandBody) IsSimpleCommand() bool

IsSimpleCommand checks if a command body represents a simple (non-decorated) command

func (*CommandBody) Position

func (b *CommandBody) Position() Position

func (*CommandBody) SemanticTokens

func (b *CommandBody) SemanticTokens() []types.Token

func (*CommandBody) String

func (b *CommandBody) String() string

func (*CommandBody) TokenRange

func (b *CommandBody) TokenRange() TokenRange

type CommandContent

type CommandContent interface {
	Node
	IsCommandContent() bool
}

CommandContent represents the content within a command body

type CommandDecl

type CommandDecl struct {
	Name   string
	Type   CommandType
	Body   CommandBody
	Pos    Position
	Tokens TokenRange

	// Concrete syntax tokens for precise formatting and LSP
	TypeToken  *types.Token // The watch/stop keyword (nil for regular commands)
	NameToken  types.Token  // The command name token
	ColonToken types.Token  // The ":" token
}

CommandDecl represents command definitions with concrete syntax preservation

func Cmd

func Cmd(name string, body CommandContent) CommandDecl

Cmd creates a simple command: NAME: BODY

func (*CommandDecl) Position

func (c *CommandDecl) Position() Position

func (*CommandDecl) SemanticTokens

func (c *CommandDecl) SemanticTokens() []types.Token

func (*CommandDecl) String

func (c *CommandDecl) String() string

func (*CommandDecl) TokenRange

func (c *CommandDecl) TokenRange() TokenRange

type CommandType

type CommandType int

CommandType represents the type of command

const (
	Command CommandType = iota
	WatchCommand
	StopCommand
)

func (CommandType) String

func (ct CommandType) String() string

type DurationLiteral

type DurationLiteral struct {
	Value  string
	Pos    Position
	Tokens TokenRange
	Token  types.Token
}

DurationLiteral represents duration values like 30s, 5m

func Dur

func Dur(value string) *DurationLiteral

Dur creates a duration literal expression

func (*DurationLiteral) GetType

func (d *DurationLiteral) GetType() ExpressionType

func (*DurationLiteral) IsExpression

func (d *DurationLiteral) IsExpression() bool

func (*DurationLiteral) Position

func (d *DurationLiteral) Position() Position

func (*DurationLiteral) SemanticTokens

func (d *DurationLiteral) SemanticTokens() []types.Token

func (*DurationLiteral) String

func (d *DurationLiteral) String() string

func (*DurationLiteral) TokenRange

func (d *DurationLiteral) TokenRange() TokenRange

type Expression

type Expression interface {
	Node
	IsExpression() bool
	GetType() types.ExpressionType
}

Expression represents any expression (literals, identifiers, etc.)

type ExpressionType

type ExpressionType = types.ExpressionType

Use types from the shared types package

type Identifier

type Identifier struct {
	Name   string
	Pos    Position
	Tokens TokenRange
	Token  types.Token
}

Identifier represents identifiers

func Id

func Id(name string) *Identifier

Id creates an identifier expression

func (*Identifier) GetType

func (i *Identifier) GetType() ExpressionType

func (*Identifier) IsExpression

func (i *Identifier) IsExpression() bool

func (*Identifier) Position

func (i *Identifier) Position() Position

func (*Identifier) SemanticTokens

func (i *Identifier) SemanticTokens() []types.Token

func (*Identifier) String

func (i *Identifier) String() string

func (*Identifier) TokenRange

func (i *Identifier) TokenRange() TokenRange

type IdentifierPattern

type IdentifierPattern struct {
	Name   string
	Pos    Position
	Tokens TokenRange
	Token  types.Token
}

IdentifierPattern represents named patterns like "production", "main", "error"

func NewIdentifierPattern

func NewIdentifierPattern(name string) *IdentifierPattern

NewIdentifierPattern creates an identifier pattern

func (*IdentifierPattern) GetPatternType

func (i *IdentifierPattern) GetPatternType() PatternType

func (*IdentifierPattern) IsPattern

func (i *IdentifierPattern) IsPattern() bool

func (*IdentifierPattern) Position

func (i *IdentifierPattern) Position() Position

func (*IdentifierPattern) SemanticTokens

func (i *IdentifierPattern) SemanticTokens() []types.Token

func (*IdentifierPattern) String

func (i *IdentifierPattern) String() string

func (*IdentifierPattern) TokenRange

func (i *IdentifierPattern) TokenRange() TokenRange

type NamedParameter

type NamedParameter struct {
	Name   string     // Parameter name (e.g., "concurrency", "failOnFirstError")
	Value  Expression // Parameter value
	Pos    Position
	Tokens TokenRange

	// Concrete syntax tokens for LSP support
	NameToken   *types.Token // The parameter name token (nil for positional args)
	EqualsToken *types.Token // The "=" token (nil for positional args)
}

NamedParameter represents a named parameter in decorator arguments Supports both named syntax (name = value) and positional (resolved by parser)

func FindParameter

func FindParameter(params []NamedParameter, name string) *NamedParameter

FindParameter searches for a parameter by name in the slice

func Param

func Param(name string, value Expression) NamedParameter

Param creates a named parameter for decorators

func UnnamedParam

func UnnamedParam(value Expression) NamedParameter

UnnamedParam creates an unnamed parameter (positional)

func (NamedParameter) IsNamed

func (n NamedParameter) IsNamed() bool

IsNamed returns true if this parameter was specified with a name

func (NamedParameter) Position

func (n NamedParameter) Position() Position

func (NamedParameter) SemanticTokens

func (n NamedParameter) SemanticTokens() []types.Token

func (NamedParameter) String

func (n NamedParameter) String() string

func (NamedParameter) TokenRange

func (n NamedParameter) TokenRange() TokenRange

type Node

type Node interface {
	String() string
	Position() Position
	TokenRange() TokenRange
	SemanticTokens() []types.Token
}

Node represents any node in the AST

type NumberLiteral

type NumberLiteral struct {
	Value  string
	Pos    Position
	Tokens TokenRange
	Token  types.Token
}

NumberLiteral represents numeric values

func Num

func Num(value interface{}) *NumberLiteral

Num creates a number literal expression

func (*NumberLiteral) GetType

func (n *NumberLiteral) GetType() ExpressionType

func (*NumberLiteral) IsExpression

func (n *NumberLiteral) IsExpression() bool

func (*NumberLiteral) Position

func (n *NumberLiteral) Position() Position

func (*NumberLiteral) SemanticTokens

func (n *NumberLiteral) SemanticTokens() []types.Token

func (*NumberLiteral) String

func (n *NumberLiteral) String() string

func (*NumberLiteral) TokenRange

func (n *NumberLiteral) TokenRange() TokenRange

type Pattern

type Pattern interface {
	Node
	IsPattern() bool
	GetPatternType() PatternType
}

Pattern represents a pattern in pattern-matching decorators

type PatternBranch

type PatternBranch struct {
	Pattern  Pattern          // The pattern identifier or wildcard
	Commands []CommandContent // The commands to execute for this pattern (supports multiple)
	Pos      Position
	Tokens   TokenRange

	// Concrete syntax tokens for precise formatting and LSP
	ColonToken types.Token // The ":" token separating pattern from command
}

PatternBranch represents a single pattern branch in pattern-matching decorators Examples: "production: deploy.sh", "main: npm start", "*: default.sh" Supports multiple commands per pattern when using newlines

func FindPatternBranches

func FindPatternBranches(node Node, decoratorName string) []*PatternBranch

FindPatternBranches finds all pattern branches for a specific decorator

func GetPatternBranchForPattern

func GetPatternBranchForPattern(patternDecorator *PatternDecorator, patternName string) *PatternBranch

GetPatternBranchForPattern finds a specific pattern branch within pattern content GetPatternBranchForPattern finds a pattern branch for a specific pattern name

func NewPatternBranch

func NewPatternBranch(pattern Pattern, commands []CommandContent) PatternBranch

NewPatternBranch creates a pattern branch

func (*PatternBranch) Position

func (b *PatternBranch) Position() Position

func (*PatternBranch) SemanticTokens

func (b *PatternBranch) SemanticTokens() []types.Token

func (*PatternBranch) String

func (b *PatternBranch) String() string

func (*PatternBranch) TokenRange

func (b *PatternBranch) TokenRange() TokenRange

type PatternContent

type PatternContent struct {
	Pattern  string           // The pattern string (e.g., "production", "main", "*")
	Commands []CommandContent // The commands to execute for this pattern
	Pos      Position
	Tokens   TokenRange
}

PatternContent represents a simple pattern with commands Simplified to just Pattern and Commands

func (*PatternContent) IsCommandContent

func (p *PatternContent) IsCommandContent() bool

func (*PatternContent) Position

func (p *PatternContent) Position() Position

func (*PatternContent) SemanticTokens

func (p *PatternContent) SemanticTokens() []types.Token

func (*PatternContent) String

func (p *PatternContent) String() string

func (*PatternContent) TokenRange

func (p *PatternContent) TokenRange() TokenRange

type PatternDecorator

type PatternDecorator struct {
	Name     string           // Decorator name: "when", "try"
	Args     []NamedParameter // Arguments within parentheses (e.g., variable for @when)
	Patterns []PatternBranch  // Pattern branches inside the decorator block
	Pos      Position
	Tokens   TokenRange

	// LSP support
	AtToken   types.Token
	NameToken types.Token
}

PatternDecorator represents pattern decorators like @when, @try This handles cases like: @when(MODE) { production: deploy.sh; staging: deploy-staging.sh }

func GetPatternDecorators

func GetPatternDecorators(node Node) []*PatternDecorator

GetPatternDecorators returns all pattern decorators in the AST

func GetPatternDecoratorsByName

func GetPatternDecoratorsByName(node Node, decoratorName string) []*PatternDecorator

GetPatternDecoratorsByName finds pattern decorators for a specific decorator type

func NewPatternDecorator

func NewPatternDecorator(name string, args []NamedParameter, patterns []PatternBranch) *PatternDecorator

NewPatternDecorator creates a pattern decorator node

func (*PatternDecorator) IsCommandContent

func (d *PatternDecorator) IsCommandContent() bool

func (*PatternDecorator) Position

func (d *PatternDecorator) Position() Position

func (*PatternDecorator) SemanticTokens

func (d *PatternDecorator) SemanticTokens() []types.Token

func (*PatternDecorator) String

func (d *PatternDecorator) String() string

func (*PatternDecorator) TokenRange

func (d *PatternDecorator) TokenRange() TokenRange

type PatternType

type PatternType int

PatternType represents the type of pattern

const (
	IdentifierPatternType PatternType = iota // Named patterns like "production", "main"
	WildcardPatternType                      // Wildcard pattern "*"
)

func (PatternType) String

func (pt PatternType) String() string

type Position

type Position struct {
	Line   int
	Column int
	Offset int // Byte offset in source
}

Position represents source location information

type Program

type Program struct {
	Variables []VariableDecl
	VarGroups []VarGroup // Grouped variable declarations: var ( ... )
	Commands  []CommandDecl
	Pos       Position
	Tokens    TokenRange
}

Program represents the root of the CST (entire devcmd file) Preserves concrete syntax for LSP, Tree-sitter, and formatting tools

func NewProgram

func NewProgram(items ...interface{}) *Program

NewProgram creates a program AST node

func (*Program) Position

func (p *Program) Position() Position

func (*Program) SemanticTokens

func (p *Program) SemanticTokens() []types.Token

func (*Program) String

func (p *Program) String() string

func (*Program) TokenRange

func (p *Program) TokenRange() TokenRange

type ShellContent

type ShellContent struct {
	Parts  []ShellPart // Mixed content: text and inline decorators
	Pos    Position
	Tokens TokenRange
}

ShellContent represents shell command content with potential inline decorators This supports mixed content like: echo "Building on port @var(PORT)"

func Shell

func Shell(parts ...ShellPart) *ShellContent

Shell creates a shell content node

func (*ShellContent) IsCommandContent

func (s *ShellContent) IsCommandContent() bool

func (*ShellContent) Position

func (s *ShellContent) Position() Position

func (*ShellContent) SemanticTokens

func (s *ShellContent) SemanticTokens() []types.Token

func (*ShellContent) String

func (s *ShellContent) String() string

func (*ShellContent) TokenRange

func (s *ShellContent) TokenRange() TokenRange

type ShellPart

type ShellPart interface {
	Node
	IsShellPart() bool
}

ShellPart represents a part of shell content (text or inline decorator)

type StringLiteral

type StringLiteral struct {
	Value       string
	Raw         string
	Pos         Position
	Tokens      TokenRange
	StringToken types.Token
}

StringLiteral represents string values

func Str

func Str(value string) *StringLiteral

Str creates a string literal expression

func (*StringLiteral) GetType

func (s *StringLiteral) GetType() ExpressionType

func (*StringLiteral) IsExpression

func (s *StringLiteral) IsExpression() bool

func (*StringLiteral) Position

func (s *StringLiteral) Position() Position

func (*StringLiteral) SemanticTokens

func (s *StringLiteral) SemanticTokens() []types.Token

func (*StringLiteral) String

func (s *StringLiteral) String() string

func (*StringLiteral) TokenRange

func (s *StringLiteral) TokenRange() TokenRange

type TextPart

type TextPart struct {
	Text   string
	Pos    Position
	Tokens TokenRange
}

TextPart represents plain text within shell content

func Text

func Text(text string) *TextPart

Text creates a text part

func (*TextPart) IsShellPart

func (t *TextPart) IsShellPart() bool

func (*TextPart) Position

func (t *TextPart) Position() Position

func (*TextPart) SemanticTokens

func (t *TextPart) SemanticTokens() []types.Token

func (*TextPart) String

func (t *TextPart) String() string

func (*TextPart) TokenRange

func (t *TextPart) TokenRange() TokenRange

type TokenRange

type TokenRange struct {
	Start types.Token
	End   types.Token
	All   []types.Token
}

TokenRange represents the span of tokens for this AST node

type ValueDecorator

type ValueDecorator struct {
	Name   string
	Args   []NamedParameter
	Pos    Position
	Tokens TokenRange

	// Concrete syntax tokens for precise formatting and LSP
	AtToken    types.Token  // The "@" symbol
	NameToken  types.Token  // The decorator name token
	OpenParen  *types.Token // The "(" token (nil if no args)
	CloseParen *types.Token // The ")" token (nil if no args)
}

ValueDecorator represents inline decorators that provide values for shell interpolation Examples: @var(NAME), @env(VAR) - these appear WITHIN shell content and return values

func At

func At(name string, args ...NamedParameter) *ValueDecorator

At creates a value decorator within shell content: @var(NAME)

func FindVariableReferences

func FindVariableReferences(node Node) []*ValueDecorator

FindVariableReferences finds all @var() value decorator references in the AST

func GetReferencesForVariable

func GetReferencesForVariable(program *Program, varName string) []*ValueDecorator

GetReferencesForVariable finds all @var() value decorator references to a specific variable

func (*ValueDecorator) GetType

func (v *ValueDecorator) GetType() ExpressionType

func (*ValueDecorator) IsExpression

func (v *ValueDecorator) IsExpression() bool

func (*ValueDecorator) IsShellPart

func (v *ValueDecorator) IsShellPart() bool

func (*ValueDecorator) Position

func (v *ValueDecorator) Position() Position

func (*ValueDecorator) SemanticTokens

func (v *ValueDecorator) SemanticTokens() []types.Token

func (*ValueDecorator) String

func (v *ValueDecorator) String() string

func (*ValueDecorator) TokenRange

func (v *ValueDecorator) TokenRange() TokenRange

type VarGroup

type VarGroup struct {
	Variables []VariableDecl
	Pos       Position
	Tokens    TokenRange

	// Concrete syntax tokens for precise formatting
	VarToken   types.Token // The "var" keyword
	OpenParen  types.Token // The "(" token
	CloseParen types.Token // The ")" token
}

VarGroup represents grouped variable declarations: var ( NAME = value; ANOTHER = value ) Preserves the concrete syntax for formatting and LSP features

func (*VarGroup) Position

func (g *VarGroup) Position() Position

func (*VarGroup) SemanticTokens

func (g *VarGroup) SemanticTokens() []types.Token

func (*VarGroup) String

func (g *VarGroup) String() string

func (*VarGroup) TokenRange

func (g *VarGroup) TokenRange() TokenRange

type VariableDecl

type VariableDecl struct {
	Name   string
	Value  Expression
	Pos    Position
	Tokens TokenRange

	// LSP-specific information
	NameToken  types.Token
	ValueToken types.Token
}

VariableDecl represents variable declarations (both individual and grouped)

func GetDefinitionForVariable

func GetDefinitionForVariable(program *Program, varName string) *VariableDecl

GetDefinitionForVariable finds the variable declaration for a given reference

func Var

func Var(name string, value Expression) VariableDecl

Var creates a variable declaration: var NAME = VALUE

func (*VariableDecl) Position

func (v *VariableDecl) Position() Position

func (*VariableDecl) SemanticTokens

func (v *VariableDecl) SemanticTokens() []types.Token

func (*VariableDecl) String

func (v *VariableDecl) String() string

func (*VariableDecl) TokenRange

func (v *VariableDecl) TokenRange() TokenRange

type WildcardPattern

type WildcardPattern struct {
	Pos    Position
	Tokens TokenRange
	Token  types.Token
}

WildcardPattern represents the wildcard pattern "*"

func (*WildcardPattern) GetPatternType

func (w *WildcardPattern) GetPatternType() PatternType

func (*WildcardPattern) IsPattern

func (w *WildcardPattern) IsPattern() bool

func (*WildcardPattern) Position

func (w *WildcardPattern) Position() Position

func (*WildcardPattern) SemanticTokens

func (w *WildcardPattern) SemanticTokens() []types.Token

func (*WildcardPattern) String

func (w *WildcardPattern) String() string

func (*WildcardPattern) TokenRange

func (w *WildcardPattern) TokenRange() TokenRange

Jump to

Keyboard shortcuts

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