18 return std::regex( key +
"\\s*" +
key_sep +
"\\s*([\\-0-9]+)" );
21 #define X( type, name, is_optional ) \ 22 if ( std::regex_search( buffer, match, get_key_int_regex( #name ) ) ) \ 24 entry.name = decltype( entry.name )( std::stoi( match[ 1 ] ) ); \ 28 if constexpr ( !( is_optional ) ) \ 30 throw std::runtime_error( "Could not parse '" #name "' in line: " + buffer ); \ 35 const auto name_regex =
39 if ( std::regex_search( buffer, match, name_regex ) )
41 entry.name = match[ 1 ];
45 throw std::runtime_error(
"Could not parse 'name' in line: " + buffer );
50 const auto sub_sep =
",";
51 const auto str_map_regex = std::regex(
"str_map\\s*" +
key_sep +
"\\s*\\{.*\\}" );
52 if ( std::regex_search( buffer, str_map_regex ) )
54 entry.str_map.resize( entry.max - entry.min + 1 );
55 auto pos = buffer.find(
"str_map" );
56 pos = 1 + buffer.find(
key_sep, pos + 1 );
57 const auto entry_regex =
59 auto sub = buffer.substr( pos );
60 while ( std::regex_search( sub, match, entry_regex ) )
62 entry.str_map[ std::size_t( std::stoi( match[ 1 ] ) - entry.min ) ] = match[ 2 ];
63 pos = sub.find( sub_sep );
64 if ( pos == std::string::npos )
68 sub = sub.substr( pos + 1 );
73 const auto map_regex = std::regex(
"map\\s*" +
key_sep +
"\\s*\\{.*\\}" );
74 if ( std::regex_search( buffer, map_regex ) )
76 entry.map.resize( entry.max - entry.min + 1 );
77 auto pos = buffer.find(
"map" );
78 pos = 1 + buffer.find(
key_sep, pos + 1 );
79 const auto entry_regex = std::regex(
"([\\-0-9]+)\\s*" +
key_sep +
"\\s*([\\-0-9]+)" );
80 auto sub = buffer.substr( pos );
81 while ( std::regex_search( sub, match, entry_regex ) )
83 entry.map[ std::size_t( std::stoi( match[ 1 ] ) - entry.min ) ] =
84 std::stoi( match[ 2 ] );
85 pos = sub.find( sub_sep );
86 if ( pos == std::string::npos )
90 sub = sub.substr( pos + 1 );
96 inline std::vector< section_t >
read_file( std::istream& file )
98 std::vector< section_t > sections;
100 while ( !file.eof() )
103 std::getline( file, buffer );
104 if ( buffer.empty() )
112 if ( std::regex_match( buffer, match, section_regex ) )
114 sections.emplace_back( match[ 1 ] );
119 sections.back().entries.emplace_back();
122 read_entry( sections.back().entries.back(), buffer );
124 catch ( std::runtime_error& error )
126 std::cerr << error.what() << std::endl;
127 sections.back().entries.pop_back();
Definition: device_spec.hpp:26
void read_entry(device_entry_t &entry, const std::string &buffer)
Definition: device_spec_reader.hpp:33
std::vector< section_t > read_file(std::istream &file)
Definition: device_spec_reader.hpp:96
#define SEQUENCER_DEVICE_CC_VALUES
Definition: device_spec.hpp:9
std::regex get_key_int_regex(const std::string &key)
Definition: device_spec_reader.hpp:16
const auto key_sep
Definition: device_spec_reader.hpp:13
const auto string_identifier_regex_str
Definition: device_spec_reader.hpp:14