bibtex

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: Apache-2.0 Imports: 10 Imported by: 16

README

bibtex Build Status GoDoc

nickng/bibtex is a bibtex parser and library for Go.

The bibtex format is not standardised, this parser follows the descriptions found here. Please file any issues with a minimal working example.

To get:

go get -u github.com/nickng/bibtex/...

This will also install prettybib, a bibtex pretty printer. To parse and pretty print a bibtex file, for example:

cd $GOPATH/src/github.com/nickng/bibtex
prettybib -in example/simple.bib

Documentation

Overview

Package bibtex is a bibtex parser written in Go.

The package contains a simple parser and data structure to represent bibtex records.

Supported syntax

The basic syntax is:

@BIBTYPE{IDENT,
    key1 = word,
    key2 = "quoted",
    key3 = {quoted},
}

where BIBTYPE is the type of document (e.g. inproceedings, article, etc.) and IDENT is a string identifier.

The bibtex format is not standardised, this parser follows the descriptions found in the link below. If there are any problems, please file any issues with a minimal working example at the GitHub repository. http://maverick.inria.fr/~Xavier.Decoret/resources/xdkbibtex/bibtex_summary.html

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

This section is empty.

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.
	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) 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) 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 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

Directories

Path Synopsis
cmd
prettybib
Command prettybib pretty prints a bib entry from command line.
Command prettybib pretty prints a bib entry from command line.

Jump to

Keyboard shortcuts

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