I write a parser to find string concatenation expressions. I have a range of strings which are enclosed by parentheses, originated mainly from a function call.
For example, ("one"+"two"+"three") -> ("one"|"two"|"three")
is a simple case and I can handle it.
A more difficult case is (null, "one"+"two"+"three", null) -> (null, "one"|"two"|"three", null)
, but I'm able parse it with boost::tokenizer
.
(null, "one"+"two"+"three,four", 1 /* third parameter can be: 1, 2, 3 */)
, in such a difficult example I suggest parsing with boost::spirit
but I need help in writing some rules for it.
Later:
Seems like escaped_list_separator
from the boost::tokenizer
is what I need.
But I have one problem with it:
using namespace std;
using namespace boost;
string s = "Field 1,\"putting quotes around fields, allows commas\",Field 3";
tokenizer<escaped_list_separator<char> > tok(s,escaped_list_separator<char>("", ",", "\""));
for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end();++beg){
cout <<"~~~"<< *beg << "\n";
}
removes "
for me. It is possible to keep quotes in output like this
Field 1
"putting quotes around fields, allows commas"
Field 3