Re: simple sql query parser
labsquare <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CABeqv=XALGVMS5MVr5OB2Zzezp0oit-o3u733uhCZ-iaa8TrWw@mail.gmail.com> |
It works perfect !!! Thanks you ! My last question : what's the goal of "class" inside the rule declaration . auto rule = x3::rule<*class whereRule*, string>() is "class whereRule" is really necessary ? What's the purpose ? 2018-01-01 17:47 GMT+01:00 Mike Gresens <[email protected]>: > That's easy too. Try: > > > #include <boost/fusion/include/adapt_struct.hpp> > > struct result { > std::vector<std::string> selectData; > std::string fromData; > std::vector<std::string> whereData; > std::string insideData; > }; > > BOOST_FUSION_ADAPT_STRUCT > ( > result, > selectData, > fromData, > whereData, > insideData > ); > > ... > > result result; > x3::phrase_parse(begin,end, > selectRule >> fromRule >> -whereRule >> -insideRule, > x3::space, result); > > > Mike... > > > > Am 01.01.2018 um 17:25 schrieb labsquare: > > Now, how can store each extracted data in the corresponding variable ? > Actually, everything is keepying is one vector<string> . I would like to > fill 4 differents variables . > See the code exemple : https://github.com/labsquare/vql/blob/master/ > vqlcompiler.cpp#L42 > > 2018-01-01 17:03 GMT+01:00 labsquare <[email protected]>: > >> I don't know how, I don't know why... But It works !!! >> Thank you very much !! >> >> 2017-12-31 2:31 GMT+01:00 Mike Gresens <[email protected]>: >> >>> Try this: >>> >>> // any character except "INSIDE" >>> auto condition = x3::rule<class condition, string>() >>> = x3::lexeme[*(x3::char_ - "INSIDE")]; >>> >>> Mike... >>> >>> Am 31.12.2017 um 01:49 schrieb labsquare: >>> >>> I'm trying to parse a simple pseudo-SQL like query using boost spirit x3. >>> But I didn't succes to extract the condition alone. It takes all the >>> string to the end ( with the INSIDE part). >>> Here is my attempt . Any suggestion ? >>> https://stackoverflow.com/questions/48033462/parse-sql-like- >>> query-with-boost-spirit-x3 >>> >>> // SELECT chr, pos FROM table// Select chr, pos FROM table WHERE a=5 and b = 6// SELECT chr, pos FROM table WHERE a =5 and b=6 INSIDE region >>> // I would like to extract :// vector<string> fields = {chr, pos}// string tablename = "table"// string where = "a=5 and b=6"// string region = "region" >>> >>> string source ="SELECT chr,pos FROM table WHERE a=5 AND b=6 INSIDE region"; >>> // varname = chr, pos, table, region >>> auto varname = x3::rule<class varname, string>() >>> = x3::lexeme[(x3::alpha >> *(x3::alnum|'_'|'.'))]; >>> // any character except "INSIDE" >>> auto condition = x3::rule<class condition, string>() >>> = x3::lexeme[*x3::char_]-"INSIDE"; >>> // fields selection >>> auto selectRule = x3::rule<class fields, vector<string>> () >>> = "SELECT" >> varname % ","; >>> >>> // table name >>> auto fromRule = x3::rule<class fromRule, string>() >>> = "FROM" >> varname; >>> // where clause >>> auto whereRule = x3::rule<class whereRule, vector<string>>() >>> = "WHERE" >> condition ; >>> // inside clause >>> auto insideRule = x3::rule<class insideRule, string>() >>> = "INSIDE" >> varname; >>> >>> auto begin = source.begin(); >>> auto end = source.end(); >>> >>> vector<string> results; >>> >>> x3::phrase_parse(begin,end, >>> selectRule >> fromRule >> -(whereRule >>-insideRule), >>> x3::space, results); >>> if (begin != end) >>> cout<<"COULD NOT PARSE"<<endl;else >>> cout<<"parse succes"<<endl; >>> for (auto i : results) >>> cout<<i<<endl; >>> >>> It returns: >>> >>> chr >>> postable >>> a=5 AND b=6 INSIDE region >>> >>> >>> >>> >>> >>> -- >>> -- >>> Dr Sacha Schutz >>> médecine / génétique moléculaire >>> Bioinformaticien >>> +33651571606 >>> dridk.me >>> www.labsquare.org >>> Fork me on github <https://github.com/> >>> >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>> >>> >>> >>> _______________________________________________ >>> Spirit-general mailing [email protected]://lists.sourceforge.net/lists/listinfo/spirit-general >>> >>> >>> >> >> >> -- >> -- >> Dr Sacha Schutz >> médecine / génétique moléculaire >> Bioinformaticien >> +33651571606 >> dridk.me >> www.labsquare.org >> Fork me on github <https://github.com/> >> >> >> > > > -- > -- > Dr Sacha Schutz > médecine / génétique moléculaire > Bioinformaticien > +33651571606 > dridk.me > www.labsquare.org > Fork me on github <https://github.com/> > > > > -- -- Dr Sacha Schutz médecine / génétique moléculaire Bioinformaticien +33651571606 dridk.me www.labsquare.org Fork me on github <https://github.com/> ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Spirit-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spirit-general