latex

package
v0.0.0-...-d2edf06 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Definitions for known latex commands (basckslash commands) definitions are pulled from mathquill and pie-frameworks' extended version

The Tokenizer has two main functions: Peek() and Eat(). Peek() returns the current token(Of the tokenizer). Each token is a (atomic) string which is a single digit(NUM) / letter(VARLIT) / symbol(SYM) or a latex command, (e.g. \int) and latex commands are seperated into commands formed by a word, CMDSTR, or a command formed by a single symbol(e.g. \{), CMDSYM.

Index

Constants

View Source
const (
	ERR_TOKEN           = iota
	ERR_MISSING_CLOSE   // A Closing expression is missing e.g. "}" or "\right"
	ERR_UNMATCHED_CLOSE // Unmatched Closing expression e.g. "}" or "\right"
)
View Source
const ERROR_TOLERANCE = 1

Variables

This section is empty.

Functions

func NewCompletion

func NewCompletion() *trie.Trie

Types

type BadExpr

type BadExpr struct {
	From, To Pos
	// contains filtered or unexported fields
}

A BadExpr node is a placeholder for an expression containing syntax errors for which a correct expression node cannot be created.

func (*BadExpr) Content

func (x *BadExpr) Content() string

Literal method definitions

func (*BadExpr) End

func (x *BadExpr) End() Pos

func (*BadExpr) Pos

func (x *BadExpr) Pos() Pos

func (*BadExpr) VisualizeTree

func (x *BadExpr) VisualizeTree() string

type Cmd1ArgExpr

type Cmd1ArgExpr struct {
	Type      LatexCmd
	Backslash Pos // position of "\"
	Arg1      Expr
	To        Pos
	// contains filtered or unexported fields
}

TODO maybe remove variable source if not used A Cmd1ArgExpr node represents a command that takes 1 arguement e.g. \underline

func (*Cmd1ArgExpr) Children

func (x *Cmd1ArgExpr) Children() []Expr

func (*Cmd1ArgExpr) Command

func (x *Cmd1ArgExpr) Command() LatexCmd

func (*Cmd1ArgExpr) End

func (x *Cmd1ArgExpr) End() Pos

func (*Cmd1ArgExpr) Parameters

func (x *Cmd1ArgExpr) Parameters() int

func (*Cmd1ArgExpr) Pos

func (x *Cmd1ArgExpr) Pos() Pos

func (*Cmd1ArgExpr) SetArg

func (x *Cmd1ArgExpr) SetArg(index int, expr Expr)

func (*Cmd1ArgExpr) VisualizeTree

func (x *Cmd1ArgExpr) VisualizeTree() string

type Cmd2ArgExpr

type Cmd2ArgExpr struct {
	Type      LatexCmd
	Backslash Pos // position of "\"
	Arg1      Expr
	Arg2      Expr
	To        Pos
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------

Expresions

An expression is represented by a tree consisting of one or more of the
folowing concrete expression nodes.

func (*Cmd2ArgExpr) Children

func (x *Cmd2ArgExpr) Children() []Expr

func (*Cmd2ArgExpr) Command

func (x *Cmd2ArgExpr) Command() LatexCmd

func (*Cmd2ArgExpr) End

func (x *Cmd2ArgExpr) End() Pos

func (*Cmd2ArgExpr) Parameters

func (x *Cmd2ArgExpr) Parameters() int

func (*Cmd2ArgExpr) Pos

func (x *Cmd2ArgExpr) Pos() Pos

func (*Cmd2ArgExpr) SetArg

func (x *Cmd2ArgExpr) SetArg(index int, expr Expr)

func (*Cmd2ArgExpr) VisualizeTree

func (x *Cmd2ArgExpr) VisualizeTree() string

type CmdContainer

type CmdContainer interface {
	FixedContainer
	CmdExpr
}

A Latex Command that accepts a fixed number of children as its arguments. e.g. "_" which accepts 1 argument, "\frac" which accepts 2 args

type CmdExpr

type CmdExpr interface {
	Command() LatexCmd
}

type CmdLiteral

type CmdLiteral interface {
	Literal // the only reason this is here is to identify UnknownCmdLit via Content()
	CmdExpr
}

A Latex Command which takes no arguments and is (usually?) rendered as a single unicode symbol e.g. "\times", "\oplus", ...

type Comment

type Comment struct {
	Percent Pos    // position of "%" starting in a Comment
	Text    string // commented text (excluding \n)
}

---

func (*Comment) End

func (c *Comment) End() Pos

func (*Comment) Pos

func (c *Comment) Pos() Pos

type CompositeExpr

type CompositeExpr struct {
	Type       Expr   // literal type; or nil ?
	Lbrace     Pos    // Position of "{"
	Elts       []Expr // list of composite elements; or nil
	Rbrace     Pos    // position of "}"
	Incomplete bool   // true if (source) expressions are missing in Elts
}

A Composite node represents a composite braces surrounded { expression }

func (*CompositeExpr) AppendChildren

func (x *CompositeExpr) AppendChildren(children ...Expr)

func (*CompositeExpr) Children

func (x *CompositeExpr) Children() []Expr

func (*CompositeExpr) DeleteChildren

func (x *CompositeExpr) DeleteChildren(from int, to int)

func (*CompositeExpr) End

func (x *CompositeExpr) End() Pos

func (*CompositeExpr) Identifier

func (x *CompositeExpr) Identifier() string

func (*CompositeExpr) InsertChildren

func (x *CompositeExpr) InsertChildren(at int, children ...Expr)

func (*CompositeExpr) Pos

func (x *CompositeExpr) Pos() Pos

func (*CompositeExpr) VisualizeTree

func (x *CompositeExpr) VisualizeTree() string

VisualizeTree, naive approach, only for debugging purposes

type Container

type Container interface {
	Node
	Children() []Expr
}

A branch in the syntax tree

type EmptyExpr

type EmptyExpr struct {
	From, To Pos
	Type     Token
}

A EmptyExpr node is a placeholder to mark the termination of a previous expression TODO remove?

func (*EmptyExpr) Content

func (x *EmptyExpr) Content() string

func (*EmptyExpr) End

func (x *EmptyExpr) End() Pos

func (*EmptyExpr) Pos

func (x *EmptyExpr) Pos() Pos

func (*EmptyExpr) VisualizeTree

func (x *EmptyExpr) VisualizeTree() string

type ErrCode

type ErrCode int

func (ErrCode) String

func (e ErrCode) String() string

type ErrorHandler

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

func (*ErrorHandler) AddErr

func (eh *ErrorHandler) AddErr(e ErrCode, desc string)

func (*ErrorHandler) Errors

func (eh *ErrorHandler) Errors() int

func (*ErrorHandler) Trace

func (eh *ErrorHandler) Trace()

type Expr

type Expr interface {
	Node
}

type FixedContainer

type FixedContainer interface {
	Container
	Parameters() int // number of children
	SetArg(int, Expr)
}

Containers with a fixed number of children. Used for commands that take n arguements e.g. \frac takes 2 arguements and same goes for superscript ^ and subscript _, which take 1 arguement

type FlexContainer

type FlexContainer interface {
	Container
	AppendChildren(...Expr)

	// delete range of children, range inclusive on both ends
	DeleteChildren(from int, to int)
	InsertChildren(int, ...Expr)
	// TODO
	Identifier() string // temporary solution to identify the concrete type
}

Referring to containers that have indefinite amount of children

type IncompleteCmdLit

type IncompleteCmdLit struct {
	Backslash Pos    // Position of "\"
	Source    string // he command string including backslash
	To        Pos    // position of the last character
}

IncompleteCmdLit node is a placeholder for an incomplete command It is treated as a SimpleCmdLit, without any special grammar TODO remove?

type LatexCmd

type LatexCmd int

Note on wierd indentation: it's to group them together

const (
	CMD_UNKNOWN LatexCmd = iota

	// text formatting
	CMD_text

	// accents
	CMD_underline
	CMD_overline
	CMD_subscript
	CMD_superscript
	// CMD_lowercase
	CMD_sqrt

	CMD_binom
	CMD_frac

	CMD_left
	CMD_right

	CMD_alpha
	CMD_beta
	CMD_gamma
	CMD_delta
	CMD_zeta
	CMD_eta
	CMD_theta
	CMD_iota
	CMD_kappa
	CMD_mu
	CMD_nu
	CMD_xi
	CMD_rho
	CMD_sigma
	CMD_tau
	CMD_chi
	CMD_psi
	CMD_omega

	CMD_phi
	CMD_phiv
	CMD_varphi

	CMD_epsilon
	CMD_epsiv
	CMD_varepsilon

	CMD_piv
	CMD_varpi

	CMD_sigmaf
	CMD_sigmav
	CMD_varsigma

	CMD_thetav
	CMD_vartheta
	CMD_thetasym

	CMD_upsilon
	CMD_upsi

	CMD_gammad
	CMD_Gammad
	CMD_digamma

	CMD_kappav
	CMD_varkappa

	CMD_rhov
	CMD_varrho

	CMD_pi
	CMD_lambda

	CMD_Upsilon
	CMD_Upsi
	CMD_upsih
	CMD_Upsih

	CMD_Gamma
	CMD_Delta
	CMD_Theta
	CMD_Lambda
	CMD_Xi
	CMD_Pi
	CMD_Sigma
	CMD_Phi
	CMD_Psi
	CMD_Omega

	CMD_cdot
	CMD_sim
	CMD_cong
	CMD_equiv
	CMD_oplus
	CMD_otimes
	CMD_times
	CMD_div
	CMD_ne
	CMD_pm
	CMD_mp
	CMD_ast
	CMD_therefore
	CMD_because

	CMD_propto
	CMD_asymp

	CMD_lt
	CMD_gt
	CMD_le
	CMD_ge
	CMD_in
	CMD_notin
	CMD_ni
	CMD_notni

	CMD_subset
	CMD_supset
	CMD_nsubset
	CMD_nsupset

	CMD_subseteq
	CMD_supseteq

	CMD_nsubseteq
	CMD_nsupseteq

	CMD_sum
	CMD_prod
	CMD_coprod
	CMD_int

	CMD_N
	CMD_P
	CMD_Z
	CMD_Q
	CMD_Reals
	CMD_Complex
	CMD_H

	// spacing
	CMD_SPACE
	CMD_quad
	CMD_emsp
	CMD_qquad

	CMD_diamond
	CMD_bigtriangleup
	CMD_ominus
	CMD_uplus
	CMD_bigtriangledown
	CMD_sqcap
	CMD_triangleleft
	CMD_sqcup
	CMD_triangleright
	CMD_odot
	CMD_bigcirc
	CMD_dagger
	CMD_ddagger
	CMD_wr
	CMD_amalg

	CMD_models
	CMD_prec
	CMD_succ
	CMD_preceq
	CMD_succeq
	CMD_simeq
	CMD_mid
	CMD_ll
	CMD_gg
	CMD_parallel
	CMD_bowtie
	CMD_sqsubset
	CMD_sqsupset
	CMD_smile
	CMD_sqsubseteq
	CMD_sqsupseteq
	CMD_doteq
	CMD_frown
	CMD_vdash
	CMD_dashv

	CMD_longleftarrow
	CMD_longrightarrow
	CMD_Longleftarrow
	CMD_Longrightarrow
	CMD_longleftrightarrow
	CMD_updownarrow
	CMD_Longleftrightarrow
	CMD_Updownarrow
	CMD_mapsto
	CMD_nearrow
	CMD_hookleftarrow
	CMD_hookrightarrow
	CMD_searrow
	CMD_leftharpoonup
	CMD_rightharpoonup
	CMD_swarrow
	CMD_leftharpoondown
	CMD_rightharpoondown
	CMD_nwarrow

	CMD_ldots
	CMD_cdots
	CMD_vdots
	CMD_ddots
	CMD_surd
	CMD_triangle
	CMD_ell
	CMD_top
	CMD_flat
	CMD_natural
	CMD_sharp
	CMD_wp
	CMD_bot
	CMD_clubsuit
	CMD_diamondsuit
	CMD_heartsuit
	CMD_spadesuit

	CMD_oint
	CMD_bigcap
	CMD_bigcup
	CMD_bigsqcup
	CMD_bigvee
	CMD_bigwedge
	CMD_bigodot
	CMD_bigotimes
	CMD_bigoplus
	CMD_biguplus

	CMD_lfloor
	CMD_rfloor
	CMD_lceil
	CMD_rceil
	CMD_slash
	CMD_opencurlybrace
	CMD_closecurlybrace

	CMD_caret
	CMD_underscore
	CMD_backslash
	CMD_vert
	CMD_perp
	CMD_nabla
	CMD_hbar
	CMD_AA
	CMD_circ
	CMD_bullet
	CMD_setminus
	CMD_smallsetminus
	CMD_neg
	CMD_dots

	CMD_darr
	CMD_dArr
	CMD_uarr
	CMD_uArr
	CMD_to
	CMD_rArr
	CMD_gets
	CMD_lArr
	CMD_harr
	CMD_hArr

	CMD_Re
	CMD_Im
	CMD_partial

	CMD_infty
	CMD_alef

	CMD_forall
	CMD_exists
	CMD_land
	CMD_lor

	CMD_emptyset
	CMD_cup
	CMD_cap

	CMD_degree
	CMD_angle

	CMD_ln
	CMD_lg
	CMD_log
	CMD_span
	CMD_proj
	CMD_det
	CMD_dim
	CMD_min
	CMD_max
	CMD_mod
	CMD_lcm
	CMD_gcd
	CMD_gcf
	CMD_hcf
	CMD_lim

	CMD_sin
	CMD_cos
	CMD_tan
	CMD_sec
	CMD_cosec
	CMD_csc
	CMD_cotan
	CMD_cot

	CMD_sinh
	CMD_cosh
	CMD_tanh
	CMD_sech
	CMD_cosech
	CMD_csch
	CMD_cotanh
	CMD_coth

	CMD_asin
	CMD_acos
	CMD_atan
	CMD_asec
	CMD_acosec
	CMD_acsc
	CMD_acotan
	CMD_acot

	CMD_asinh
	CMD_acosh
	CMD_atanh
	CMD_asech
	CMD_acosech
	CMD_acsch
	CMD_acotanh
	CMD_acoth

	CMD_arcsin
	CMD_arccos
	CMD_arctan
	CMD_arcsec
	CMD_arccosec
	CMD_arccsc
	CMD_arccotan
	CMD_arccot

	CMD_arcsinh
	CMD_arccosh
	CMD_arctanh
	CMD_arcsech
	CMD_arccosech
	CMD_arccsch
	CMD_arccotanh
	CMD_arccoth

	// extended symbols by pie framework
	CMD_complement
	CMD_nexists
	CMD_sphericalangle
	CMD_iint
	CMD_iiint
	CMD_oiint
	CMD_oiiint
	CMD_backsim
	CMD_backsimeq
	CMD_eqsim
	CMD_ncong
	CMD_approxeq
	CMD_bumpeq
	CMD_Bumpeq
	CMD_doteqdot
	CMD_fallingdotseq
	CMD_risingdotseq
	CMD_eqcirc
	CMD_circeq
	CMD_triangleq
	CMD_leqq
	CMD_geqq
	CMD_lneqq
	CMD_gneqq
	CMD_between
	CMD_nleq
	CMD_ngeq
	CMD_lesssim
	CMD_gtrsim
	CMD_lessgtr
	CMD_gtrless
	CMD_preccurlyeq
	CMD_succcurlyeq
	CMD_precsim
	CMD_succsim
	CMD_nprec
	CMD_nsucc
	CMD_subsetneq
	CMD_supsetneq
	CMD_vDash
	CMD_Vdash
	CMD_Vvdash
	CMD_VDash
	CMD_nvdash
	CMD_nvDash
	CMD_nVdash
	CMD_nVDash
	CMD_vartriangleleft
	CMD_vartriangleright
	CMD_trianglelefteq
	CMD_trianglerighteq
	CMD_multimap
	CMD_Subset
	CMD_Supset
	CMD_Cap
	CMD_Cup
	CMD_pitchfork
	CMD_lessdot
	CMD_gtrdot
	CMD_lll
	CMD_ggg
	CMD_lesseqgtr
	CMD_gtreqless
	CMD_curlyeqprec
	CMD_curlyeqsucc
	CMD_nsim
	CMD_lnsim
	CMD_gnsim
	CMD_precnsim
	CMD_succnsim
	CMD_ntriangleleft
	CMD_ntriangleright
	CMD_ntrianglelefteq
	CMD_ntrianglerighteq
	CMD_blacksquare
	CMD_colon
	CMD_llcorner
	CMD_dotplus
	CMD_nmid
	CMD_intercal
	CMD_veebar
	CMD_barwedge
	CMD_ltimes
	CMD_rtimes
	CMD_leftthreetimes
	CMD_rightthreetimes
	CMD_curlyvee
	CMD_curlywedge
	CMD_circledcirc
	CMD_circledast
	CMD_circleddash
	CMD_boxplus
	CMD_boxminus
	CMD_boxtimes
	CMD_boxdot
)

func MatchLatexCmd

func MatchLatexCmd(cmd string) LatexCmd

func (LatexCmd) GetCmd

func (cmd LatexCmd) GetCmd() string

BUG map variables are unordered, this returns a different string everytime if multiple commands are available

func (LatexCmd) IsEnclosing

func (cmd LatexCmd) IsEnclosing() bool

func (LatexCmd) IsTextCmd

func (cmd LatexCmd) IsTextCmd() bool

func (LatexCmd) IsVanillaSym

func (cmd LatexCmd) IsVanillaSym() bool

func (LatexCmd) TakesOneArg

func (cmd LatexCmd) TakesOneArg() bool

func (LatexCmd) TakesRawStrArg

func (cmd LatexCmd) TakesRawStrArg() bool

func (LatexCmd) TakesTwoArg

func (cmd LatexCmd) TakesTwoArg() bool

type Literal

type Literal interface {
	Node
	Content() string
}

A leaf in the syntax tree

type Node

type Node interface {
	Pos() Pos
	End() Pos
	VisualizeTree() string
}

TODO after completing error handling component, see if we still need Pos() and End(), they're not implemented yet

type NumberLit

type NumberLit struct {
	From, To Pos
	Source   string // literal string; e.g. 23x
}

A NumberLit node represents a literal consisting of digits

func (*NumberLit) Content

func (x *NumberLit) Content() string

func (*NumberLit) End

func (x *NumberLit) End() Pos

func (*NumberLit) Pos

func (x *NumberLit) Pos() Pos

func (*NumberLit) VisualizeTree

func (x *NumberLit) VisualizeTree() string

type ParenCompExpr

type ParenCompExpr struct {
	From, To Pos
	Left     string // the character on the left side of the expression
	Right    string // the character on the right side of the expression
	Elts     []Expr // list of composite elements; or nil
}

A ParenCompExpr is a parenthesized Composite Expression surrounded by \left\right commands e.g. \left( x-y \right) Implements FlexContainer

func (*ParenCompExpr) AppendChildren

func (x *ParenCompExpr) AppendChildren(children ...Expr)

func (*ParenCompExpr) Children

func (x *ParenCompExpr) Children() []Expr

func (*ParenCompExpr) DeleteChildren

func (x *ParenCompExpr) DeleteChildren(from int, to int)

func (*ParenCompExpr) End

func (x *ParenCompExpr) End() Pos

func (*ParenCompExpr) Identifier

func (x *ParenCompExpr) Identifier() string

func (*ParenCompExpr) InsertChildren

func (x *ParenCompExpr) InsertChildren(at int, children ...Expr)

func (*ParenCompExpr) Pos

func (x *ParenCompExpr) Pos() Pos

func (*ParenCompExpr) VisualizeTree

func (x *ParenCompExpr) VisualizeTree() string

type ParseErr

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

type Parser

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

func NewParser

func NewParser(src string) *Parser

TODO: don't export?

func (*Parser) GetTree

func (p *Parser) GetTree() *UnboundCompExpr

func (*Parser) IsEOF

func (p *Parser) IsEOF() bool

Note that the parser's EOF is separate from the tokenizer's. the Parser's EOF should arrive one iteration of Parser.next() later than the tokenizer

type Pos

type Pos int // TODO remove

type RawRuneLit

type RawRuneLit rune

RawRuneLit node is a raw string, used by \text-like commands to wrap a string in a Expr node

func (RawRuneLit) Content

func (x RawRuneLit) Content() string

func (RawRuneLit) End

func (x RawRuneLit) End() Pos

func (RawRuneLit) Pos

func (x RawRuneLit) Pos() Pos

func (RawRuneLit) VisualizeTree

func (x RawRuneLit) VisualizeTree() string

type RunesContainer

type RunesContainer interface {
	Container
	BuildString() string
}

type SimpleCmdLit

type SimpleCmdLit struct {
	Backslash Pos    // Position of "\"
	Source    string // the command string including backslash
	Type      LatexCmd
	To        Pos // position of last character
}

A SimpleCmdLit node is a simple command that behaves like any other simple literal e.g. \times

func (*SimpleCmdLit) Command

func (x *SimpleCmdLit) Command() LatexCmd

func (*SimpleCmdLit) Content

func (x *SimpleCmdLit) Content() string

func (*SimpleCmdLit) End

func (x *SimpleCmdLit) End() Pos

func (*SimpleCmdLit) Pos

func (x *SimpleCmdLit) Pos() Pos

func (*SimpleCmdLit) VisualizeTree

func (x *SimpleCmdLit) VisualizeTree() string

type SimpleOpLit

type SimpleOpLit struct {
	From, To Pos
	Source   string // e.g. + - =
}

A SimpleOpLit node represents a simple operator literal

func (*SimpleOpLit) Content

func (x *SimpleOpLit) Content() string

func (*SimpleOpLit) End

func (x *SimpleOpLit) End() Pos

func (*SimpleOpLit) Pos

func (x *SimpleOpLit) Pos() Pos

func (*SimpleOpLit) VisualizeTree

func (x *SimpleOpLit) VisualizeTree() string

type SubExpr

type SubExpr struct {
	Symbol Pos  // position of "_"
	X      Expr // superscripted expression
	Close  Pos  // position of "}" if its a composite expression, otherwise the character
}

A SubExpr node represents a subscript expression

func (*SubExpr) End

func (x *SubExpr) End() Pos

func (*SubExpr) Pos

func (x *SubExpr) Pos() Pos

func (*SubExpr) VisualizeTree

func (x *SubExpr) VisualizeTree() string

type SuperExpr

type SuperExpr struct {
	Symbol Pos  // position of "^"
	X      Expr // superscripted expression
	Close  Pos  // position of "}" if its a composite expression, otherwise the character
}

A SuperExpr node represents a superscript expression TODO generalize

func (*SuperExpr) End

func (x *SuperExpr) End() Pos

func (*SuperExpr) Pos

func (x *SuperExpr) Pos() Pos

func (*SuperExpr) VisualizeTree

func (x *SuperExpr) VisualizeTree() string

type TextContainer

type TextContainer struct {
	CmdText  Pos // position of "\text"
	Type     LatexCmd
	From, To Pos // position of "{" / "}" or position of single-character
	Text     *TextStringWrapper
}

func (*TextContainer) Children

func (x *TextContainer) Children() []Expr

Container method definitions

func (*TextContainer) Command

func (x *TextContainer) Command() LatexCmd

func (*TextContainer) End

func (x *TextContainer) End() Pos

func (*TextContainer) Parameters

func (x *TextContainer) Parameters() int

FixedContainer methods

func (*TextContainer) Pos

func (x *TextContainer) Pos() Pos

func (*TextContainer) SetArg

func (x *TextContainer) SetArg(index int, expr Expr)

func (*TextContainer) VisualizeTree

func (x *TextContainer) VisualizeTree() string

type TextStringWrapper

type TextStringWrapper struct {
	Runes []Expr
}

func (*TextStringWrapper) AppendChildren

func (x *TextStringWrapper) AppendChildren(children ...Expr)

FlexContainer methods

func (*TextStringWrapper) BuildString

func (x *TextStringWrapper) BuildString() string

RunesContainer method definitions

func (*TextStringWrapper) Children

func (x *TextStringWrapper) Children() []Expr

func (*TextStringWrapper) DeleteChildren

func (x *TextStringWrapper) DeleteChildren(from int, to int)

Deletes Children from the first index to the second index, inclusive

func (*TextStringWrapper) End

func (x *TextStringWrapper) End() Pos

func (*TextStringWrapper) Identifier

func (x *TextStringWrapper) Identifier() string

func (*TextStringWrapper) InsertChildren

func (x *TextStringWrapper) InsertChildren(at int, children ...Expr)

Insert child at index; the new child has the index 'at'

func (*TextStringWrapper) Pos

func (x *TextStringWrapper) Pos() Pos

func (*TextStringWrapper) VisualizeTree

func (x *TextStringWrapper) VisualizeTree() string

type Token

type Token int

Token is the set of lexical tokens

const (
	// Special tokens
	ILLEGAL Token = iota
	EOF
	NOTOKEN     // for Parser.expect, representing 'not expecting anything'
	SINGLETOKEN // for Parser.expect, 'expecting single characters'
	COMMENT

	// basic type literals
	NUM     // numbers
	VARLIT  // variable string literal, contains only alphabets
	TEXTSTR // string in \text, can be anything: symbols, numbers, letters...
	SYM     // symbols: non-alphabet characters that have no special grammar

	LPAREN // (
	LBRACK // [
	LBRACE // {
	RPAREN // )
	RBRACK // ]
	RBRACE // }

	CARET      // ^
	UNDERSCORE // _
	AMPERSAND  // &

	CMDSTR
	CMDSYM
)

func (Token) IsLiteral

func (tok Token) IsLiteral() bool

IsLiteral returns true for tokens corresponding to identifiers and basic type literals; it returns false otherwise.

func (Token) IsOperator

func (tok Token) IsOperator() bool

IsOperator returns true for tokens corresponding to operators and delimiters; it returns false otherwise.

func (Token) String

func (tok Token) String() string

type Tokenizer

type Tokenizer struct {
	Cursor Pos
	Stream string
	// contains filtered or unexported fields
}

func (*Tokenizer) Eat

func (t *Tokenizer) Eat() string

func (*Tokenizer) Init

func (t *Tokenizer) Init(stream string)

func (*Tokenizer) IsEOF

func (t *Tokenizer) IsEOF() bool

func (*Tokenizer) Peek

func (t *Tokenizer) Peek() Token

func (*Tokenizer) SkipToDelimiter

func (t *Tokenizer) SkipToDelimiter(delimiter string) string

skips to the delimiter and return the skipped string

type UnboundCompExpr

type UnboundCompExpr struct {
	From, To Pos
	Elts     []Expr // list of composite elements; or nil
}

A UnboundCompExpr is basically the same as CompositeExpr but without brackets "{}"

func Parse

func Parse(src string) *UnboundCompExpr

func (*UnboundCompExpr) AppendChildren

func (x *UnboundCompExpr) AppendChildren(children ...Expr)

func (*UnboundCompExpr) Children

func (x *UnboundCompExpr) Children() []Expr

func (*UnboundCompExpr) DeleteChildren

func (x *UnboundCompExpr) DeleteChildren(from int, to int)

func (*UnboundCompExpr) End

func (x *UnboundCompExpr) End() Pos

func (*UnboundCompExpr) Identifier

func (x *UnboundCompExpr) Identifier() string

func (*UnboundCompExpr) InsertChildren

func (x *UnboundCompExpr) InsertChildren(at int, children ...Expr)

func (*UnboundCompExpr) Pos

func (x *UnboundCompExpr) Pos() Pos

func (*UnboundCompExpr) VisualizeTree

func (x *UnboundCompExpr) VisualizeTree() string

---------------------------------------------------------------------------- VisualizeTree, naive approach, only for debugging purposes

type UnknownCmdLit

type UnknownCmdLit struct {
	Backslash Pos    // Position of "\"
	Source    string // he command string including backslash
	To        Pos    // position of the last character
}

UnknownCmdLit node is a placeholder for an unrecognized command It is treated as a SimpleCmdLit, without any special grammar TODO remove?

func (*UnknownCmdLit) Command

func (x *UnknownCmdLit) Command() LatexCmd

CmdLiteral, CmdContainer method definitions

func (*UnknownCmdLit) Content

func (x *UnknownCmdLit) Content() string

func (*UnknownCmdLit) End

func (x *UnknownCmdLit) End() Pos

func (*UnknownCmdLit) Pos

func (x *UnknownCmdLit) Pos() Pos

func (*UnknownCmdLit) VisualizeTree

func (x *UnknownCmdLit) VisualizeTree() string

type VarLit

type VarLit struct {
	From, To Pos
	Source   string
}

A VarLit node represents a literal consisting of alphabets

func (*VarLit) Content

func (x *VarLit) Content() string

func (*VarLit) End

func (x *VarLit) End() Pos

func (*VarLit) Pos

func (x *VarLit) Pos() Pos

func (*VarLit) VisualizeTree

func (x *VarLit) VisualizeTree() string

Jump to

Keyboard shortcuts

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