bibtex

package module
v0.0.0-...-5e192c7 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package resolver transforms a Bibtex AST into complete bibtex entries, resolving cross references, parsing authors and editors, and normalizing page numbers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractAuthors

func ExtractAuthors(txt *ast.ParsedText) (ast.Authors, error)

ExtractAuthors extracts the authors from the parsed text of a bibtex field, usually from the author or editor field of bibtex entry.

func SimplifyEscapedTextResolver

func SimplifyEscapedTextResolver(root ast.Node) error

SimplifyEscapedTextResolver replaces ast.TextEscaped nodes with a plain ast.Text containing the value that was escaped. Meaning, `\&` is converted to `&`.

Types

type AuthorResolver

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

AuthorResolver extracts ast.Authors from the expression value of a tag statement.

func NewAuthorResolver

func NewAuthorResolver(tags ...string) AuthorResolver

func (AuthorResolver) Resolve

func (a AuthorResolver) Resolve(root ast.Node) error

type Biber

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

Bibtex contains methods for parsing, resolving, and rendering bibtex.

func New

func New(opts ...Option) *Biber

func (*Biber) Parse

func (b *Biber) Parse(r io.Reader) (*ast.File, error)

func (*Biber) Render

func (b *Biber) Render(w io.Writer, root ast.Node) error

func (*Biber) Resolve

func (b *Biber) Resolve(node ast.Node) ([]Entry, error)

Resolve resolves all bibtex entries from an AST. The AST is a faithful representation of source code. By default, resolving the AST means replacing all abbreviation expressions with the value, inlining concatenation expressions, simplifying tag values by replacing TeX quote macros with Unicode graphemes, and stripping Tex macros.

The exact resolve steps are configurable using bibtex.WithResolvers.

type CiteKey

type CiteKey = string

CiteKey is the citation key for a Bibtex entry, like the "foo" in:

@article{ foo }

type Entry

type Entry struct {
	Type EntryType
	Key  CiteKey
	// All tags in the entry with the corresponding expression value.
	Tags map[Field]ast.Expr
}

Entry is a Bibtex entry, like an @article{} entry, that provides the rendered plain text of the entry.

type EntryType

type EntryType = string

EntryType is the type of Bibtex entry. An "@article" entry is represented as "article". String alias to allow for unknown entries.

const (
	EntryArticle       EntryType = "article"
	EntryBook          EntryType = "book"
	EntryBooklet       EntryType = "booklet"
	EntryInBook        EntryType = "inbook"
	EntryInCollection  EntryType = "incollection"
	EntryInProceedings EntryType = "inproceedings"
	EntryManual        EntryType = "manual"
	EntryMastersThesis EntryType = "mastersthesis"
	EntryMisc          EntryType = "misc"
	EntryPhDThesis     EntryType = "phdthesis"
	EntryProceedings   EntryType = "proceedings"
	EntryTechReport    EntryType = "techreport"
	EntryUnpublished   EntryType = "unpublished"
)

type Field

type Field = string

Field is a single field in a Bibtex Entry.

const (
	FieldAddress      Field = "address"
	FieldAnnote       Field = "annote"
	FieldAuthor       Field = "author"
	FieldBookTitle    Field = "booktitle"
	FieldChapter      Field = "chapter"
	EntryDOI          Field = "doi"
	FieldCrossref     Field = "crossref"
	FieldEdition      Field = "edition"
	FieldEditor       Field = "editor"
	FieldHowPublished Field = "howpublished"
	FieldInstitution  Field = "institution"
	FieldJournal      Field = "journal"
	FieldKey          Field = "key"
	FieldMonth        Field = "month"
	FieldNote         Field = "note"
	FieldNumber       Field = "number"
	FieldOrganization Field = "organization"
	FieldPages        Field = "pages"
	FieldPublisher    Field = "publisher"
	FieldSchool       Field = "school"
	FieldSeries       Field = "series"
	FieldTitle        Field = "title"
	FieldType         Field = "type"
	FieldVolume       Field = "volume"
	FieldYear         Field = "year"
)

type Option

type Option func(*Biber)

Option is a functional option to change how Bibtex is parsed, resolved, and rendered.

func WithParserMode

func WithParserMode(mode parser.Mode) Option

WithParserMode sets the parser options overwriting any previous parser options. parser.Mode is a bitflag so use bit-or for multiple flags like so:

WithParserMode(parser.ParserStrings|parser.Trace)

func WithRenderer

func WithRenderer(kind ast.NodeKind, r render.NodeRendererFunc) Option

WithRenderer sets the renderer for the node kind, replacing the previous renderer.

func WithResolvers

func WithResolvers(rs ...Resolver) Option

WithResolvers appends the resolvers to the list of resolvers. Resolvers run in the order given.

type RenderParsedTextResolver

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

RenderParsedTextResolver replaces ast.ParsedText with a simplified rendering of ast.Text.

func NewRenderParsedTextResolver

func NewRenderParsedTextResolver() *RenderParsedTextResolver

func (*RenderParsedTextResolver) Resolve

func (r *RenderParsedTextResolver) Resolve(root ast.Node) error

type Resolver

type Resolver interface {
	Resolve(n ast.Node) error
}

Resolver is an in-place mutation of an ast.Node to support resolving Bibtex entries. Typically, the mutations simplify the AST to support easier manipulation, like replacing ast.EscapedText with the escaped value.

type ResolverFunc

type ResolverFunc func(n ast.Node) error

func (ResolverFunc) Resolve

func (r ResolverFunc) Resolve(n ast.Node) error

Directories

Path Synopsis
Package ast declares the types used to represent syntax trees for bibtex files.
Package ast declares the types used to represent syntax trees for bibtex files.
Packages asts contains utilities for constructing and manipulating ASTs.
Packages asts contains utilities for constructing and manipulating ASTs.
This file contains the exported entry points for invoking the parser.
This file contains the exported entry points for invoking the parser.
Package scanner implements a scanner for bibtex source text.
Package scanner implements a scanner for bibtex source text.
Package token defines constants representing the lexical tokens of the bibtex language and basic operations on tokens (printing, predicates).
Package token defines constants representing the lexical tokens of the bibtex language and basic operations on tokens (printing, predicates).

Jump to

Keyboard shortcuts

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