@@ -64,6 +64,17 @@ constexpr std::array<std::string_view, BasicOp::Conditional + 1> mapping{
6464 " nbitwise_not" ,
6565 " ifnode" };
6666
67+ constexpr std::array<std::string_view, 8 > cfgtypes{
68+ " uint16_t" , // 0
69+ " int16_t" , // 1
70+ " uint32_t" , // 2
71+ " int32_t" , // 3
72+ " uint64_t" , // 4
73+ " int64_t" , // 5
74+ " float" , // 6
75+ " double" // 7
76+ };
77+
6778// / math constants to recognize in string expressions
6879constexpr std::array<std::string_view, 9 > mathConstants{
6980 " Almost0" ,
@@ -813,7 +824,8 @@ Tokenizer::Tokenizer(std::string const& input)
813824{
814825 LastChar = ' ' ;
815826 if (!source.empty ()) {
816- source.erase (std::remove_if (source.begin (), source.end (), ::isspace), source.end ());
827+ source.erase (std::remove_if (source.begin (), source.end (), ::isspace), source.end ()); // strip whitespaces
828+ source.erase (std::remove (source.begin (), source.end (), ' \" ' ), source.end ()); // strip quotes
817829 }
818830 current = source.begin ();
819831}
@@ -827,7 +839,8 @@ void Tokenizer::reset(std::string const& input)
827839 FloatValue = 0 .f ;
828840 source = input;
829841 if (!source.empty ()) {
830- source.erase (std::remove_if (source.begin (), source.end (), ::isspace), source.end ());
842+ source.erase (std::remove_if (source.begin (), source.end (), ::isspace), source.end ()); // strip whitespaces
843+ source.erase (std::remove (source.begin (), source.end (), ' \" ' ), source.end ()); // strip quotes
831844 }
832845 current = source.begin ();
833846 currentToken = Token::Unexpected;
@@ -1202,6 +1215,78 @@ std::unique_ptr<Node> Parser::parseBase(Tokenizer& tk)
12021215 }
12031216 tk.nextToken ();
12041217 return node;
1218+ } else if (id == " ncfg" ) { // configurable placeholder, 3 args none of them can be expressions
1219+ int args = 0 ;
1220+ std::string type;
1221+ std::string value;
1222+ std::string path;
1223+ while (tk.currentToken != ' )' ) {
1224+ do {
1225+ tk.nextToken ();
1226+ if (args == 0 ) { // type
1227+ type = tk.TokenStr ;
1228+ tk.nextToken ();
1229+ } else if (args == 1 ) { // value
1230+ value = tk.TokenStr ;
1231+ tk.nextToken ();
1232+ } else if (args == 2 ) { // path
1233+ path = tk.TokenStr ;
1234+ tk.nextToken ();
1235+ } else {
1236+ throw runtime_error_f (" Extra argument in configurable: %s" , tk.TokenStr .c_str ());
1237+ }
1238+ ++args;
1239+ } while (tk.currentToken == ' ,' );
1240+ }
1241+ tk.nextToken ();
1242+ auto locate = std::find (cfgtypes.begin (), cfgtypes.end (), type);
1243+ if (locate == cfgtypes.end ()) {
1244+ throw runtime_error_f (" Unsupported type in configurable: %s" , type.c_str ());
1245+ }
1246+ switch (std::distance (cfgtypes.begin (), locate)) {
1247+ case 0 :
1248+ return std::make_unique<Node>(
1249+ PlaceholderNode (
1250+ static_cast <uint16_t >(std::stoi (value)),
1251+ std::move (path)));
1252+ case 1 :
1253+ return std::make_unique<Node>(
1254+ PlaceholderNode (
1255+ static_cast <int16_t >(std::stoi (value)),
1256+ std::move (path)));
1257+ case 2 :
1258+ return std::make_unique<Node>(
1259+ PlaceholderNode (
1260+ static_cast <uint32_t >(std::stoi (value)),
1261+ std::move (path)));
1262+ case 3 :
1263+ return std::make_unique<Node>(
1264+ PlaceholderNode (
1265+ static_cast <int32_t >(std::stoi (value)),
1266+ std::move (path)));
1267+ case 4 :
1268+ return std::make_unique<Node>(
1269+ PlaceholderNode (
1270+ static_cast <uint64_t >(std::stoll (value)),
1271+ std::move (path)));
1272+ case 5 :
1273+ return std::make_unique<Node>(
1274+ PlaceholderNode (
1275+ static_cast <int64_t >(std::stol (value)),
1276+ std::move (path)));
1277+ case 6 :
1278+ return std::make_unique<Node>(
1279+ PlaceholderNode (
1280+ std::stof (value),
1281+ std::move (path)));
1282+ case 7 :
1283+ return std::make_unique<Node>(
1284+ PlaceholderNode (
1285+ std::stod (value),
1286+ std::move (path)));
1287+ default :
1288+ throw runtime_error_f (" Unsupported type in configurable: %s" , type.c_str ());
1289+ }
12051290 } else { // normal function
12061291 auto node = std::make_unique<Node>(opFromToken (id), LiteralNode{-1 }, LiteralNode{-1 });
12071292 int args = 0 ;
0 commit comments