Skip to content

Commit 21388d4

Browse files
fix: apply Copilot review suggestions
- README.md: clarify MATLAB/Verilog only support flat numeric arrays - concore_base.hpp: add #include <stdexcept> and <cctype> for portability - concore_base.hpp: fix keyword boundary checks to also exclude underscore - concore.hpp: add Doxygen docs for parse_literal and flatten_numeric
1 parent 6170087 commit 21388d4

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _concore_ enables composing studies from programs developed in different languag
2323

2424
## Wire Format
2525

26-
Concore payloads follow Python literal syntax compatible with `ast.literal_eval()`. All language implementations (Python, C++, Java, MATLAB) parse this shared format. Supported value types include:
26+
Concore payloads follow Python literal syntax compatible with `ast.literal_eval()`. The Python, C++, and Java implementations parse this shared format; the MATLAB and Verilog implementations currently support only flat numeric arrays derived from it. Supported value types include:
2727

2828
* **Numbers** — integers and floats, including scientific notation (e.g., `1e3`, `-2.5`)
2929
* **Booleans**`True` / `False` (converted to `1.0` / `0.0` in numeric contexts)

concore.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,20 @@ class Concore{
256256
return concore_base::parselist_double(f);
257257
}
258258

259+
/**
260+
* @brief Parses a literal string into a ConcoreValue representation.
261+
* @param f The input string to parse.
262+
* @return A ConcoreValue obtained by parsing the input string.
263+
*/
259264
concore_base::ConcoreValue parse_literal(string f){
260265
return concore_base::parse_literal(f);
261266
}
262267

268+
/**
269+
* @brief Flattens a ConcoreValue into a vector of numeric (double) values.
270+
* @param v The ConcoreValue to flatten.
271+
* @return A vector of double values obtained by flattening the input.
272+
*/
263273
vector<double> flatten_numeric(const concore_base::ConcoreValue& v){
264274
return concore_base::flatten_numeric(v);
265275
}

concore_base.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <regex>
1515
#include <algorithm>
1616
#include <cstring>
17+
#include <stdexcept>
18+
#include <cctype>
1719

1820
namespace concore_base {
1921

@@ -188,17 +190,20 @@ inline ConcoreValue parse_literal_value(const std::string& s, size_t& pos) {
188190
return parse_literal_string(s, pos);
189191

190192
if (s.compare(pos, 4, "True") == 0 &&
191-
(pos + 4 >= s.size() || !std::isalnum(static_cast<unsigned char>(s[pos + 4])))) {
193+
(pos + 4 >= s.size() ||
194+
(!std::isalnum(static_cast<unsigned char>(s[pos + 4])) && s[pos + 4] != '_'))) {
192195
pos += 4;
193196
return ConcoreValue::make_bool(true);
194197
}
195198
if (s.compare(pos, 5, "False") == 0 &&
196-
(pos + 5 >= s.size() || !std::isalnum(static_cast<unsigned char>(s[pos + 5])))) {
199+
(pos + 5 >= s.size() ||
200+
(!std::isalnum(static_cast<unsigned char>(s[pos + 5])) && s[pos + 5] != '_'))) {
197201
pos += 5;
198202
return ConcoreValue::make_bool(false);
199203
}
200204
if (s.compare(pos, 4, "None") == 0 &&
201-
(pos + 4 >= s.size() || !std::isalnum(static_cast<unsigned char>(s[pos + 4])))) {
205+
(pos + 4 >= s.size() ||
206+
(!std::isalnum(static_cast<unsigned char>(s[pos + 4])) && s[pos + 4] != '_'))) {
202207
pos += 4;
203208
return ConcoreValue::make_string("None");
204209
}

0 commit comments

Comments
 (0)