parse

package
v1.6.69 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package parse provides readers for parsing Asciidoc

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(path asciidoc.Path, b []byte, opts ...Option) (*asciidoc.Document, error)

func Dump

func Dump(els ...asciidoc.Element)

func File

func File(path asciidoc.Path, opts ...Option) (*asciidoc.Document, error)

func Filter added in v1.5.41

func Filter(parent asciidoc.Parent, callback func(parent asciidoc.Parent, el asciidoc.Element) (remove bool, replace asciidoc.Elements, shortCircuit bool)) (shortCircuit bool)

func FindAll added in v1.5.41

func FindAll[T any](doc *asciidoc.Document, reader asciidoc.Reader, parent asciidoc.ParentElement) iter.Seq[T]

func FindFirst added in v1.5.41

func FindFirst[T any](doc *asciidoc.Document, reader asciidoc.Reader, parent asciidoc.ParentElement) T

func Raw added in v1.6.0

func Raw(path asciidoc.Path, b []byte, opts ...Option) (*asciidoc.Document, error)

func RawReader added in v1.6.0

func RawReader(path asciidoc.Path, reader io.Reader, opts ...Option) (*asciidoc.Document, error)

func Reader

func Reader(path asciidoc.Path, reader io.Reader, opts ...Option) (*asciidoc.Document, error)

func ReparseTable added in v1.5.41

func ReparseTable(table *asciidoc.Table, elements asciidoc.Elements) (err error)
func Search[T any](doc *asciidoc.Document, reader asciidoc.Reader, parent asciidoc.ParentElement, els asciidoc.Elements, callback ElementSearchCallback[T])

func Skim added in v1.5.41

func Skim[T any](reader asciidoc.Reader, parent asciidoc.ParentElement, elements asciidoc.Elements) iter.Seq[T]

func SkimFunc added in v1.5.41

func SkimFunc[T any](reader asciidoc.Reader, parent asciidoc.ParentElement, elements asciidoc.Elements, callback func(t T) bool) bool

func SkimList added in v1.5.41

func SkimList[T any](reader asciidoc.Reader, parent asciidoc.ParentElement, elements asciidoc.Elements) []T

func String

func String(path asciidoc.Path, s string) (*asciidoc.Document, error)

func Traverse added in v1.5.41

func Traverse[T any](doc *asciidoc.Document, reader asciidoc.Reader, parent asciidoc.ParentElement, els asciidoc.Elements, callback ElementSearchCallback[T])

Types

type ElementSearchCallback added in v1.5.41

type ElementSearchCallback[T any] func(doc *asciidoc.Document, el T, parent asciidoc.ParentElement, index int) SearchShould

type ElementTraverseCallback added in v1.6.0

type ElementTraverseCallback[T any] func(doc *asciidoc.Document, el T, parent asciidoc.ParentElement, index int) SearchShould

type Option

type Option func(*parser) Option

Option is a function that can set an option on the parser. It returns the previous setting as an Option.

func AllowInvalidUTF8

func AllowInvalidUTF8(b bool) Option

AllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes. Every invalid UTF-8 byte is treated as a utf8.RuneError (U+FFFD) by character class matchers and is matched by the any matcher. The returned matched value, c.text and c.offset are NOT affected.

The default is false.

func Entrypoint

func Entrypoint(ruleName string) Option

Entrypoint creates an Option to set the rule name to use as entrypoint. The rule name must have been specified in the -alternate-entrypoints if generating the parser with the -optimize-grammar flag, otherwise it may have been optimized out. Passing an empty string sets the entrypoint to the first rule in the grammar.

The default is to start parsing at the first rule in the grammar.

func GlobalStore

func GlobalStore(key string, value any) Option

GlobalStore creates an Option to set a key to a certain value in the globalStore.

func MaxExpressions

func MaxExpressions(maxExprCnt uint64) Option

MaxExpressions creates an Option to stop parsing after the provided number of expressions have been parsed, if the value is 0 then the parser will parse for as many steps as needed (possibly an infinite number).

The default for maxExprCnt is 0.

func Recover

func Recover(b bool) Option

Recover creates an Option to set the recover flag to b. When set to true, this causes the parser to recover from panics and convert it to an error. Setting it to false can be useful while debugging to access the full stack trace.

The default is true.

type PreParseContext

type PreParseContext interface {
	IsSet(name string) bool
	Get(name string) any
	Set(name string, value any)
	Unset(name string)
	GetCounterState(name string, initialValue string) (*asciidoc.CounterState, error)
	ResolvePath(root string, path string) (asciidoc.Path, error)
	ShouldIncludeFile(path asciidoc.Path) bool
}

type SearchShould added in v1.5.41

type SearchShould uint8
const (
	SearchShouldContinue SearchShould = iota
	SearchShouldStop
	SearchShouldSkip
)

type Stats

type Stats struct {
	// ExprCnt counts the number of expressions processed during parsing
	// This value is compared to the maximum number of expressions allowed
	// (set by the MaxExpressions option).
	ExprCnt uint64

	// ChoiceAltCnt is used to count for each ordered choice expression,
	// which alternative is used how may times.
	// These numbers allow to optimize the order of the ordered choice expression
	// to increase the performance of the parser
	//
	// The outer key of ChoiceAltCnt is composed of the name of the rule as well
	// as the line and the column of the ordered choice.
	// The inner key of ChoiceAltCnt is the number (one-based) of the matching alternative.
	// For each alternative the number of matches are counted. If an ordered choice does not
	// match, a special counter is incremented. The name of this counter is set with
	// the parser option Statistics.
	// For an alternative to be included in ChoiceAltCnt, it has to match at least once.
	ChoiceAltCnt map[string]map[string]int
}

Stats stores some statistics, gathered during parsing

Jump to

Keyboard shortcuts

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