Documentation ¶
Overview ¶
Package ast declares the types used to represent syntax trees for bibtex files.
Index ¶
- func Walk(n Node, w Walker) error
- type AbbrevDecl
- type Author
- type Authors
- type BadDecl
- type BadExpr
- type BadStmt
- type BibDecl
- type ConcatExpr
- type Decl
- type Expr
- type File
- type Ident
- type Node
- type NodeKind
- type Number
- type ObjKind
- type Object
- type Package
- type ParsedText
- type PreambleDecl
- type Scope
- type SimplifyTagTransformer
- type Stmt
- type TagStmt
- type TexComment
- type TexCommentGroup
- type Text
- type TextComma
- type TextDelimiter
- type TextEscaped
- type TextHyphen
- type TextMacro
- type TextMath
- type TextNBSP
- type TextSpace
- type Transformer
- type UnparsedText
- type WalkStatus
- type Walker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AbbrevDecl ¶
type AbbrevDecl struct { Doc *TexCommentGroup // associated documentation; or nil Entry gotok.Pos // position of the "@STRING" token Tag *TagStmt RBrace gotok.Pos // position of the closing right brace token: "}". }
An AbbrevDecl node represents a bibtex abbreviation, like:
@STRING { foo = "bar" }
func (*AbbrevDecl) End ¶
func (e *AbbrevDecl) End() gotok.Pos
func (*AbbrevDecl) Kind ¶
func (e *AbbrevDecl) Kind() NodeKind
func (*AbbrevDecl) Pos ¶
func (e *AbbrevDecl) Pos() gotok.Pos
type Author ¶
type Author struct {
From, To gotok.Pos
First Expr // given name
Prefix Expr // often called the 'von' part
Last Expr // family name
Suffix Expr // often called the 'jr' part
}
An Author node represents a single bibtex author.
type Authors ¶
type Authors []*Author
An Authors node represents a list of authors, typically in the author or editor fields of a bibtex declaration.
type BadDecl ¶
A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.
type BadExpr ¶
A BadExpr node is a placeholder for expressions containing syntax errors for which no correct expression nodes can be created.
type BadStmt ¶
A BadStmt node is a placeholder for statements containing syntax errors for which no correct statement nodes can be created.
type BibDecl ¶
type BibDecl struct { Type string // type of entry, e.g. "article" Doc *TexCommentGroup // associated documentation; or nil Entry gotok.Pos // position of the start token, e.g. "@article" Key *Ident // the first key in the declaration ExtraKeys []*Ident // any other keys in the declaration, usually nil Tags []*TagStmt // all tags in the declaration RBrace gotok.Pos // position of the closing right brace token: "}". }
An BibDecl node represents a bibtex entry, like:
@article { author = "bar" }
type ConcatExpr ¶
A ConcatExpr node represents a bibtex concatenation like:
"foo" # "bar"
func (*ConcatExpr) End ¶
func (x *ConcatExpr) End() gotok.Pos
func (*ConcatExpr) Kind ¶
func (x *ConcatExpr) Kind() NodeKind
func (*ConcatExpr) Pos ¶
func (x *ConcatExpr) Pos() gotok.Pos
type Decl ¶
type Decl interface { Node // contains filtered or unexported methods }
All declaration nodes implement the Decl interface, like the @article, @STRING, @COMMENT, and @PREAMBLE entries.
type Expr ¶
type Expr interface { Node // contains filtered or unexported methods }
All expression nodes implement the Expr interface.
type File ¶
type File struct { Name string Doc *TexCommentGroup // associated documentation; or nil Entries []Decl // top-level entries; or nil Scope *Scope // package scope (this file only) Unresolved []*Ident // unresolved identifiers in this file Comments []*TexCommentGroup // list of all comments in the source file }
A File node represents a bibtex source file.
The Comments list contains all comments in the source file in order of appearance, including the comments that are pointed to from other nodes via Doc and Comment fields.
For correct printing of source code containing comments (using packages go/format and go/printer), special care must be taken to update comments when a File's syntax tree is modified: For printing, comments are interspersed between tokens based on their position. If syntax tree nodes are removed or moved, relevant comments in their vicinity must also be removed (from the File.Comments list) or moved accordingly (by updating their positions). A CommentMap may be used to facilitate some of these operations.
Whether and how a comment is associated with a node depends on the interpretation of the syntax tree by the manipulating program: Except for Doc and Comment comments directly associated with nodes, the remaining comments are "free-floating".
type Ident ¶
type Ident struct { NamePos gotok.Pos // identifier position Name string // identifier name Obj *Object // denoted object; or nil }
An Ident node represents an identifier like a bibtex citation key or tag key.
type NodeKind ¶
type NodeKind int
const ( KindTexComment NodeKind = iota KindTexCommentGroup KindBadExpr KindIdent KindNumber KindAuthors KindAuthor KindUnparsedText KindParsedText KindText KindTextComma KindTextEscaped KindTextHyphen KindTextMath KindTextNBSP KindTextSpace KindTextMacro KindConcatExpr KindBadStmt KindTagStmt KindBadDecl KindAbbrevDecl KindBibDecl KindPreambleDecl KindFile KindPackage )
type ObjKind ¶
type ObjKind int
ObjKind describes what an object represents.
type Object ¶
type Object struct { Kind ObjKind Name string // declared name Decl interface{} // corresponding BibDecl, AbbrevDecl, or nil }
An Object describes a named language entity such as a bibtex entry, or string abbreviation.
The Data fields contains object-specific data:
Kind Data type Data value Pkg *Scope package scope Con int iota for the respective declaration
type Package ¶
type Package struct { Scope *Scope // package scope across all files Objects map[string]*Object // map of package id -> package object Files map[string]*File // Bibtex source files by filename }
A Package node represents a set of source files collectively representing a single, unified bibliography.
type ParsedText ¶
type ParsedText struct { Opener gotok.Pos // opening delimiter Depth int // the brace depth Delim TextDelimiter Values []Expr // Text, ParsedText, or any of the Text* types Closer gotok.Pos // closing delimiter }
A ParsedText node represents a parsed bibtex string.
func (*ParsedText) End ¶
func (x *ParsedText) End() gotok.Pos
func (*ParsedText) Kind ¶
func (x *ParsedText) Kind() NodeKind
func (*ParsedText) Pos ¶
func (x *ParsedText) Pos() gotok.Pos
type PreambleDecl ¶
type PreambleDecl struct { Doc *TexCommentGroup // associated documentation; or nil Entry gotok.Pos // position of the "@PREAMBLE" token Text Expr // The content of the preamble node RBrace gotok.Pos // position of the closing right brace token: "}" }
An PreambleDecl node represents a bibtex preamble, like:
@PREAMBLE { "foo" }
func (*PreambleDecl) End ¶
func (e *PreambleDecl) End() gotok.Pos
func (*PreambleDecl) Kind ¶
func (e *PreambleDecl) Kind() NodeKind
func (*PreambleDecl) Pos ¶
func (e *PreambleDecl) Pos() gotok.Pos
type Scope ¶
A Scope maintains the set of named language entities declared in the scope and a link to the immediately surrounding (outer) scope.
func (*Scope) Insert ¶
Insert attempts to insert a named object obj into the scope s. If the scope already contains an object alt with the same name, Insert leaves the scope unchanged and returns alt. Otherwise it inserts obj and returns nil.
type SimplifyTagTransformer ¶
type SimplifyTagTransformer struct{}
func (SimplifyTagTransformer) Transform ¶
func (s SimplifyTagTransformer) Transform(node Node) error
type Stmt ¶
type Stmt interface { Node // contains filtered or unexported methods }
All statement nodes implement the Stmt interface, like bibtex entry tags.
type TagStmt ¶
type TagStmt struct { Doc *TexCommentGroup // associated documentation; or nil NamePos gotok.Pos // identifier position Name string // identifier name, normalized with lowercase RawName string // identifier name as it appeared in source Value Expr // denoted expression }
An TagStmt node represents a tag in an BibDecl or AbbrevDecl, i.e. author = "foo".
type TexComment ¶
type TexComment struct { Start gotok.Pos // position of the '%' starting the comment Text string // comment text excluding '\n' }
A TexComment node represents a single %-style comment.
func (*TexComment) End ¶
func (c *TexComment) End() gotok.Pos
func (*TexComment) Kind ¶
func (c *TexComment) Kind() NodeKind
func (*TexComment) Pos ¶
func (c *TexComment) Pos() gotok.Pos
type TexCommentGroup ¶
type TexCommentGroup struct {
List []*TexComment // len(List) > 0
}
A TexCommentGroup represents a sequence of comments with no other tokens and no empty lines between.
func (*TexCommentGroup) End ¶
func (g *TexCommentGroup) End() gotok.Pos
func (*TexCommentGroup) Kind ¶
func (g *TexCommentGroup) Kind() NodeKind
func (*TexCommentGroup) Pos ¶
func (g *TexCommentGroup) Pos() gotok.Pos
type Text ¶
A Text node is a string of simple text.
func SimplifyParsedText ¶
func SimplifyParsedText(txt *ParsedText) *Text
type TextComma ¶
A TextComma node is a string of exactly 1 comma. Useful because a comma has semantic meaning for parsing authors as a separator for names.
type TextDelimiter ¶
type TextDelimiter int
const ( QuoteDelimiter TextDelimiter = iota BraceDelimiter )
func (TextDelimiter) String ¶
func (t TextDelimiter) String() string
type TextEscaped ¶
type TextEscaped struct { ValuePos gotok.Pos // literal position Value string // the escaped char without the backslash }
A TextEscaped node is a string of exactly 1 escaped character. The only escapable characters are:
'\\', '$', '&', '%', '{', '}'
In all other cases, a backslash is interpreted as the start of a TeX macro.
func (*TextEscaped) End ¶
func (x *TextEscaped) End() gotok.Pos
func (*TextEscaped) Kind ¶
func (x *TextEscaped) Kind() NodeKind
func (*TextEscaped) Pos ¶
func (x *TextEscaped) Pos() gotok.Pos
type TextHyphen ¶
A TextHyphen node is a string of exactly 1 hyphen (-). Hyphens are important in some cases of parsing author names so keep it as a separate node.
func (*TextHyphen) End ¶
func (x *TextHyphen) End() gotok.Pos
func (*TextHyphen) Kind ¶
func (x *TextHyphen) Kind() NodeKind
func (*TextHyphen) Pos ¶
func (x *TextHyphen) Pos() gotok.Pos
type TextMacro ¶
type TextMacro struct { Cmd gotok.Pos // command position Name string // command name without backslash, i.e. 'url' Values []Expr // parameters: Text, ParsedText, or TextMacro RBrace gotok.Pos // position of the closing }, if any }
A TextMacro node represents a piece of ParsedText that's a latex macro invocation.
type TextMath ¶
type TextMath struct { ValuePos gotok.Pos // literal position Value string // the text in-between the $...$, not including the $'s. }
A TextMath node is the string delimited by dollar signs, representing Math in TeX.
type TextSpace ¶
A TextSpace node is any consecutive whitespace '\n', '\r', '\t', ' ' in a bibtex string.
type Transformer ¶
type UnparsedText ¶
type UnparsedText struct { ValuePos gotok.Pos // literal position Type token.Token // token.String or token.BraceString Value string // excluding delimiters }
An UnparsedText is a bibtex string as it appears in source. Only appears when Mode.ParseStrings == 0 is passed to ParseFile.
func (*UnparsedText) End ¶
func (x *UnparsedText) End() gotok.Pos
func (*UnparsedText) Kind ¶
func (x *UnparsedText) Kind() NodeKind
func (*UnparsedText) Pos ¶
func (x *UnparsedText) Pos() gotok.Pos
type WalkStatus ¶
type WalkStatus int
const ( WalkStop WalkStatus = iota // stop walking immediately WalkContinue // continue walking WalkSkipChildren // continue walking )