compiler

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(prog *Program) string

func ValidateProgram

func ValidateProgram(program *Program) []error

ValidateProgram is a convenience function to validate a program

Types

type AssignmentStmt

type AssignmentStmt struct {
	Name  *IdenExpr
	Value Expr
}

func (*AssignmentStmt) String

func (ae *AssignmentStmt) String() string

type CommentedNode

type CommentedNode struct {
	LeadingComments []*Token // Comments on lines before this node
	Node            Node
	TrailingComment *Token // Comment on the same line after the node
}

CommentedNode wraps a Node with its associated comments

func AssociateComments

func AssociateComments(prog *Program) []*CommentedNode

AssociateComments attaches comments to their nearest nodes

type ConstDecl

type ConstDecl struct {
	Token      *Token // 'const' token
	Assignment *AssignmentStmt
}

func (*ConstDecl) String

func (cd *ConstDecl) String() string

type Decl

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

type DeclAnyType

type DeclAnyType struct {
	Name *IdenExpr
}

func (*DeclAnyType) String

func (dat *DeclAnyType) String() string

type DeclArrayType

type DeclArrayType struct {
	Token *Token
	Type  Decl
}

func (*DeclArrayType) String

func (dat *DeclArrayType) String() string

type DeclBoolType

type DeclBoolType struct {
	Name *IdenExpr
}

func (*DeclBoolType) String

func (dbt *DeclBoolType) String() string

type DeclByteType

type DeclByteType struct {
	Name *IdenExpr
}

func (*DeclByteType) String

func (dbt *DeclByteType) String() string

type DeclCustomType

type DeclCustomType struct {
	Name *IdenExpr
}

func (*DeclCustomType) String

func (dct *DeclCustomType) String() string

type DeclEnum

type DeclEnum struct {
	Token      *Token // 'enum' token
	Name       *IdenExpr
	Values     []*DeclEnumSet
	CloseCurly *Token
}

func (*DeclEnum) String

func (de *DeclEnum) String() string

type DeclEnumSet

type DeclEnumSet struct {
	Name      *IdenExpr
	Value     Expr
	IsDefined bool
}

func (*DeclEnumSet) String

func (des *DeclEnumSet) String() string

type DeclError

type DeclError struct {
	Token      *Token
	Name       *IdenExpr
	Code       *ValueExprNumber
	Msg        *ValueExprString
	CloseCurly *Token
}

func (*DeclError) String

func (de *DeclError) String() string

type DeclMapType

type DeclMapType struct {
	Token     *Token
	KeyType   Decl
	ValueType Decl
}

func (*DeclMapType) String

func (dmt *DeclMapType) String() string

type DeclModel

type DeclModel struct {
	Token      *Token
	Name       *IdenExpr
	Extends    []*IdenExpr
	Fields     []*DeclModelField
	CloseCurly *Token
}

func (*DeclModel) String

func (dm *DeclModel) String() string

type DeclModelField

type DeclModelField struct {
	Name     *IdenExpr
	Type     DeclType
	Optional bool
	Options  []*AssignmentStmt
}

func (*DeclModelField) String

func (dmf *DeclModelField) String() string

type DeclNameTypePair

type DeclNameTypePair struct {
	Name *IdenExpr
	Type DeclType
}

func (*DeclNameTypePair) String

func (dntp *DeclNameTypePair) String() string

type DeclNumberType

type DeclNumberType struct {
	Name *IdenExpr
}

func (*DeclNumberType) String

func (dnt *DeclNumberType) String() string

type DeclService

type DeclService struct {
	Token      *Token
	Name       *IdenExpr
	Methods    []*DeclServiceMethod
	CloseCurly *Token
}

func (*DeclService) String

func (ds *DeclService) String() string

type DeclServiceMethod

type DeclServiceMethod struct {
	Name    *IdenExpr
	Args    []*DeclNameTypePair
	Returns []*DeclNameTypePair
	Options []*AssignmentStmt
}

func (*DeclServiceMethod) String

func (dsm *DeclServiceMethod) String() string

type DeclStringType

type DeclStringType struct {
	Name *IdenExpr
}

func (*DeclStringType) String

func (dst *DeclStringType) String() string

type DeclTimestampType

type DeclTimestampType struct {
	Name *IdenExpr
}

func (*DeclTimestampType) String

func (dtt *DeclTimestampType) String() string

type DeclType

type DeclType interface {
	Decl
	// contains filtered or unexported methods
}

type Error

type Error struct {
	Token  *Token
	Reason string
}

Error represents a unified error type for scanner, parser, and validation errors

func NewError

func NewError(tok *Token, format string, args ...any) *Error

NewError creates a new Error with the given token and reason

func (*Error) Error

func (e *Error) Error() string

type ErrorDisplay

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

ErrorDisplay provides formatted error output with source context

func NewErrorDisplay

func NewErrorDisplay(source string, filename string) *ErrorDisplay

NewErrorDisplay creates a new ErrorDisplay from source code

func (*ErrorDisplay) FormatCompilerError

func (ed *ErrorDisplay) FormatCompilerError(err *Error) string

FormatCompilerError formats an Error with source context

func (*ErrorDisplay) FormatCompilerErrorPlain

func (ed *ErrorDisplay) FormatCompilerErrorPlain(err *Error) string

FormatCompilerErrorPlain formats an Error without ANSI colors

func (*ErrorDisplay) FormatError

func (ed *ErrorDisplay) FormatError(err error) string

FormatError formats an Error with source context for terminal display

func (*ErrorDisplay) FormatErrorPlain

func (ed *ErrorDisplay) FormatErrorPlain(err error) string

FormatErrorPlain formats an error without ANSI colors (for non-terminal output)

type Expr

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

type GoGenerator

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

GoGenerator transforms Ella AST to Go source code

func NewGoGenerator

func NewGoGenerator(program *Program, packageName string) *GoGenerator

NewGoGenerator creates a new Go code generator

func (*GoGenerator) Generate

func (g *GoGenerator) Generate() (string, error)

Generate produces Go source code from the Ella program

func (*GoGenerator) GenerateHelperTypes

func (g *GoGenerator) GenerateHelperTypes() string

GenerateHelperTypes generates common helper types like HandleRegistry and Error

func (*GoGenerator) GenerateToWriter

func (g *GoGenerator) GenerateToWriter(w io.Writer) error

func (*GoGenerator) GenerateWithHelpers

func (g *GoGenerator) GenerateWithHelpers() (string, error)

GenerateWithHelpers produces complete Go source with helper types

type IdenExpr

type IdenExpr struct {
	Token *Token
	Name  string
}

func (*IdenExpr) String

func (ie *IdenExpr) String() string

type Node

type Node interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

type Parser

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

func NewParser

func NewParser(s *Scanner) *Parser

func (*Parser) Parse

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

type Pos

type Pos struct {
	Offset int
	Line   int
	Column int
	Src    string
}

type Program

type Program struct {
	Nodes    []Node
	Comments []*Token
}

func (*Program) String

func (p *Program) String() string

type RuneScanner

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

func NewRuneScanner

func NewRuneScanner(r io.Reader, src string) *RuneScanner

func (*RuneScanner) Accept

func (r *RuneScanner) Accept(valid string) (rune, Pos, bool)

func (*RuneScanner) AcceptRun

func (r *RuneScanner) AcceptRun(valid string) (string, Pos, bool)

func (*RuneScanner) AcceptRunUntil

func (r *RuneScanner) AcceptRunUntil(invalid string) (string, Pos, bool)

func (*RuneScanner) Backup

func (r *RuneScanner) Backup()

func (*RuneScanner) Buffer

func (r *RuneScanner) Buffer() string

func (*RuneScanner) BufferLen

func (r *RuneScanner) BufferLen() int

func (*RuneScanner) CleanBuffer

func (r *RuneScanner) CleanBuffer()

func (*RuneScanner) Next

func (r *RuneScanner) Next() (rune, Pos)

func (*RuneScanner) Peek

func (r *RuneScanner) Peek() rune

type Scanner

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

func NewScanner

func NewScanner(r io.Reader, src string) *Scanner

func (*Scanner) Scan

func (s *Scanner) Scan() (*Token, error)

func (*Scanner) ScanNumber

func (s *Scanner) ScanNumber() (*Token, error)

func (*Scanner) ScanReservedWord

func (s *Scanner) ScanReservedWord() *Token

type Stmt

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

type Token

type Token struct {
	Type TokenType
	Pos  Pos
	Lit  string
}

func (*Token) IsInjected

func (t *Token) IsInjected() bool

type TokenType

type TokenType int
const (
	EOF TokenType = iota
	UNKNOWN
	ERROR
	COMMENT
	IDENTIFIER
	CONST
	ENUM
	MODEL
	SERVICE
	BYTE
	BOOL
	INT8
	INT16
	INT32
	INT64
	UINT8
	UINT16
	UINT32
	UINT64
	FLOAT32
	FLOAT64
	TIMESTAMP
	STRING
	ANY
	MAP
	CONST_NUMBER
	CONST_STRING_SINGLE_QUOTE
	CONST_STRING_DOUBLE_QUOTE
	CONST_STRING_BACKTICK_QOUTE
	CONST_BOOL
	CONST_NULL
	EQUAL
	OPTIONAL
	COLON
	COMMA
	DOT
	OPEN_CURLY
	CLOSE_CURLY
	OPEN_PAREN
	CLOSE_PAREN
	OPEN_ANGLE
	CLOSE_ANGLE
	OPEN_SQURE
	CLOSE_SQURE
	CUSTOM_ERROR
)

func (TokenType) String

func (tt TokenType) String() string

type TypeScriptGenerator

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

TypeScriptGenerator generates TypeScript definitions for Ella schemas

func NewTypeScriptGenerator

func NewTypeScriptGenerator(program *Program) *TypeScriptGenerator

NewTypeScriptGenerator creates a new TypeScript code generator

func (*TypeScriptGenerator) Generate

func (g *TypeScriptGenerator) Generate() (string, error)

Generate produces TypeScript definition source code

func (*TypeScriptGenerator) GenerateClient

func (g *TypeScriptGenerator) GenerateClient() (string, error)

GenerateClient produces runtime TypeScript client source code.

func (*TypeScriptGenerator) GenerateClientToWriter

func (g *TypeScriptGenerator) GenerateClientToWriter(w io.Writer) error

GenerateClientToWriter writes runtime TypeScript client code (.ts) to the writer.

func (*TypeScriptGenerator) GenerateRuntimeConstsToWriter

func (g *TypeScriptGenerator) GenerateRuntimeConstsToWriter(w io.Writer) error

GenerateRuntimeConstsToWriter writes runtime TypeScript exports. It emits schema const declarations and error code constants so values are available at runtime.

func (*TypeScriptGenerator) GenerateToWriter

func (g *TypeScriptGenerator) GenerateToWriter(w io.Writer) error

GenerateToWriter writes the TypeScript definitions to the writer

type Validator

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

Validator validates an Ella AST

func NewValidator

func NewValidator(program *Program) *Validator

NewValidator creates a new validator

func (*Validator) Validate

func (v *Validator) Validate() []error

Validate validates the program and returns any errors

type ValueExprBool

type ValueExprBool struct {
	Token *Token
}

func (*ValueExprBool) String

func (veb *ValueExprBool) String() string

type ValueExprNull

type ValueExprNull struct {
	Token *Token
}

func (*ValueExprNull) String

func (ven *ValueExprNull) String() string

type ValueExprNumber

type ValueExprNumber struct {
	Token *Token
	Type  *IdenExpr
}

func (*ValueExprNumber) String

func (ven *ValueExprNumber) String() string

type ValueExprString

type ValueExprString struct {
	Token *Token
}

func (*ValueExprString) String

func (ves *ValueExprString) String() string

type WasmGenerator

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

WasmGenerator generates JavaScript/WASM bindings for Ella services

func NewWasmGenerator

func NewWasmGenerator(program *Program, packageName string, allowExtensions bool) *WasmGenerator

NewWasmGenerator creates a new WASM code generator

func (*WasmGenerator) Generate

func (g *WasmGenerator) Generate() (string, error)

Generate produces WASM binding source code

func (*WasmGenerator) GenerateToWriter

func (g *WasmGenerator) GenerateToWriter(w io.Writer) error

GenerateToWriter writes the WASM bindings to the writer

Jump to

Keyboard shortcuts

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