btool
A parser/converter/transpiler for .bib files
KeyParserState.cpp
Go to the documentation of this file.
1 #include <KeyParserState.hpp>
2 #include <boost/algorithm/string.hpp>
3 #include <GlobalParserState.hpp>
4 #include <ValueParserState.hpp>
5 #include <string>
6 #include <cctype>
7 
8 using namespace std::literals::string_literals;
9 
15 KeyParserState::KeyParserState(ParserContext &context, std::vector<BibElement> &result) noexcept
16  : AbstractParserState{context, result} {}
17 
25  if (c == '=') {
26  if (key.empty()) {
27  fail("Key must not be empty"s);
28  } else {
29  result.back().attributes.push_back({boost::trim_copy(key), ""});
30  const auto valueState = new ValueParserState{context, result};
31  delete this;
32  return valueState;
33  }
34  } else if (c == '}') {
35  const auto globalState = new GlobalParserState{context, result};
36  delete this;
37  return globalState;
38  } else if (std::isgraph(c) || std::isspace(c)) {
39  key += c;
40  } else {
41  fail("Invalid Character in Key, got so far: ["s + key + "]"s);
42  }
43  return this;
44 }
GlobalParserState.hpp
ParserState
Definition: ParserState.hpp:7
KeyParserState.hpp
ValueParserState.hpp
KeyParserState::KeyParserState
KeyParserState(ParserContext &context, std::vector< BibElement > &result) noexcept
Definition: KeyParserState.cpp:15
AbstractParserState
Definition: AbstractParserState.hpp:13
ParserContext
Definition: ParserContext.hpp:10
KeyParserState::handleCharacter
auto handleCharacter(char c) -> ParserState *override
Definition: KeyParserState.cpp:24
GlobalParserState
Global Parser State.
Definition: GlobalParserState.hpp:14
ValueParserState
Key Parser State.
Definition: ValueParserState.hpp:16