bibtex

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ATSIGN = 57349
View Source
const BAREIDENT = 57359
View Source
const COLON = 57350
View Source
const COMMA = 57352
View Source
const COMMENT = 57346
View Source
const DQUOTE = 57356
View Source
const EQUAL = 57351
View Source
const IDENT = 57360
View Source
const LBRACE = 57354
View Source
const LPAREN = 57357
View Source
const POUND = 57353
View Source
const PREAMBLE = 57348
View Source
const RBRACE = 57355
View Source
const RPAREN = 57358
View Source
const STRING = 57347

Variables

View Source
var (
	// ErrUnexpectedAtsign is an error for unexpected @ in {}.
	ErrUnexpectedAtsign = errors.New("Unexpected @ sign")
	// ErrUnknownStringVar is an error for looking up undefined string var.
	ErrUnknownStringVar = errors.New("Unknown string variable")
)

Functions

func FullPath

func FullPath(fname string) (string, error)

FullPath returns full path to given bibtex file, looking on standard BIBINPUTS or TEXINPUTS env var paths if not found locally.

Types

type BibComposite

type BibComposite []BibString

BibComposite is a composite string, may contain both variable and string.

func NewBibComposite

func NewBibComposite(s BibString) *BibComposite

NewBibComposite creates a new composite with one element.

func (*BibComposite) Append

func (c *BibComposite) Append(s BibString) *BibComposite

Append adds a BibString to the composite

func (*BibComposite) RawString

func (c *BibComposite) RawString() string

RawString returns a raw (bibtex) representation of the composite string.

func (*BibComposite) String

func (c *BibComposite) String() string

type BibConst

type BibConst string

BibConst is a string constant.

func NewBibConst

func NewBibConst(c string) BibConst

NewBibConst converts a constant string to BibConst.

func (BibConst) RawString

func (c BibConst) RawString() string

RawString is the internal representation of the constant (i.e. the string).

func (BibConst) String

func (c BibConst) String() string

type BibEntry

type BibEntry struct {
	Type     string
	CiteName string
	Fields   map[string]BibString
}

BibEntry is a record of BibTeX record.

func NewBibEntry

func NewBibEntry(entryType string, citeName string) *BibEntry

NewBibEntry creates a new BibTeX entry.

func (*BibEntry) AddField

func (entry *BibEntry) AddField(name string, value BibString)

AddField adds a field (key-value) to a BibTeX entry.

type BibString

type BibString interface {
	RawString() string // Internal representation.
	String() string    // Displayed string.
}

BibString is a segment of a bib string.

type BibTex

type BibTex struct {
	Preambles []BibString          // List of Preambles
	Entries   []*BibEntry          // Items in a bibliography.
	KeyMap    map[string]*BibEntry // fast key lookup map -- made on demand in Lookup
	StringVar map[string]*BibVar   // Map from string variable to string.
}

BibTex is a list of BibTeX entries.

func NewBibTex

func NewBibTex() *BibTex

NewBibTex creates a new BibTex data structure.

func Parse

func Parse(r io.Reader) (*BibTex, error)

Parse is the entry point to the bibtex parser.

func (*BibTex) AddEntry

func (bib *BibTex) AddEntry(entry *BibEntry)

AddEntry adds an entry to the BibTeX data structure.

func (*BibTex) AddPreamble

func (bib *BibTex) AddPreamble(p BibString)

AddPreamble adds a preamble to a bibtex.

func (*BibTex) AddStringVar

func (bib *BibTex) AddStringVar(key string, val BibString)

AddStringVar adds a new string var (if does not exist).

func (*BibTex) GetStringVar

func (bib *BibTex) GetStringVar(key string) *BibVar

GetStringVar looks up a string by its key.

func (*BibTex) Lookup

func (bib *BibTex) Lookup(cite string) (*BibEntry, bool)

Lookup finds CiteName in entries, using fast KeyMap (made on demand) returns nil, false if not found

func (*BibTex) MakeKeyMap

func (bib *BibTex) MakeKeyMap()

MakeKeyMap creates the KeyMap from CiteName to entry

func (*BibTex) PrettyString

func (bib *BibTex) PrettyString() string

PrettyString pretty prints a BibTex.

func (*BibTex) RawString

func (bib *BibTex) RawString() string

RawString returns a BibTex data structure in its internal representation.

func (*BibTex) SortEntries added in v0.3.3

func (bib *BibTex) SortEntries()

SortEntries sorts entries by CiteName.

func (*BibTex) String

func (bib *BibTex) String() string

String returns a BibTex data structure as a simplified BibTex string.

type BibVar

type BibVar struct {
	Key   string    // Variable key.
	Value BibString // Variable actual value.
}

BibVar is a string variable.

func (*BibVar) RawString

func (v *BibVar) RawString() string

RawString is the internal representation of the variable.

func (*BibVar) String

func (v *BibVar) String() string

type ErrParse

type ErrParse struct {
	Pos TokenPos
	Err string // Error string returned from parser.
}

ErrParse is a parse error.

func (*ErrParse) Error

func (e *ErrParse) Error() string

type File

type File struct {

	// file name -- full path
	File string

	// bibtex data loaded from file
	BibTex *BibTex

	// mod time for loaded bibfile -- to detect updates
	Mod time.Time
}

File maintains a record for an bibtex file

func (*File) Open

func (fl *File) Open(fname string) error

Open [re]opens the given filename, looking on standard BIBINPUTS or TEXINPUTS env var paths if not found locally. If Mod >= mod timestamp on the file, and BibTex is already loaded, then nothing happens (already have it), but otherwise it parses the file and puts contents in BibTex field.

type Files

type Files map[string]*File

Files is a map of bibtex files

func (*Files) Open

func (fl *Files) Open(fname string) (*File, error)

Open [re]opens the given filename, looking on standard BIBINPUTS or TEXINPUTS env var paths if not found locally. If Mod >= mod timestamp on the file, and BibTex is already loaded, then nothing happens (already have it), but otherwise it parses the file and puts contents in BibTex field.

type Lexer

type Lexer struct {
	Errors chan error
	// contains filtered or unexported fields
}

Lexer for bibtex.

func NewLexer

func NewLexer(r io.Reader) *Lexer

NewLexer returns a new yacc-compatible lexer.

func (*Lexer) Error

func (l *Lexer) Error(err string)

Error handles error.

func (*Lexer) Lex

func (l *Lexer) Lex(yylval *bibtexSymType) int

Lex is provided for yacc-compatible parser.

type Scanner

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

Scanner is a lexical scanner

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() (tok Token, lit string)

Scan returns the next token and literal value.

type Token

type Token int

Lexer token.

const (
	// ILLEGAL stands for an invalid token.
	ILLEGAL Token = iota
)

type TokenPos

type TokenPos struct {
	Char  int
	Lines []int
}

TokenPos is a pair of coordinate to identify start of token.

func (TokenPos) String

func (p TokenPos) String() string

Jump to

Keyboard shortcuts

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