btool
A parser/converter/transpiler for .bib files
Parser Class Reference

interface to interact with bib-files More...

#include <Parser.hpp>

+ Collaboration diagram for Parser:

Public Member Functions

 Parser (const std::optional< boost::filesystem::path > &ruleFilePath, std::vector< std::string > targetStyles, const bool allowAll=false)
 
 Parser (std::optional< std::stringstream > ruleFileContents, std::vector< std::string > targetStyle, const bool allowAll=false)
 
auto generate (const std::vector< boost::filesystem::path > &inputPaths, const std::optional< std::string > &sorting) const -> std::vector< BibElement >
 
auto generate (const boost::filesystem::path &inputPath, const std::optional< std::string > &sorting) const -> std::vector< BibElement >
 
auto generate (std::string_view inputFileContent, const std::optional< std::string > &sorting, const std::string &filename) const -> std::vector< BibElement >
 

Static Private Member Functions

static auto elementsOf (std::string_view input, const std::string &filename) -> std::vector< BibElement >
 
static auto sortElements (std::vector< BibElement > &elements, const std::string &sorting) noexcept -> void
 
static auto filterElements (const std::vector< BibElement > &elements, const std::vector< StyleProperties > &props) noexcept -> std::vector< BibElement >
 

Private Attributes

std::vector< std::string > targetStyles
 the target-styles of the generated files More...
 
TranslationTable translationTable
 translation-Table handler More...
 
bool allowAll
 flag that allows all styles and fields to get parsed (set when missing translationTable) More...
 

Detailed Description

interface to interact with bib-files

Handles interaction with the bib-files and does parsing of it

Examples
/github/workspace/test/ParserFixtureTest.cpp.

Definition at line 17 of file Parser.hpp.

Constructor & Destructor Documentation

◆ Parser() [1/2]

Parser::Parser ( const std::optional< boost::filesystem::path > &  ruleFilePath,
std::vector< std::string >  targetStyles,
const bool  allowAll = false 
)

Constructor.

Parameters
ruleFilePathoptional filepath to the translation-table
targetStylethe style name to filter parse-results for
allowAllflag to allow every element to get parsed (ignore TranslationTable)
Exceptions
boost::property_tree::json_parser_errorwhenever translationTable is not JSON compliant
std::invalid_argumentwhenever translationTable is no regular file or does not exist

Definition at line 18 of file Parser.cpp.

References allowAll.

◆ Parser() [2/2]

Parser::Parser ( std::optional< std::stringstream >  ruleFileContents,
std::vector< std::string >  targetStyles,
const bool  allowAll = false 
)

Constructor.

Parameters
ruleFileContentsoptional contents of the translation-table
targetStylethe style name to filter parse-results for
allowAllflag to allow every element to get parsed (ignore TranslationTable)
Exceptions
boost::property_tree::json_parser_errorwhenever translationTable is not JSON compliant

Definition at line 33 of file Parser.cpp.

References allowAll.

Member Function Documentation

◆ elementsOf()

auto Parser::elementsOf ( std::string_view  input,
const std::string &  filename 
) -> std::vector<BibElement>
staticprivate

Parse Bib-Elements from a source-file

Parameters
inputthe contents of the source-file
filenamename or path of the parsed file (for logging errors)
Returns
collection of parsed bib-elements
Exceptions
std::runtime_errorif parsing failed

Definition at line 113 of file Parser.cpp.

References ParserContext::column, ParserState::handleCharacter(), ParserContext::line, ParserException::state, and ParserException::what().

Referenced by generate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ filterElements()

auto Parser::filterElements ( const std::vector< BibElement > &  elements,
const std::vector< StyleProperties > &  props 
) -> std::vector<BibElement>
staticprivatenoexcept

Filters list of elements for only elements that are compliant to one of a list of properties

Parameters
elementsthe list of elements to filter
propsthe list of properties to filter for
Returns
the filtered list of elements

Definition at line 187 of file Parser.cpp.

References BibElement::isCompliantTo().

+ Here is the call graph for this function:

◆ generate() [1/3]

auto Parser::generate ( const boost::filesystem::path &  inputPath,
const std::optional< std::string > &  sorting 
) const -> std::vector<BibElement>

Generate bib-elements and Filter them for a Style

Parameters
inputPathfilepath to a directory of bib-Files or a single bib-File
sortingthe style name to sort parsing-results for
Returns
collection of parsed bib-elements
Exceptions
std::runtime_erroron parsing error
std::illegal_argumentif file is invalid

Definition at line 49 of file Parser.cpp.

◆ generate() [2/3]

auto Parser::generate ( const std::vector< boost::filesystem::path > &  inputPaths,
const std::optional< std::string > &  sorting 
) const -> std::vector<BibElement>

Generates Elements of multiple input-files

Parameters
inputPathsall theinput-paths
sortingoptional sorting to use
Returns
optionally sorted elements
Exceptions
std::runtime_erroron parsing-error
std::invalid_argumentif a file is invalid
Examples
/github/workspace/test/ParserFixtureTest.cpp.

Definition at line 164 of file Parser.cpp.

Referenced by main(), and TEST_F().

+ Here is the caller graph for this function:

◆ generate() [3/3]

auto Parser::generate ( std::string_view  inputFileContent,
const std::optional< std::string > &  sorting,
const std::string &  filename 
) const -> std::vector<BibElement>

Generate bib-elements and Filter them for a Style

Parameters
inputFileContentcontent of a input-file
sortingthe style name to sort parsing-results for
filenamename or path of the parsed file (for logging errors)
Returns
collection of parsed, sorted and filtered bib-elements
Exceptions
std::runtime_erroron parsing error

Definition at line 87 of file Parser.cpp.

References elementsOf().

+ Here is the call graph for this function:

◆ sortElements()

auto Parser::sortElements ( std::vector< BibElement > &  elements,
const std::string &  sorting 
) -> void
staticprivatenoexcept

Sorts a vector of bibElements

Parameters
elements[out]the vector of bibElements
sortingthe attribute to sort for

Definition at line 145 of file Parser.cpp.

References BibElement::findAttribute(), and Field::value.

+ Here is the call graph for this function:

Member Data Documentation

◆ allowAll

bool Parser::allowAll
private

flag that allows all styles and fields to get parsed (set when missing translationTable)

Definition at line 21 of file Parser.hpp.

Referenced by Parser().

◆ targetStyles

std::vector<std::string> Parser::targetStyles
private

the target-styles of the generated files

Definition at line 19 of file Parser.hpp.

◆ translationTable

TranslationTable Parser::translationTable
private

translation-Table handler

Definition at line 20 of file Parser.hpp.


The documentation for this class was generated from the following files: