libparser

package module
v0.1.2-beta Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: ISC Imports: 8 Imported by: 2

README

Tomefile Parser

Library to parse Tomefile code and output statements similar to AST for use by another program.

Uses just-in-time compilation to allow for execution of statements as soon as possible rather than waiting for the entire code to parse first. It comes with a drawback of not catching errors ahead of time.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Null = &Node{Type: NODE_NULL}

Functions

This section is empty.

Types

type FormatModifier

type FormatModifier func(string) string

func GetModifier

func GetModifier(name string, args []string) FormatModifier

type FormatPart

type FormatPart interface {
	Eval(Scope) (string, error)
}

type Formatter

type Formatter struct {
	Reader *bufio.Reader
	// contains filtered or unexported fields
}

func NewFormatter

func NewFormatter(reader io.Reader) *Formatter

func (*Formatter) Parse

func (formatter *Formatter) Parse() ([]FormatPart, error)

func (*Formatter) Read

func (formatter *Formatter) Read() (rune, error)

type LiteralFormat

type LiteralFormat struct {
	Literal string
}

func (LiteralFormat) Eval

func (format LiteralFormat) Eval(_ Scope) (string, error)

type Node

type Node struct {
	Parent *Node // Optional

	Type    NodeType
	Literal string
	Args    []any // can either contain [string] or [*Node]

	// The offset in bytes where this node begins
	OffsetStart uint
	// The offset in bytes where this node ends
	OffsetEnd uint

	Col, Row uint
	// Equals 0 if offset range is multi-line. Otherwise the length starting from [.Col]
	Length uint

	Children []*Node // Optional
}

func (*Node) IsError

func (node *Node) IsError() bool

type NodeType

type NodeType byte
const (
	NODE_NULL NodeType = iota
	NODE_COMMENT
	NODE_DIRECTIVE
	NODE_MACRO
	NODE_EXEC

	NODE_ERROR_READ
	NODE_ERROR_SYNTAX

	ErrMin = NODE_ERROR_READ
	ErrMax = NODE_ERROR_SYNTAX
)

type Parser

type Parser struct {
	Reader  *internal.AdvancedReader
	Channel chan *Node
	// contains filtered or unexported fields
}

func New

func New(reader *bufio.Reader, consumer chan *Node) *Parser

func (*Parser) ParseComplete

func (parser *Parser) ParseComplete()

Nodes are returned only once all of their children are read (slow). Sets Node.Children if applicable. Node.Parent is always nil to prevent pointer recursion

func (*Parser) ParseFragmented

func (parser *Parser) ParseFragmented()

Nodes are returned as soon as they are read (fast). Sets Node.Parent. Node.Children is always nil

type Scope

type Scope map[string]string

type VariableFormat

type VariableFormat struct {
	Name       string
	Modifier   FormatModifier
	IsOptional bool
}

func (VariableFormat) Eval

func (format VariableFormat) Eval(scope Scope) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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