libparser

package module
v0.0.2-beta Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: ISC Imports: 5 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 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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