ast

package
v0.0.0-...-5c1ce85 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package ast declares the types used to represent syntax trees for LaTeX documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inspect

func Inspect(node Node, f func(Node) bool)

Inspect traverses an AST in depth-first order: It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f recursively for each of the non-nil children of node, followed by a call of f(nil).

func Print

func Print(o io.Writer, node Node)

Print prints node to w.

func Walk

func Walk(v Visitor, node Node)

Walk traverses an AST in depth-first order: It starts by calling v.Visit(node); node must not be nil. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).

Types

type Arg

type Arg struct {
	Lbrace token.Pos // position of '{'
	List   List      // or stmt?
	Rbrace token.Pos // position of '}'
}

Arg is an argument of a macro. ex:

{a} in \sqrt{a}

func (*Arg) End

func (x *Arg) End() token.Pos

func (*Arg) Pos

func (x *Arg) Pos() token.Pos

type Ident

type Ident struct {
	NamePos token.Pos // identifier position
	Name    string    // identifier name
}

func (*Ident) End

func (x *Ident) End() token.Pos

func (*Ident) Pos

func (x *Ident) Pos() token.Pos

type List

type List []Node

List is a collection of nodes.

func (List) End

func (x List) End() token.Pos

func (List) Pos

func (x List) Pos() token.Pos

type Literal

type Literal struct {
	LitPos token.Pos
	Text   string
}

func (*Literal) End

func (x *Literal) End() token.Pos

func (*Literal) Pos

func (x *Literal) Pos() token.Pos

type Macro

type Macro struct {
	Name *Ident
	Args List
}

Macro is a LaTeX macro. ex:

\sqrt{a}
\frac{num}{den}

func (*Macro) End

func (x *Macro) End() token.Pos

func (*Macro) Pos

func (x *Macro) Pos() token.Pos

type MathExpr

type MathExpr struct {
	Delim string    // delimiter used for this math expression.
	Left  token.Pos // position of opening '$', '\(', '\[' or '\begin{math}'
	List  List
	Right token.Pos // position of closing '$', '\)', '\]' or '\end{math}'
}

MathExpr is a math expression. ex:

$f(x) \doteq \sqrt[n]{x}$
\[ x^n + y^n = z^n \]

func (*MathExpr) End

func (x *MathExpr) End() token.Pos

func (*MathExpr) Pos

func (x *MathExpr) Pos() token.Pos

type Node

type Node interface {
	Pos() token.Pos // position of first character belonging to the node.
	End() token.Pos // position of first character immediately after the node.
	// contains filtered or unexported methods
}

Node is a node in a LaTeX document.

type OptArg

type OptArg struct {
	Lbrack token.Pos // position of '['
	List   List
	Rbrack token.Pos // position of ']'
}

OptArg is an optional argument of a macro ex:

[n] in \sqrt[n]{a}

func (*OptArg) End

func (x *OptArg) End() token.Pos

func (*OptArg) Pos

func (x *OptArg) Pos() token.Pos

type Sub

type Sub struct {
	UnderPos token.Pos
	Node     Node
}

Sub is a subscript node.

e.g.: \sum_{i=0}

func (*Sub) End

func (x *Sub) End() token.Pos

func (*Sub) Pos

func (x *Sub) Pos() token.Pos

type Sup

type Sup struct {
	HatPos token.Pos
	Node   Node
}

Sup is a superscript node.

e.g.: \sum^{n}

func (*Sup) End

func (x *Sup) End() token.Pos

func (*Sup) Pos

func (x *Sup) Pos() token.Pos

type Symbol

type Symbol struct {
	SymPos token.Pos
	Text   string
}

func (*Symbol) End

func (x *Symbol) End() token.Pos

func (*Symbol) Pos

func (x *Symbol) Pos() token.Pos

type Visitor

type Visitor interface {
	Visit(node Node) (w Visitor)
}

A Visitor's Visit method is invoked for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).

type Word

type Word struct {
	WordPos token.Pos
	Text    string
}

func (*Word) End

func (x *Word) End() token.Pos

func (*Word) Pos

func (x *Word) Pos() token.Pos

Jump to

Keyboard shortcuts

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