Parse data and asign it to variables
Hello, I have a question. I need some parser with which I can parse plain binary data and then assign the data to e.g. an PropertyTree It should be possible to parse the data with a userdefined pattern. It would be also great if I can use the same thing to make some filter for traffic, with which I can assign the data to some structs...in this case it is for sure better if this parser is made during compiletime... Is there some library in boost available with which it is possible to solve this problem? I don't know may be it is possible to solve the problem with spirit... Thanks for any hint! Best regards Hansjörg
Hi! Hansi schrieb:
Is there some library in boost available with which it is possible to solve this problem? I don't know may be it is possible to solve the problem with spirit...
Yes, spirit is the only library targeting your problem within boost. But spirit is for parsing anything, but it only has ready-to-use parsers for text. You would need to implement own parsers, that would parse e.g. an int out of binary data. See: http://www.boost.org/doc/libs/1_35_0/libs/spirit/doc/indepth_the_parser.html Inherit from parser<Derived> and implement the parse function. Look into the boost sources to see how predefined parsers are built. Decide upon "char type" to use, probably unsigned char for binary data. Frank
Frank Birbacher wrote:
Hansi schrieb:
Is there some library in boost available with which it is possible to solve this problem? I don't know may be it is possible to solve the problem with spirit...
Yes, spirit is the only library targeting your problem within boost.
A-hem. http://www.boost.org/doc/libs/1_35_0/doc/html/xpressive.html :-) If by "user-defined pattern" you mean, specified by the user either at compile-time or at runtime, then I think Xpressive is your best bet. -- Eric Niebler BoostPro Computing http://www.boostpro.com
Hi! Eric Niebler schrieb:
A-hem. http://www.boost.org/doc/libs/1_35_0/doc/html/xpressive.html
Ups. I should keep up a little. :)
:-) If by "user-defined pattern" you mean, specified by the user either at compile-time or at runtime, then I think Xpressive is your best bet.
Altough spirit has dynamic parsing capabilities it is focussed on a static grammar. Maybe to the OP xpressive is of more help then. By the way: looking into the introduction of xpressive, who actually allowed identifiers like "_w"? Leading underscore and a non-digit following it would be reserved to the compiler, I thought?!? Frank
AMDG Frank Birbacher wrote:
By the way: looking into the introduction of xpressive, who actually allowed identifiers like "_w"? Leading underscore and a non-digit following it would be reserved to the compiler, I thought?!?
Only in the global namespace for lower case letters. In Christ, Steven Watanabe
Frank Birbacher wrote:
By the way: looking into the introduction of xpressive, who actually allowed identifiers like "_w"? Leading underscore and a non-digit following it would be reserved to the compiler, I thought?!?
Leading underscore followed by capital letter is reserved, as are leading underscore followed by lowercase *at global scope*. "_w" is in the boost::xpressive namespace, so it's ok. I'm pretty sure I got that right, but someone will correct me if I didn't. -- Eric Niebler BoostPro Computing http://www.boostpro.com
Is there some package available which can be used with 1.34.1? Best regards Hansjörg Eric Niebler schrieb:
Frank Birbacher wrote:
Hansi schrieb:
Is there some library in boost available with which it is possible to solve this problem? I don't know may be it is possible to solve the problem with spirit... Yes, spirit is the only library targeting your problem within boost.
A-hem. http://www.boost.org/doc/libs/1_35_0/doc/html/xpressive.html
:-) If by "user-defined pattern" you mean, specified by the user either at compile-time or at runtime, then I think Xpressive is your best bet.
Yep. http://boostpro.com/vault/index.php?action=downloadfile&filename=xpressive.zip&directory=Strings%20-%20Text%20Processing& HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com Hansi wrote:
Is there some package available which can be used with 1.34.1?
Best regards Hansjörg
Eric Niebler schrieb:
Frank Birbacher wrote:
Hansi schrieb:
Is there some library in boost available with which it is possible to solve this problem? I don't know may be it is possible to solve the problem with spirit... Yes, spirit is the only library targeting your problem within boost. A-hem. http://www.boost.org/doc/libs/1_35_0/doc/html/xpressive.html
:-) If by "user-defined pattern" you mean, specified by the user either at compile-time or at runtime, then I think Xpressive is your best bet.
Is there also somewhere an example which handles binary data? I think xpressive is the right library to use! Best regards and thanks Hansjörg Eric Niebler schrieb:
Yep.
HTH,
Hansi wrote:
Is there also somewhere an example which handles binary data? I think xpressive is the right library to use!
Here's a brief section in the docs on searching non-character data with xpressive. http://tinyurl.com/5blyuw It's a bit out of date in that it suggests that you can only use static regexes for non-char data, which isn't true (TODO FIXME). The following shows how to use xpressive to search non-char data with dynamic or static regexes. It is part of xpressive's test suite: http://svn.boost.org/trac/boost/browser/trunk/libs/xpressive/test/test_non_c... HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (4)
-
Eric Niebler
-
Frank Birbacher
-
Hansi
-
Steven Watanabe