in according to the answer from sehe i want to parse quoted and normal content from a memory mapped file, as fast as possible.
The actual Parser looks like:
namespace qi = boost::spirit::qi;
using MatrixType = std::vector<std::vector<boost::string_ref>>;
template<typename It>
struct parser : qi::grammar<It, MatrixType(), qi::blank_type, qi::locals<char> >
{
parser()
: parser::base_type( table, "parser" )
{
using namespace boost::phoenix;
using namespace qi;
delimiter = ',';
quoted =
omit [ char_("'\"") [_a = _1] ]
>> raw [ *(char_ - char_(_a)) ] [ _val = construct<boost::string_ref>(begin(_1), size(_1)) ]
>> lit(_a);
unquoted = raw[ *(char_ - (eol | delimiter) ) ] [ _val = construct<boost::string_ref>(begin(_1), size(_1))]; //raw [ *(char_ - char_("\"',")) ] [ _val = construct<boost::string_ref>(begin(_1), size(_1)) ];
any_string = quoted | unquoted;
line = any_string % delimiter;
table = line % eol;
}
qi::rule<It, boost::string_ref() ,qi::locals<char> , qi::blank_type> any_string;
qi::rule<It, boost::string_ref() ,qi::locals<char> , qi::blank_type> quoted;
qi::rule<It, boost::string_ref() ,qi::locals<char> , qi::blank_type> unquoted;
qi::rule<It> delimiter;
qi::rule<It, std::vector<boost::string_ref>(), qi::blank_type> line;
qi::rule<It, MatrixType(), qi::blank_type, qi::locals<char>> table;
};
example Inputfile:
"a","b", "c", "d,e,f"
"a", -1, abc, 0.1
The actual parser add one , not existing empty line. There is no "\n" at the end of the file.