Top Inners Fields Constructors Methods
org.jabref.logic.bst

public Class BstFunctions

extends Object
Class Inheritance
Imports
java.util.Deque, .HashMap, .Map, .Optional, java.util.regex.Matcher, .Pattern, org.jabref.logic.bst.util.BstCaseChanger, .BstNameFormatter, .BstPurifier, .BstTextPrefixer, .BstWidthCalculator, org.jabref.model.database.BibDatabase, org.jabref.model.entry.Author, .AuthorList, com.google.common.annotations.VisibleForTesting, org.antlr.v4.runtime.ParserRuleContext, org.antlr.v4.runtime.tree.ParseTree, org.slf4j.Logger, .LoggerFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
BstFunctions.BstAssignFunction

Pops the top two literals and assigns to the first (which must be a global or entry variable) the value of the second.

public class
BstFunctions.BstCallTypeFunction

Executes the function whose name is the entry type of entry.

public class
BstFunctions.BstCiteFunction

Pushes the string that was the \cite-command argument for this entry.

public static interface
public class
BstFunctions.BstTypeFunction

Pushes the current entry's type (book, article, etc.), but pushes the null string if the type is either unknown or undefined.

Field Summary

Modifier and TypeField and Description
private static final Pattern
private final StringBuilder
private int
private final Map<String, BstFunctions.BstFunction>
private final Map<String, Integer>
private static final Logger
private final String
private final Deque<Object>
private final Map<String, String>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
bstAdd(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (integer) literals and pushes their sum.

private void
bstAddPeriod(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal, adds a `.' to it if the last non '}' character isn't a `.', `?', or `!', and pushes this resulting string.

private void
bstChangeCase(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (string) literals; it changes the case of the second according to the specifications of the first, as follows.

private void
bstChrToInt(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal, makes sure it's a single character, converts it to the corresponding ASCII integer, and pushes this integer.

private void
bstConcat(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (string) literals, concatenates them (in reverse order, that is, the order in which pushed), and pushes the resulting string.

private void
bstDuplicate(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top literal from the stack and pushes two copies of it.

private void
bstEmpty(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top literal and pushes the integer 1 if it's a missing field or a string having no non-white-space characters, 0 otherwise.

private void
bstEquals(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (both integer or both string) literals, compares them, and pushes the integer 1 if they're equal, 0 otherwise.

private void
bstFormatName(BstVMVisitor visitor, ParserRuleContext ctx)

The |built_in| function {\.{format.name\$}} pops the top three literals (they are a string, an integer, and a string literal, in that order).

private void
bstIf(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top three literals (they are two function literals and an integer literal, in that order); if the integer is greater than 0, it executes the second literal, else it executes the first.

private void
bstIntToChr(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (integer) literal, interpreted as the ASCII integer value of a single character, converts it to the corresponding single-character string, and pushes this string.

private void
bstIntToStr(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (integer) literal, converts it to its (unique) string equivalent, and pushes this string.

private void
bstIsGreaterThan(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (integer) literals, compares them, and pushes the integer 1 if the second is greater than the first, 0 otherwise.

private void
bstIsLowerThan(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (integer) literals, compares them, and pushes the integer 1 if the second is lower than the first, 0 otherwise.

private void
bstMissing(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top literal and pushes the integer 1 if it's a missing field, 0 otherwise.

private void
bstNewLine(BstVMVisitor visitor, ParserRuleContext ctx)

Writes onto the bbl file what is accumulated in the output buffer.

private void
bstNumNames(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal and pushes the number of names the string represents one plus the number of occurrences of the substring "and" (ignoring case differences) surrounded by non-null white-space at the top brace level.

private void
bstPop(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top of the stack but doesn't print it; this gets rid of an unwanted stack literal.

private void
bstPreamble(BstVMVisitor visitor, ParserRuleContext ctx)

The |built_in| function {\.{preamble\$}} pushes onto the stack the concatenation of all the \.{preamble} strings read from the database files.

private void
bstPurify(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal, removes nonalphanumeric characters except for white-space characters and hyphens and ties (these all get converted to a space), removes certain alphabetic characters contained in the control sequences associated with a \special character", and pushes the resulting string.

private void
bstQuote(BstVMVisitor visitor, ParserRuleContext ctx)

Pushes the string consisting of the double-quote character.

private void
bstSkip(BstVMVisitor visitor, ParserRuleContext ctx)

Does nothing.

private void
bstStack(BstVMVisitor visitor, ParserRuleContext ctx)

Pops and prints the whole stack; it's meant to be used for style designers while debugging.

pack-priv void
bstSubstring(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top three literals (they are the two integers literals len and start, and a string literal, in that order).

private void
bstSubtract(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (integer) literals and pushes their difference (the first subtracted from the second).

private void
bstSwap(BstVMVisitor visitor, ParserRuleContext ctx)

Swaps the top two literals on the stack.

private void
bstTextLength(BstVMVisitor visitor, ParserRuleContext ctx)

text.length$ Pops the top (string) literal, and pushes the number of text characters it contains, where an accented character (more precisely, a "special character", defined in Section 4) counts as a single text character, even if it's missing its matching right brace, and where braces don't count as text characters.

private void
bstTextPrefix(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two literals (the integer literal len and a string literal, in that order).

private void
bstTop(BstVMVisitor visitor, ParserRuleContext ctx)

Pops and prints the top of the stack to the log file.

private void
bstWarning(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal and prints it following a warning message.

private void
bstWhile(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (function) literals, and keeps executing the second as long as the (integer) literal left on the stack by executing the first is greater than 0.

private void
bstWidth(BstVMVisitor visitor, ParserRuleContext ctx)

The |built_in| function {\.{width\$}} pops the top (string) literal and pushes the integer that represents its width in units specified by the |char_width| array.

private void
bstWrite(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal and writes it on the output buffer (which will result in stuff being written onto the bbl file when the buffer fills up).

private void
protected Map<String, BstFunctions.BstFunction>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ADD_PERIOD_PATTERNback to summary
private static final Pattern ADD_PERIOD_PATTERN
bblback to summary
private final StringBuilder bbl
bstWarningback to summary
private int bstWarning
functionsback to summary
private final Map<String, BstFunctions.BstFunction> functions
integersback to summary
private final Map<String, Integer> integers
LOGGERback to summary
private static final Logger LOGGER
preambleback to summary
private final String preamble
stackback to summary
private final Deque<Object> stack
stringsback to summary
private final Map<String, String> strings

Constructor Detail

BstFunctionsback to summary
public BstFunctions(BstVMContext bstVMContext, StringBuilder bbl)

Method Detail

bstAddback to summary
private void bstAdd(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (integer) literals and pushes their sum.

bstAddPeriodback to summary
private void bstAddPeriod(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal, adds a `.' to it if the last non '}' character isn't a `.', `?', or `!', and pushes this resulting string.

bstChangeCaseback to summary
private void bstChangeCase(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (string) literals; it changes the case of the second according to the specifications of the first, as follows. (Note: The word `letters' in the next sentence refers only to those at brace-level 0, the top-most brace level; no other characters are changed, except perhaps for \special characters", described in Section 4.) If the first literal is the string `t', it converts to lower case all letters except the very first character in the string, which it leaves alone, and except the first character following any colon and then nonnull white space, which it also leaves alone; if it's the string `l', it converts all letters to lower case; and if it's the string `u', it converts all letters to upper case. It then pushes this resulting string. If either type is incorrect, it complains and pushes the null string; however, if both types are correct but the specification string (i.e., the first string) isn't one of the legal ones, it merely pushes the second back onto the stack, after complaining. (Another

Note

It ignores case differences in the specification string; for example, the strings t and T are equivalent for the purposes of this built-in function.)

bstChrToIntback to summary
private void bstChrToInt(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal, makes sure it's a single character, converts it to the corresponding ASCII integer, and pushes this integer.

bstConcatback to summary
private void bstConcat(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (string) literals, concatenates them (in reverse order, that is, the order in which pushed), and pushes the resulting string.

bstDuplicateback to summary
private void bstDuplicate(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top literal from the stack and pushes two copies of it.

bstEmptyback to summary
private void bstEmpty(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top literal and pushes the integer 1 if it's a missing field or a string having no non-white-space characters, 0 otherwise.

bstEqualsback to summary
private void bstEquals(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (both integer or both string) literals, compares them, and pushes the integer 1 if they're equal, 0 otherwise.

bstFormatNameback to summary
private void bstFormatName(BstVMVisitor visitor, ParserRuleContext ctx)

The |built_in| function {\.{format.name\$}} pops the top three literals (they are a string, an integer, and a string literal, in that order). The last string literal represents a name list (each name corresponding to a person), the integer literal specifies which name to pick from this list, and the first string literal specifies how to format this name, as described in the \BibTeX\ documentation. Finally, this function pushes the formatted name. If any of the types is incorrect, it complains and pushes the null string.

bstIfback to summary
private void bstIf(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top three literals (they are two function literals and an integer literal, in that order); if the integer is greater than 0, it executes the second literal, else it executes the first.

bstIntToChrback to summary
private void bstIntToChr(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (integer) literal, interpreted as the ASCII integer value of a single character, converts it to the corresponding single-character string, and pushes this string.

bstIntToStrback to summary
private void bstIntToStr(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (integer) literal, converts it to its (unique) string equivalent, and pushes this string.

bstIsGreaterThanback to summary
private void bstIsGreaterThan(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (integer) literals, compares them, and pushes the integer 1 if the second is greater than the first, 0 otherwise.

bstIsLowerThanback to summary
private void bstIsLowerThan(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (integer) literals, compares them, and pushes the integer 1 if the second is lower than the first, 0 otherwise.

bstMissingback to summary
private void bstMissing(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top literal and pushes the integer 1 if it's a missing field, 0 otherwise.

bstNewLineback to summary
private void bstNewLine(BstVMVisitor visitor, ParserRuleContext ctx)

Writes onto the bbl file what is accumulated in the output buffer. It writes a blank line if and only if the output buffer is empty. Since write$ does reasonable line breaking, you should use this function only when you want a blank line or an explicit line break.

bstNumNamesback to summary
private void bstNumNames(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal and pushes the number of names the string represents one plus the number of occurrences of the substring "and" (ignoring case differences) surrounded by non-null white-space at the top brace level.

bstPopback to summary
private void bstPop(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top of the stack but doesn't print it; this gets rid of an unwanted stack literal.

bstPreambleback to summary
private void bstPreamble(BstVMVisitor visitor, ParserRuleContext ctx)

The |built_in| function {\.{preamble\$}} pushes onto the stack the concatenation of all the \.{preamble} strings read from the database files. (or the empty string if there were none) '@PREAMBLE' strings are read from the database files.

bstPurifyback to summary
private void bstPurify(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal, removes nonalphanumeric characters except for white-space characters and hyphens and ties (these all get converted to a space), removes certain alphabetic characters contained in the control sequences associated with a \special character", and pushes the resulting string.

bstQuoteback to summary
private void bstQuote(BstVMVisitor visitor, ParserRuleContext ctx)

Pushes the string consisting of the double-quote character.

bstSkipback to summary
private void bstSkip(BstVMVisitor visitor, ParserRuleContext ctx)

Does nothing.

bstStackback to summary
private void bstStack(BstVMVisitor visitor, ParserRuleContext ctx)

Pops and prints the whole stack; it's meant to be used for style designers while debugging.

bstSubstringback to summary
pack-priv void bstSubstring(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top three literals (they are the two integers literals len and start, and a string literal, in that order). It pushes the substring of the (at most) len consecutive characters starting at the start-th character (assuming 1-based indexing) if start is positive, and ending at the start-th character (including) from the end if start is negative (where the first character from the end is the last character).

Annotations
@VisibleForTesting
bstSubtractback to summary
private void bstSubtract(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (integer) literals and pushes their difference (the first subtracted from the second).

bstSwapback to summary
private void bstSwap(BstVMVisitor visitor, ParserRuleContext ctx)

Swaps the top two literals on the stack. text.length$ Pops the top (string) literal, and pushes the number of text characters it contains, where an accented character (more precisely, a \special character", defined in Section 4) counts as a single text character, even if it's missing its matching right brace, and where braces don't count as text characters.

bstTextLengthback to summary
private void bstTextLength(BstVMVisitor visitor, ParserRuleContext ctx)

text.length$ Pops the top (string) literal, and pushes the number of text characters it contains, where an accented character (more precisely, a "special character", defined in Section 4) counts as a single text character, even if it's missing its matching right brace, and where braces don't count as text characters.

From BibTeXing: For the purposes of counting letters in labels, BibTEX considers everything contained inside the braces as a single letter.

bstTextPrefixback to summary
private void bstTextPrefix(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two literals (the integer literal len and a string literal, in that order). It pushes the substring of the (at most) len consecutive text characters starting from the beginning of the string. This function is similar to substring$, but this one considers a \special character", even if it's missing its matching right brace, to be a single text character (rather than however many ASCII characters it actually comprises), and this function doesn't consider braces to be text characters; furthermore, this function appends any needed matching right braces.

bstTopback to summary
private void bstTop(BstVMVisitor visitor, ParserRuleContext ctx)

Pops and prints the top of the stack to the log file. It's useful for debugging.

bstWarningback to summary
private void bstWarning(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal and prints it following a warning message. This also increments a count of the number of warning messages issued.

bstWhileback to summary
private void bstWhile(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top two (function) literals, and keeps executing the second as long as the (integer) literal left on the stack by executing the first is greater than 0.

bstWidthback to summary
private void bstWidth(BstVMVisitor visitor, ParserRuleContext ctx)

The |built_in| function {\.{width\$}} pops the top (string) literal and pushes the integer that represents its width in units specified by the |char_width| array. This function takes the literal literally; that is, it assumes each character in the string is to be printed as is, regardless of whether the character has a special meaning to \TeX, except that special characters (even without their |right_brace|s) are handled specially. If the literal isn't a string, it complains and pushes~0.

bstWriteback to summary
private void bstWrite(BstVMVisitor visitor, ParserRuleContext ctx)

Pops the top (string) literal and writes it on the output buffer (which will result in stuff being written onto the bbl file when the buffer fills up).

callIdentifierOrTreeback to summary
private void callIdentifierOrTree(Object f, BstVMVisitor visitor, ParserRuleContext ctx)
getBuiltInFunctionsback to summary
protected Map<String, BstFunctions.BstFunction> getBuiltInFunctions()
org.jabref.logic.bst back to summary

public Class BstFunctions.BstAssignFunction

extends Object
implements BstFunction
Class Inheritance
All Implemented Interfaces
org.jabref.logic.bst.BstFunctions.BstFunction

Pops the top two literals and assigns to the first (which must be a global or entry variable) the value of the second.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BstAssignFunctionback to summary
public BstAssignFunction()

Method Detail

executeback to summary
public void execute(BstVMVisitor visitor, ParserRuleContext ctx)

Implements org.jabref.logic.bst.BstFunctions.BstFunction.execute.

Annotations
@Override
executeback to summary
public void execute(BstVMVisitor visitor, ParserRuleContext ctx, BstEntry bstEntry)

Overrides default org.jabref.logic.bst.BstFunctions.BstFunction.execute.

Annotations
@Override
org.jabref.logic.bst back to summary

public Class BstFunctions.BstCallTypeFunction

extends Object
implements BstFunction
Class Inheritance
All Implemented Interfaces
org.jabref.logic.bst.BstFunctions.BstFunction

Executes the function whose name is the entry type of entry. For example if an entry is of type book, this function executes the book function. When given as an argument to the ITERATE command, call.type$ actually produces the output for the entries. For an entry with an unknown type, it executes the function default.type. Thus, you should define (before the READ command) one function for each standard entry type as well as a default.type function.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BstCallTypeFunctionback to summary
public BstCallTypeFunction()

Method Detail

executeback to summary
public void execute(BstVMVisitor visitor, ParserRuleContext ctx)

Implements org.jabref.logic.bst.BstFunctions.BstFunction.execute.

Annotations
@Override
executeback to summary
public void execute(BstVMVisitor visitor, ParserRuleContext ctx, BstEntry bstEntry)

Overrides default org.jabref.logic.bst.BstFunctions.BstFunction.execute.

Annotations
@Override
org.jabref.logic.bst back to summary

public Class BstFunctions.BstCiteFunction

extends Object
implements BstFunction
Class Inheritance
All Implemented Interfaces
org.jabref.logic.bst.BstFunctions.BstFunction

Pushes the string that was the \cite-command argument for this entry.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BstCiteFunctionback to summary
public BstCiteFunction()

Method Detail

executeback to summary
public void execute(BstVMVisitor visitor, ParserRuleContext ctx)

Implements org.jabref.logic.bst.BstFunctions.BstFunction.execute.

Annotations
@Override
executeback to summary
public void execute(BstVMVisitor visitor, ParserRuleContext ctx, BstEntry bstEntryContext)

Overrides default org.jabref.logic.bst.BstFunctions.BstFunction.execute.

Annotations
@Override
org.jabref.logic.bst back to summary

public Interface BstFunctions.BstFunction

Known Direct Implementers
org.jabref.logic.bst.BstFunctions.BstAssignFunction, org.jabref.logic.bst.BstFunctions.BstCallTypeFunction, org.jabref.logic.bst.BstFunctions.BstCiteFunction, org.jabref.logic.bst.BstFunctions.BstTypeFunction
Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public void
public default void
execute(BstVMVisitor visitor, ParserRuleContext ctx, BstEntry bstEntryContext)

Method Detail

executeback to summary
public void execute(BstVMVisitor visitor, ParserRuleContext ctx)
executeback to summary
public default void execute(BstVMVisitor visitor, ParserRuleContext ctx, BstEntry bstEntryContext)
org.jabref.logic.bst back to summary

public Class BstFunctions.BstTypeFunction

extends Object
implements BstFunction
Class Inheritance
All Implemented Interfaces
org.jabref.logic.bst.BstFunctions.BstFunction

Pushes the current entry's type (book, article, etc.), but pushes the null string if the type is either unknown or undefined.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BstTypeFunctionback to summary
public BstTypeFunction()

Method Detail

executeback to summary
public void execute(BstVMVisitor visitor, ParserRuleContext ctx)

Implements org.jabref.logic.bst.BstFunctions.BstFunction.execute.

Annotations
@Override
executeback to summary
public void execute(BstVMVisitor visitor, ParserRuleContext ctx, BstEntry bstEntryContext)

Overrides default org.jabref.logic.bst.BstFunctions.BstFunction.execute.

Annotations
@Override