18#ifndef SIMPLE_PARSER_HPP_
19#define SIMPLE_PARSER_HPP_
55 if (
match(
"&description",
true)) {
61 if (
match(
"¶meter",
true)) {
63 }
else if (
match(
"&column",
true)) {
65 }
else if (
match(
"&associate",
true)) {
67 }
else if (
match(
"&array",
true)) {
69 }
else if (
match(
"&include",
true)) {
71 }
else if (
match(
"&data",
true)) {
95 bool match(std::string_view str,
bool ignoreCase =
false) {
103 if (std::char_traits<char>::compare(
data, str.data(), str.size()) == 0) {
108 for (std::size_t i = 0; i < str.size(); ++i) {
109 if (std::tolower(
static_cast<unsigned char>(
data[i]))
110 != std::tolower(
static_cast<unsigned char>(str[i]))) {
131 if (!
match(str,
true)) {
132 throw std::runtime_error(
"Expected: " + std::string(str));
138 throw std::runtime_error(std::string(
"Expected: ") + c);
165 std::size_t start =
pos_;
168 if (std::isalnum(
static_cast<unsigned char>(c)) ||
169 c ==
'@' || c ==
'#' || c ==
':' || c ==
'+' ||
170 c ==
'-' || c ==
'%' || c ==
'.' || c ==
'_' ||
171 c ==
'$' || c ==
'&' || c ==
'/') {
177 return std::string(
input_.substr(start,
pos_ - start));
194 && std::isdigit(
static_cast<unsigned char>(
input_[
pos_]))) {
198 if (numStr.empty()) {
199 throw std::runtime_error(
"Expected version number");
209 if (
match(
"&end",
true)) {
211 }
else if (
match(
"name",
true)) {
214 }
else if (
match(
"text",
true)) {
217 }
else if (
match(
"contents",
true)) {
225 if (
match(
','))
continue;
236 if (
match(
"&end",
true)) {
238 }
else if (
match(
"name",
true)) {
241 }
else if (
match(
"type",
true)) {
246 throw std::runtime_error(
"Unknown parameter type: " + typeStr);
249 }
else if (
match(
"units",
true)) {
252 }
else if (
match(
"description",
true)) {
260 if (
match(
','))
continue;
266 throw std::runtime_error(
"Parameter declaration missing mandatory attributes");
276 if (
match(
"&end",
true)) {
278 }
else if (
match(
"name",
true)) {
281 }
else if (
match(
"type",
true)) {
286 throw std::runtime_error(
"Unknown column type: " + typeStr);
289 }
else if (
match(
"units",
true)) {
292 }
else if (
match(
"description",
true)) {
300 if (
match(
','))
continue;
305 throw std::runtime_error(
"Column declaration missing mandatory attributes");
315 if (
match(
"&end",
true))
break;
317 if (
match(
','))
continue;
327 if (
match(
"&end",
true))
break;
329 if (
match(
','))
continue;
339 if (
match(
"&end",
true))
break;
341 if (
match(
','))
continue;
350 bool modeSet =
false;
352 if (
match(
"&end",
true)) {
358 throw std::runtime_error(
"Malformed &data entry");
371 throw std::runtime_error(
"Unknown data mode: " + modeStr);
384 throw std::runtime_error(
"Missing mode attribute in &data");
constexpr std::optional< dataType > parseDataType(std::string_view typeName)
constexpr bool equalsIgnoreCase(std::string_view lhs, std::string_view rhs)
void skipWhitespaceAndComments(std::string_view input, std::size_t &pos)
std::optional< std::string > name_m
std::optional< ast::dataType > type_m
bool checkMandatories() const
std::optional< std::string > units_m
std::optional< std::string > description_m
std::optional< std::string > content_m
std::optional< std::string > text_m
std::optional< description > sddsDescription_m
includeList sddsIncludes_m
parameterList sddsParameters_m
associateList sddsAssociates_m
std::optional< std::string > name_m
std::optional< std::string > description_m
std::optional< std::string > units_m
std::optional< ast::dataType > type_m
bool checkMandatories() const
std::size_t dataStartPos() const
std::size_t dataStartPos_
std::string parseString()
SimpleParser(std::string_view input)
associate parseAssociate()
description parseDescription()
void expect(std::string_view str)
bool match(std::string_view str, bool ignoreCase=false)
parameter parseParameter()
std::string parseIdentifier()
std::string parseQuotedString()