parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PREC_LOWEST     = iota
	PREC_PIPE       // |
	PREC_OR         // ||
	PREC_AND        // &&
	PREC_EQUALS     // ==, !=
	PREC_COMPARISON // <, <=, >, >=
	PREC_SUM        // +, -
	PREC_PRODUCT    // *, /
)

Operator precedence levels (higher = tighter binding)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Body []Node
	Pos  Pos
}

Array represents an array (e.g., [value1, value2])

func (*Array) GetPos

func (a *Array) GetPos() Pos

type AssignmentStatement

type AssignmentStatement struct {
	Name  string
	Value ValueStatement
	Pos   Pos
}

AssignmentStatement represents variable reassignment (e.g., name = "new value")

func (*AssignmentStatement) GetPos

func (a *AssignmentStatement) GetPos() Pos

type BinaryOp

type BinaryOp struct {
	Left     Expression
	Operator string // "&&", "||", "==", "!=", "<", "<=", ">", ">=", "+", "-", "*", "/"
	Right    Expression
	Pos      Pos
}

BinaryOp represents a binary operation (e.g., Values.debug && Values.verbose)

func (*BinaryOp) GetPos

func (b *BinaryOp) GetPos() Pos

type BooleanLiteral

type BooleanLiteral struct {
	Value bool
	Pos   Pos
}

BooleanLiteral represents a boolean value (true or false)

func (*BooleanLiteral) GetPos

func (b *BooleanLiteral) GetPos() Pos

type BreakStatement

type BreakStatement struct {
	Pos Pos
}

BreakStatement represents a break statement in a loop

func (*BreakStatement) GetPos

func (b *BreakStatement) GetPos() Pos

type CallExpression

type CallExpression struct {
	Function Expression
	Args     []Expression
	Pos      Pos
}

CallExpression represents a function call (e.g., upper(name), quote(str))

func (*CallExpression) GetPos

func (c *CallExpression) GetPos() Pos

type Comment

type Comment struct {
	Text string
	Pos  Pos
}

Comment represents a comment line

func (*Comment) GetPos

func (c *Comment) GetPos() Pos

type ContinueStatement

type ContinueStatement struct {
	Pos Pos
}

ContinueStatement represents a continue statement in a loop

func (*ContinueStatement) GetPos

func (c *ContinueStatement) GetPos() Pos

type CurrentContext

type CurrentContext struct {
	Pos Pos
}

CurrentContext represents a reference to the current context (.)

func (*CurrentContext) GetPos

func (c *CurrentContext) GetPos() Pos

type Definition

type Definition struct {
	Name string
	Body []Node // Single value for expression form, multiple for do block
	Pos  Pos
}

Definition represents a template definition (e.g., define(name, arg1, arg2) body)

func (*Definition) GetPos

func (d *Definition) GetPos() Pos

type Document

type Document struct {
	Body        []Statement
	Definitions []*Definition
}

Document represents the root of a helmtk template

func (*Document) GetPos

func (d *Document) GetPos() Pos

type Expression

type Expression interface {
	Node
	Statement
	ValueStatement
	// contains filtered or unexported methods
}

type ForStatement

type ForStatement struct {
	KeyVar   string
	ValueVar string
	Iterable Expression
	Body     []Node
	Pos      Pos
}

ForStatement represents a loop (e.g., for k, v in Values.extraEnvs { ... })

func (*ForStatement) GetPos

func (f *ForStatement) GetPos() Pos

type Identifier

type Identifier struct {
	Name string
	Pos  Pos
}

Identifier represents a variable reference (e.g., Values, name)

func (*Identifier) GetPos

func (i *Identifier) GetPos() Pos

type IfStatement

type IfStatement struct {
	Condition Expression
	Body      []Node
	Else      []Node // Optional else clause
	Pos       Pos
}

IfStatement represents a conditional (e.g., if Values.debug { ... })

func (*IfStatement) GetPos

func (i *IfStatement) GetPos() Pos

type IncludeExpression

type IncludeExpression struct {
	Name    string
	Context Expression
	Pos     Pos
}

IncludeExpression represents a template inclusion (e.g., include(name, arg1, arg2))

func (*IncludeExpression) GetPos

func (i *IncludeExpression) GetPos() Pos

type IndexExpression

type IndexExpression struct {
	Object Expression
	Index  Expression
	Pos    Pos
}

IndexExpression represents array/object indexing (e.g., array[0], obj[key])

func (*IndexExpression) GetPos

func (idx *IndexExpression) GetPos() Pos

type InterpolatedString

type InterpolatedString struct {
	Parts []Expression // Alternating StringLiteral and expression values
	Pos   Pos
}

InterpolatedString represents a string with embedded expressions (e.g., "Hello ${name}!")

func (*InterpolatedString) GetPos

func (i *InterpolatedString) GetPos() Pos

type KeyValueStatement

type KeyValueStatement struct {
	Key   string
	Value ValueStatement
	Pos   Pos
}

KeyValueStatement represents a key-value pair (e.g., apiVersion: "apps/v1")

func (*KeyValueStatement) GetPos

func (kv *KeyValueStatement) GetPos() Pos

type LetStatement

type LetStatement struct {
	Name  string
	Value ValueStatement
	Pos   Pos
}

LetStatement represents a variable definition (e.g., let name = "helmtk")

func (*LetStatement) GetPos

func (l *LetStatement) GetPos() Pos

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

func NewLexer

func NewLexer(input string) *Lexer

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

type MemberExpression

type MemberExpression struct {
	Object Expression
	Member string
	Pos    Pos
}

MemberExpression represents member access (e.g., obj.key)

func (*MemberExpression) GetPos

func (m *MemberExpression) GetPos() Pos

type Node

type Node interface {
	GetPos() Pos
	// contains filtered or unexported methods
}

Node represents a node in the abstract syntax tree

type NullLiteral

type NullLiteral struct {
	Pos Pos
}

NullLiteral represents a null value

func (*NullLiteral) GetPos

func (n *NullLiteral) GetPos() Pos

type NumberLiteral

type NumberLiteral struct {
	Value float64
	Pos   Pos
}

NumberLiteral represents a numeric value

func (*NumberLiteral) GetPos

func (n *NumberLiteral) GetPos() Pos

type Object

type Object struct {
	Body []Node
	Pos  Pos
}

Object represents an object (e.g., {key: value})

func (*Object) GetPos

func (o *Object) GetPos() Pos

type ParseError

type ParseError struct {
	Message string
	Line    int
	Col     int
	Offset  int
	Source  string // The full source code for context
}

ParseError represents a parsing error with position information

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) FormatWithContext

func (e *ParseError) FormatWithContext() string

FormatWithContext returns a formatted error message with source context

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser represents a helmtk template parser

func New

func New(source, filename string) *Parser

func (*Parser) Parse

func (p *Parser) Parse() (*Document, error)

Parse parses the input and returns a Document AST node

type Pos

type Pos struct {
	Filename string
	Line     int
	Col      int
}

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

Printer formats an AST for display

func NewPrinter

func NewPrinter(w io.Writer) *Printer

NewPrinter creates a new AST printer

func (*Printer) PrintArray

func (p *Printer) PrintArray(arr *Array)

PrintArray prints an Array node

func (*Printer) PrintBinaryOp

func (p *Printer) PrintBinaryOp(b *BinaryOp)

PrintBinaryOp prints a BinaryOp node

func (*Printer) PrintCallExpression

func (p *Printer) PrintCallExpression(call *CallExpression)

PrintCallExpression prints a CallExpression node

func (*Printer) PrintComment

func (p *Printer) PrintComment(c *Comment)

PrintComment prints a Comment node

func (*Printer) PrintDefineStatement

func (p *Printer) PrintDefineStatement(def *Definition)

PrintDefineStatement prints a DefineStatement node

func (*Printer) PrintDocument

func (p *Printer) PrintDocument(doc *Document)

PrintDocument prints a Document node

func (*Printer) PrintForStatement

func (p *Printer) PrintForStatement(forStmt *ForStatement)

PrintForStatement prints a ForStatement node

func (*Printer) PrintIfStatement

func (p *Printer) PrintIfStatement(ifStmt *IfStatement)

PrintIfStatement prints an IfStatement node

func (*Printer) PrintIncludeExpression

func (p *Printer) PrintIncludeExpression(inc *IncludeExpression)

PrintIncludeExpression prints an IncludeExpression node

func (*Printer) PrintIndexExpression

func (p *Printer) PrintIndexExpression(idx *IndexExpression)

PrintIndexExpression prints an IndexExpression node

func (*Printer) PrintInterpolatedString

func (p *Printer) PrintInterpolatedString(s *InterpolatedString)

PrintInterpolatedString prints an InterpolatedString node

func (*Printer) PrintKeyValue

func (p *Printer) PrintKeyValue(kv *KeyValueStatement)

PrintKeyValue prints a KeyValue node

func (*Printer) PrintLetStatement

func (p *Printer) PrintLetStatement(let *LetStatement)

PrintLetStatement prints a LetStatement node

func (*Printer) PrintMemberExpression

func (p *Printer) PrintMemberExpression(m *MemberExpression)

PrintMemberExpression prints a MemberExpression node

func (*Printer) PrintNode

func (p *Printer) PrintNode(node Node)

PrintNode prints any Node

func (*Printer) PrintObject

func (p *Printer) PrintObject(obj *Object)

PrintObject prints an Object node

func (*Printer) PrintSpreadElement

func (p *Printer) PrintSpreadElement(s *SpreadStatement)

PrintSpreadElement prints a SpreadElement node

func (*Printer) PrintStatement

func (p *Printer) PrintStatement(stmt Statement)

PrintStatement prints a Statement node

func (*Printer) PrintUnaryOp

func (p *Printer) PrintUnaryOp(u *UnaryOp)

PrintUnaryOp prints a UnaryOp node

func (*Printer) PrintValue

func (p *Printer) PrintValue(val Expression)

PrintValue prints an Expression node

func (*Printer) PrintValueStatement

func (p *Printer) PrintValueStatement(vs ValueStatement)

func (*Printer) PrintWithStatement

func (p *Printer) PrintWithStatement(withStmt *WithStatement)

PrintWithStatement prints a WithStatement node

type SpreadStatement

type SpreadStatement struct {
	Operand ValueStatement
	Pos     Pos
}

SpreadStatement represents a spread operator (e.g., spread obj, spread arr)

func (*SpreadStatement) GetPos

func (s *SpreadStatement) GetPos() Pos

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

Statement represents a top-level statement

type StringLiteral

type StringLiteral struct {
	Value string
	Pos   Pos
}

StringLiteral represents a quoted string

func (*StringLiteral) GetPos

func (s *StringLiteral) GetPos() Pos

type Token

type Token struct {
	Type  TokenType
	Value string
	Line  int
	Col   int
}

func (Token) String

func (t Token) String() string

type TokenType

type TokenType int
const (
	TokenEOF TokenType = iota
	TokenIdent
	TokenString
	TokenNumber
	TokenColon
	TokenComma
	TokenLBrace
	TokenRBrace
	TokenLBracket
	TokenRBracket
	TokenLParen
	TokenRParen
	TokenComment
	TokenNewline
	TokenIf
	TokenElse
	TokenFor
	TokenIn
	TokenWith
	TokenAs
	TokenDo
	TokenEnd
	TokenBreak
	TokenContinue
	TokenLet
	TokenDefine
	TokenInclude
	TokenSpread
	TokenTrue
	TokenFalse
	TokenNull
	TokenDot    // .
	TokenAssign // =
	TokenPlus   // +
	TokenMinus  // -
	TokenMul    // *
	TokenDiv    // /
	TokenPipe   // |
	TokenAnd    // &&
	TokenOr     // ||
	TokenEq     // ==
	TokenNeq    // !=
	TokenNot    // !
	TokenLt     // <
	TokenLte    // <=
	TokenGt     // >
	TokenGte    // >=
)

func (TokenType) String

func (t TokenType) String() string

type UnaryOp

type UnaryOp struct {
	Operator string // "!"
	Operand  Expression
	Pos      Pos
}

UnaryOp represents a unary operation (e.g., !Values.debug)

func (*UnaryOp) GetPos

func (u *UnaryOp) GetPos() Pos

type ValueStatement

type ValueStatement interface {
	Node
	// contains filtered or unexported methods
}

type WithStatement

type WithStatement struct {
	Context Expression
	VarName string // Variable name for the context (optional, empty string means use ".")
	Body    []Node
	Pos     Pos
}

WithStatement represents a context change (e.g., with Values.ingress as ing do ... end)

func (*WithStatement) GetPos

func (w *WithStatement) GetPos() Pos

Jump to

Keyboard shortcuts

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