Carl Barron | 1 Aug 02:07

Re: compiling spirit 2 with xcode 3 [or less probably]


On Jul 29, 2008, at 9:23 PM, Carl Barron wrote:

Does anyone use Xcode to compile spirit 2 stuff?  I wonder what settings to use it should be just
setting 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 merge
boost::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 to
hold numeric excapses as well.

[snip]
well here is a single file first cut of a comma delimited data parser that accepts and translates
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
Naim Kingston | 3 Aug 05:17
Picon

Re: spirit and newlines

Thanks very much, that worked immediately on both counts.

-Naim

Jan Swoboda wrote:
> Naim Kingston <naim.kingston <at> gmail.com> writes:
> 
>> The input string (a single string because C automatically concatenates 
>> string literals):
>> "{"
>> "hello = 4;"
>> "}\n"
>> This will crash with the newline as the unparsed part of the string.
>>
>> "{"
>> "hello \n = 4;"
>> "}"
>> This works fine.
>>
>> "{\n"
>> "hello = 4;"
>> "}"
>> This doesn't. It ends up reading the "hello" as "\nhello".
>>
>> It also parses fine if I put the newline at the end of the middle 
>> statement, before the '}', or between the assignment and the '4', or 
>> between the '4' and the ';'.
>>
>> Should I be adding the possibility of newlines at the end of a block of 
>> code to my grammar? And, for the identifier ("hello"), here is the rule:
>>
>> identifier =	boost::spirit::token_node_d[
>> 		(boost::spirit::alpha_p | '_') >>  *(boost::spirit::alpha_p | 
>> boost::spirit::digit_p | '_') ];
>>
>> I'm pretty sure that 'alpha_p' and 'digit_p' don't accept whitespace, so 
>> where is the whitespace coming from in "\nhello"?
>>
> 
> 
> Those are actually two different problems.
> 
> Your initial problem is expected behaviour (see also "Evil Post Skips",
> http://thread.gmane.org/gmane.comp.parsers.spirit.general/9839). Fix it by
> calling (ast_)parse( begin, end, grammar >> end_p, space_p ).
> 
> For the second I'd still like to see a reaction (see also "Whitespace and
> leaf_node_d", http://article.gmane.org/gmane.comp.parsers.spirit.general/13145,
> or the Trac entry), leaf_node_d and token_node_d "work the same". Replace it
> with reduced_node_d as a workaround.
> 
> 
> 
> -------------------------------------------------------------------------
> 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=/

-------------------------------------------------------------------------
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=/
Richard Webb | 7 Aug 18:19
Gravatar

[spirit2] file spirit/home/phoenix.hpp is empty

The file boost/spirit/home/phoenix.hpp (included from spirit/include/phoenix.hpp
 ) in the Boost SVN is empty (doesn't include any files).
Should it be including the other Phoenix files, as the 'classic' version does?

Thanks,
Richard Webb

-------------------------------------------------------------------------
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=/
Joel de Guzman | 9 Aug 04:50
Picon
Favicon

Re: [spirit2] file spirit/home/phoenix.hpp is empty

Richard Webb wrote:
> The file boost/spirit/home/phoenix.hpp (included from spirit/include/phoenix.hpp
>  ) in the Boost SVN is empty (doesn't include any files).
> Should it be including the other Phoenix files, as the 'classic' version does?

Yes. I'll fix it. Thanks for spotting.

Regards,
--

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

-------------------------------------------------------------------------
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=/
River Tarnell | 9 Aug 12:47
Picon

c_escape_ch_p problem (Boost 1.35.0)


hi,

i have a grammar that looks like this:

	   ch_p('"')
	>> *(c_escape_ch_p - '"')
	>> ch_p('"')

the string "x\x20y" is parsed correctly.  however, if the \x escape contains
a..f or A..F, or is followed by 0..f or 0..F, parsing fails.  for example,
these strings fail:

  "\xaa"
  "\x205"
  "\xffb"

what am i doing wrong?

	- river.
Hartmut Kaiser | 9 Aug 16:35
Picon
Gravatar

Re: c_escape_ch_p problem (Boost 1.35.0)


> i have a grammar that looks like this:
> 
> 	   ch_p('"')
> 	>> *(c_escape_ch_p - '"')
> 	>> ch_p('"')
> 
> the string "x\x20y" is parsed correctly.  however, if the \x escape
> contains
> a..f or A..F, or is followed by 0..f or 0..F, parsing fails.  for
> example,
> these strings fail:
> 
>   "\xaa"
>   "\x205"
>   "\xffb"

The escape parser makes sure the parsed number fits into the data type
specified as the 2nd template parameter to the parser type:

    template <unsigned long Flags, typename CharT>
    struct escape_char_parser;

and CharT defaults to 'char'. 

But none of your numbers can be represented using a signed char. For this
reason parsing fails for you.

If you need to parse hex numbers larger than representable by a char you
need to use something like:

const escape_char_parser<c_escapes, int> c_escape_int_p =
    escape_char_parser<c_escapes, int >();

        ch_p('"')
    >> *(c_escape_int_p - '"')
    >>  ch_p('"')

HTH
Regards Hartmut

> 
> what am i doing wrong?
> 
> 	- river.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (SunOS)
> 
> iEYEARECAAYFAkiddbsACgkQIXd7fCuc5vK+NQCfcFKZkuLut1qBfj/AZuzXVWA3
> w/4An0LBQSmPMM35Kld6vr5WjfkdruYS
> =oRhU
> -----END PGP SIGNATURE-----
> 
> -----------------------------------------------------------------------
> --
> 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

-------------------------------------------------------------------------
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=/
River Tarnell | 10 Aug 03:41
Picon

Re: c_escape_ch_p problem (Boost 1.35.0)


Hartmut Kaiser:
> The escape parser makes sure the parsed number fits into the data type
> specified as the 2nd template parameter to the parser type:

>     template <unsigned long Flags, typename CharT>
>     struct escape_char_parser;

> and CharT defaults to 'char'. 

> But none of your numbers can be represented using a signed char. For this
> reason parsing fails for you.

okay - am i right then in thinking that it's not a bug that '\x' matches more
than two following characters?  my impression from the description page was
that it would work like the C++ \x.  (the problem with this behaviour is i
have to write "\xFF" + "2" instead of "\xFF2").

thanks,
river.
Hartmut Kaiser | 10 Aug 04:42
Picon
Gravatar

Re: c_escape_ch_p problem (Boost 1.35.0)

> > The escape parser makes sure the parsed number fits into the data
> type
> > specified as the 2nd template parameter to the parser type:
> 
> >     template <unsigned long Flags, typename CharT>
> >     struct escape_char_parser;
> 
> > and CharT defaults to 'char'.
> 
> > But none of your numbers can be represented using a signed char. For
> this
> > reason parsing fails for you.
> 
> okay - am i right then in thinking that it's not a bug that '\x'
> matches more
> than two following characters?  my impression from the description page
> was
> that it would work like the C++ \x.  (the problem with this behaviour
> is i
> have to write "\xFF" + "2" instead of "\xFF2").

If you need a parser which takes exactly 2 digits you might want to do the
following:

1) declare a customized uint parser: 

    uint_parser<unsigned, 16, 2, 2> const
        hex2_p   = uint_parser<unsigned, 16, 2, 2>();

i.e. a uint parser for hexdigits, taking exactly 2 digits.

And 2) use it as "\\x" >> hex2_p

HTH
Regards Hartmut

> 
> thanks,
> river.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (SunOS)
> 
> iEYEARECAAYFAkieR1cACgkQIXd7fCuc5vKExQCff5AbMd451+/3JvaIiADfOcDX
> EKoAn3fvme1a+GoKTsREUxvr/GhDxzBZ
> =oWSI
> -----END PGP SIGNATURE-----

-------------------------------------------------------------------------
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=/
Alex Ott | 11 Aug 15:48
Picon
Gravatar

bug in c_escape_ch?

Hello all

I'm currently working on one program, that use their own DSL.  DSL is
implemented using Boost.Spirit (from boost 1.35) and i have strange
behaviour of c_escape_ch parser - it successfully parse some strings, while
doesn't taking into account other one - for example, with following parser

	rule<> SigString = confix_p('"',*(alnum_p|c_escape_ch_p),'"');

string "7z\xBC\xAF\x27\x1C" isn't parsed, while "PK\x03\x04" parsed without
any problem.

How i can fix existing grammar in boost 1.35?

P.S. The test case is attached 

Attachment (test-spirit2.cpp): text/x-c++src, 1068 bytes

--

-- 
With best wishes, Alex Ott, MBA
http://alexott.blogspot.com/           http://xtalk.msk.su/~ott/
http://alexott-ru.blogspot.com/
-------------------------------------------------------------------------
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
Hartmut Kaiser | 11 Aug 16:07
Picon
Gravatar

Re: bug in c_escape_ch?

Alex,

> I'm currently working on one program, that use their own DSL.  DSL is
> implemented using Boost.Spirit (from boost 1.35) and i have strange
> behaviour of c_escape_ch parser - it successfully parse some strings,
> while doesn't taking into account other one - for example, with
> following parser
> 
> 	rule<> SigString = confix_p('"',*(alnum_p|c_escape_ch_p),'"');
> 
> string "7z\xBC\xAF\x27\x1C" isn't parsed, while "PK\x03\x04" parsed
> without any problem.
> 
> How i can fix existing grammar in boost 1.35?
> 
> P.S. The test case is attached

This is the same issue as discussed the day before yesterday on this list
(see thread: 'c_escape_ch_p problem (Boost 1.35.0)').

HTH
Regards Hartmut

-------------------------------------------------------------------------
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=/

Gmane