I've text which contains "equations" like :
-- This is comment
ABC:= 121-XY1/7 > 45 OR SS >= 3
ZY2 AND -- This is another comment
(JKL * PQR) < 75;
JKL:= PP1 OR
PP2/2 XOR PP3;
ZZ_1:=A-B > 0 XOR (B2 % GH == 6 AND
SP == 4
-- Again a comment
NOT AX > GF < 2 OR C*AS2 >= 5);
I decided to use boost spirit to parse this text , as of now I just need to know my operands and operators.
I've referred this nice answer (thanks to sehe :) ) to write my expression grammar (relational operators not written yet)
However I cannot strip my comments with :-
qi::phrase_parse(input.begin()
,input.end()
,p >> ';' // parser object
,qi::space | "--" >> *(qi::char_ - qi::eol) >> qi::eol
,result //expression object, (boost::variant with boost::recursive_wrapper)
);
because it gives several errors, some of the post says to tweak a boost header file.
So I'm using another grammar to strip off comment first using :
qi::phrase_parse(input.begin()
,input.end()
,qi::char_ >> *qi::char_
, qi::space | "--" >> *(qi::char_ - qi::eol) >> qi::eol
,stripped // std::string
);
But this gives me a text with all space and comment removed :
ABC:=121-XY1/7>45ORSS>=3ZY2AND(JKL*PQR)<75;JKL:=PP1ORPP2/2XORPP3;ZZ_1:=A-B>0XOR(B2%GH==6ANDSP==4NOTAX>GF<2ORC*AS2>=5);
So, the question is how can I strip just the comments, preserving space and newlines ?
Using : Boost Version 1.55.0
decltype
orBOOST_TYPEOF
. If that were your problem (and I'm taking a shot in the dark) I believe the usual solution is creating a skipper grammar (something like this). – llonesmiz