10std::optional<InMessage>
16 std::vector<std::string> errorMessages;
17 errorMessages.reserve(3);
20 "String '{}' parsed as assignment message: '{}'", line,
asg.getMessage().toString());
21 return asg.getMessage();
23 errorMessages.push_back(
asg.getError());
26 IRSOL_LOG_TRACE(
"String '{}' parsed as inquiry message: {}", line, inq.getMessage().toString());
27 return inq.getMessage();
29 errorMessages.push_back(inq.getError());
32 IRSOL_LOG_TRACE(
"String '{}' parsed as command message: {}", line, cmd.getMessage().toString());
33 return cmd.getMessage();
35 errorMessages.push_back(cmd.getError());
38 std::string fullErrorMessage =
"";
39 for(
const auto& errorMessage : errorMessages) {
40 fullErrorMessage += errorMessage +
"; ";
43 "String '{}' could not be parsed as any known message type. {}", line, fullErrorMessage);
65 static const std::regex re(R
"(^([a-zA-Z]+[a-zA-Z0-9_]*(?:\[\d+\])*)=(.+)$)");
67 std::string errorMessage;
68 if(std::regex_match(line,
m, re)) {
71 }
catch(
const std::invalid_argument& e) {
72 errorMessage = e.what();
75 errorMessage =
"Regex pattern for Assignment did not match";
77 return {std::move(errorMessage)};
97 static const std::regex re(R
"(^([a-zA-Z]+[a-zA-Z0-9_]*(?:\[\d+\])*)\?$)");
99 std::string errorMessage;
100 if(std::regex_match(line,
m, re)) {
103 }
catch(
const std::invalid_argument& e) {
104 errorMessage = e.what();
107 errorMessage =
"Regex pattern for Inquiry did not match";
109 return {std::move(errorMessage)};
126 static const std::regex re(R
"(^([a-zA-Z]+[a-zA-Z0-9_]*)$)");
128 std::string errorMessage;
129 if(std::regex_match(line,
m, re)) {
132 }
catch(
const std::invalid_argument& e) {
133 errorMessage = e.what();
136 errorMessage =
"Regex pattern for Command did not match";
138 return {std::move(errorMessage)};
146 double d = utils::fromString<double>(valStr);
151 valStr.find(
'.') != std::string::npos || valStr.find(
'e') != std::string::npos ||
152 valStr.find(
'E') != std::string::npos) {
157 if(d >= std::numeric_limits<int>::min() && d <= std::numeric_limits<int>::max()) {
158 return static_cast<int>(d);
168 !valStr.empty() && ((valStr.front() ==
'"' && valStr.back() ==
'"') ||
169 (valStr.front() ==
'\'' && valStr.back() ==
'\'') ||
170 (valStr.front() ==
'{' && valStr.back() ==
'}'))) {
171 return valStr.substr(1, valStr.size() - 2);
static internal::ParserResult< Inquiry > parseInquiry(const std::string &line)
Parses an inquiry message from a protocol line.
static irsol::types::protocol_value_t parseValue(const std::string &valueString)
Attempts to parse a raw value string into a typed protocol value.
static std::optional< InMessage > parse(const std::string &line)
Attempts to parse a single protocol input line into a structured InMessage.
static internal::ParserResult< Assignment > parseAssignment(const std::string &line)
Parses an assignment message from a protocol line.
static internal::ParserResult< Command > parseCommand(const std::string &line)
Parses a command message from a protocol line.
Wrapper for the result of a protocol parsing attempt.
#define IRSOL_LOG_WARN(...)
Logs a warning-level message using the default logger.
#define IRSOL_LOG_TRACE(...)
Logs a trace-level message using the default logger.
Logging utilities and configuration for the irsol library.
std::string trim(const std::string &s)
Remove leading and trailing whitespace from a string.
std::variant< int, double, std::string > protocol_value_t
Variant type representing protocol values that can be one of several types.
Parses raw protocol input strings into structured messages.
Utility functions for protocol string handling and validation in the irsol library.
Represents an assignment operation in the protocol.
Represents a command invocation in the protocol.
Represents a value inquiry in the protocol.
irsol::protocol::Assignment m(identifier, value)