parser

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node interface {
	// GetNext returns the next node of the current node.
	GetNext() Node

	// GetChildren returns the children nodes of the current node.
	GetChildren() []Node

	// GetValue returns the value of the current node, the value is
	// the command or the args of the line by parsing the modelfile.
	GetValue() string

	// GetAttributes returns the attributes of the current node, such as key-value pairs.
	// Attributes can be used to expand the information of the node.
	GetAttributes() map[string]string

	// GetStartLine returns the start line of the current node, it will help to
	// locate the start of the node.
	GetStartLine() int

	// GetEndLine returns the end line of the current node, it will help to
	// locate the end of the node.
	GetEndLine() int

	// AddChild adds a child node to the current node.
	AddChild(child Node)

	// AddNext adds a next node to the current node.
	AddNext(next Node)

	// AddAttribute adds an attribute to the current node.
	AddAttribute(key, value string)
}

Node is the interface for the AST node.

Walk the AST to get the information by the root node. The root node is the entry point of the AST. Use the Node interface to build the AST for the modelfile.

func NewNode

func NewNode(value string, start, end int) Node

NewNode creates a new node of the AST with the value, start line, and end line. It is used to create the node of the AST, so need to create the node with the value by parsing the modelfile.

func NewRootNode

func NewRootNode() Node

NewRootNode creates a new root node of the AST. It is used as the entry point of the AST, so do not use it to create the node of the AST.

func Parse

func Parse(reader io.Reader) (Node, error)

Parse parses the modelfile and returns the root node of the AST, and the root node is the entry point of the AST. Walk the AST to get the information of the modelfile.

Jump to

Keyboard shortcuts

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