1 Aug 02:07
Re: compiling spirit 2 with xcode 3 [or less probably]
Carl Barron <cbarron413 <at> roadrunner.com>
2008-08-01 00:07:36 GMT
2008-08-01 00:07:36 GMT
On Jul 29, 2008, at 9:23 PM, Carl Barron wrote:
well here is a single file first cut of a comma delimited data parser that accepts and translatesDoes anyone use Xcode to compile spirit 2 stuff? I wonder what settings to use it should be justsetting a recursive search of my update fromf svn of the trunk branch of the boost svn. correct?what namespace contains what? semms like lexeme is not in namespace boost::spirit::qi errors etc.are common. [I perfer to write my parsers etc that are templates in headers and do not wish to mergeboost::spiriit and its sub namespaces in the global namespace.I have this to recognize a string in quotes with embedded quotes but eventually want to extend it tohold numeric excapses as well.[snip]
escaped chars in the strings in the list. It still complains that about _1 not being defined or no matching
phrase_parse:
#include <iostream>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/variant.hpp>
#include <vector>
#include <string>
#include <boost/variant.hpp>
#include <vector>
typedef boost::variant<std::string,double> parsed_item;
using namespace boost::spirit;
using namespace boost::spirit::qi;
using namespace boost::spirit::arg_names;
using namespace boost::spirit::ascii;
template <class Iter>
struct string_gram:boost::spirit::qi::grammar
<
Iter,
std::string()
>
{
string_gram():string_gram::base_type(start)
{
my_char = lexeme[char_('\\') >> char_ [_val = _1] // _1 not definhed in this scope
| !char_('"') >> char_ [_val = _1] ]
;
start = lexeme[char_('"') >> +(my_char [_val += _1]) >> '"']
;
}
rule<Iter,char()> my_char;
rule<Iter,std::string() > start;
};
typedef boost::variant<std::string,double> item_type;
template <class Iter>
struct list_gram:boost::spirit::qi::grammar
<
Iter,
std::vector<item_type>(),
space_type
>
{
list_gram():list_gram::base_type(start)
{
start %= item % ',';
item %= (str | double_);
}
string_gram<Iter> str;
boost::spirit::qi::rule<Iter,item_type() > item;
boost::spirit::qi::rule<Iter,std::vector<item_type>(),boost::spirit::ascii::space_type> start;
};
int main()
{
std::string input("\"this is a \\\"test\\\"\",12345.3");
std::vector<item_type> ans;
list_gram<std::string::iterator> gram;
bool r = phrase_parse(input.begin(),input.end(),gram,ans,space);
// can't find matching phrase_parse
std::cout << "code parses is " << std::boolalpha << r << '\n';
}
------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________ Spirit-general mailing list Spirit-general <at> lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spirit-general
RSS Feed