473,804 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String Parser using BOOST.Spirit

hi,

i have problem implemting a string parser that parser comman delimited
string:
"str1,str2,str3 "
INTO:
1. str1
2. str2
3. str3
*also strings are of any string (no specific string/keyword)

I have this code below, what it does so far is to parse specific
string: "x1", "x2", "y1", "y2"
but what i need is a parser for any kind of string (comma delimited)

bool
parse_string(ch ar const* str, vector<string>& v)
(
return parse(str,
(
(str_p("x1"[push_back_a(v)]) |
str_p("x2")[push_back_a(v)] )
*(',' >> (str_p("y1")[push_back_a(v)] |

str_p("y2")[push_back_a(v)] ) )
),
space_p).full;
)

example use: INPUT: "x1,y2,y1,y 2"
OUTPUT:
x1
y2
y1
y2

what i need is:
example: INPUT: "this,is,a,test "
OUTPUT:
this
is
a
test

ps. i need to implement this using BOOST.Spirit
--
Thx

Apr 2 '06 #1
13 8442
krbyxtrm wrote:
hi,

i have problem implemting a string parser that parser comman delimited
string:
"str1,str2,str3 "
INTO:
1. str1
2. str2
3. str3
*also strings are of any string (no specific string/keyword)


Your better off joining the boost.spirit mailing list at:
http://lists.sourceforge.net/lists/l...spirit-general

Also I'd be surprised if there weren't an example of doing exactly that in
your spirit installation. Something like rule<> comma_delimited =
(*(anychar_p-','))[push_back_a(a)] % ',';

Jeff Flinn
Apr 3 '06 #2

Also I'd be surprised if there weren't an example of doing exactly
that in your spirit installation. Something like rule<>
comma_delimited = (*(anychar_p-','))[push_back_a(a)] % ',';


OT, but: What is that % operator used for?
Apr 3 '06 #3
Gernot Frisch wrote:
Also I'd be surprised if there weren't an example of doing exactly
that in your spirit installation. Something like rule<>
comma_delimited = (*(anychar_p-','))[push_back_a(a)] % ',';


OT, but: What is that % operator used for?


From the docs at http://www.boost.org/libs/spirit/doc/operators.html,

a % b ; Match a list of one or more repetitions of a separated by
occurrences of b. This is the same as a >> *(b >> a). Note that a must not
also match b.

Jeff
Apr 3 '06 #4
> Gernot Frisch wrote:
OT, but: What is that % operator used for?


Awesome expression metatemplate techniques are never off-topic!

(And could we all learn to stand up to the chronic naggers, instead of
cringing each time a thread strays off The C++ Standard?)

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 3 '06 #5
Phlip wrote:
Gernot Frisch wrote:

OT, but: What is that % operator used for?


Awesome expression metatemplate techniques are never off-topic!


I don't consider them awesome. Actually, it's the worst case of operator
abuse I've ever seen.

Apr 3 '06 #6
Rolf Magnus wrote:
I don't consider them awesome. Actually, it's the worst case of operator
abuse I've ever seen.


Can you implement an efficient and appealing parser generator directly in
C++ without abusing the occassional operator?

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 3 '06 #7
Phlip wrote:
Rolf Magnus wrote:
I don't consider them awesome. Actually, it's the worst case of operator
abuse I've ever seen.


Can you implement an efficient and appealing parser generator directly in
C++ without abusing the occassional operator?


No, and I wouldn't want to do that either.
Apr 3 '06 #8
Hello people,

I have this parser that parses string that represents a function,
CONSIDER:

bool
parse_info<> x_parser3(char const* str, FunctionSpec& spec)
{
// some rules...
rettype = lexeme_d[(alpha_p)
*(alnum_p | space_p | ch_p('*'))][&do_ret];
// assign function name when match...
functionName = lexeme_d[(alpha_p | ch_p('_')) *(alnum_p | ch_p('_'))][assign_a(spec.m _Name)];

// other rules....
....
return parse(str,top);
}

for the functionName rule it was easy, just assign the name.
but for the rettype rule its much harder since i should not be assigned
directly,
since the FunctionSpec struct look like this:

strcut FunctionSpec {
std::string m_Name;
enum eVarType {
VAR_VOID, VAR_BOOL, VAR_INT...
}
eVarType m_RetType;
}

How can i assign value for 'm_RetType' ? since [do_ret] callback on
rettype rule is like this: do_ret[char const*,char const*], is there a
way around here?

Apr 3 '06 #9
krbyxtrm wrote:
I have this parser that parses string that represents a function,


Your post has two little problems:

- it's a new question, so it gets a new Subject
- the best place for Boost questions are its mailing lists

Just so you understand how topicality works, _I_ don't mind reading Boost
traffic here, because it's very important, and I'm not on that mailing
list. But _you_ will get the best answer on the narrowest possible
technical forum. There are too many people here who don't know enough about
Boost to qualify.

Try the Boost.Spirit mailing list for this one.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 3 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3182
by: sbobrows | last post by:
{Whilst I think much of this is OT for this newsgroup, I think the issue of understanding diagnostics just about gets under the door. -mod} Hi, I'm a C++ newbie trying to use the Boost regex libraries. Here's my situation. My system is Red Hat Linux 9, using the Borland C++BuilderX Personal IDE (which uses the g++ compiler).
1
2091
by: Ingo Nolden | last post by:
Hi, I am using spirit 1.31 I have been trying the following example from the spirit docs. I tried it with int and double neither works: vector<int> v; rule<> r = list_p(int_p, ch_p(',')); but it gives the weird messages:
1
3778
by: Alf P. Steinbach | last post by:
Microsoft Visual C++ warning C4267 (the number is not a typo) can occur e.g. when compiling Boost Spirit, or when doing std::size_t x = 0; std::cout << x; when compiled with 64-bit compatibility warnings enabled. One fix is to turn off conversion warnings, another _may be_ as follows -- I'm wondering whether someone could test this on a 64-bit machine, or have
3
2907
by: Paul van Hagen | last post by:
Hello, I've been doing some research as to ways to optimise our parsing and evaluation of mathematical expressions and came across the spirit template library as part of the boost library. It looks like for the parsing bit that library provides everything we need. However, I'm still pondering about the best performing options for the evaluation part. The idea is to evaluate the same expressions many times with different values....
4
2873
by: Marcin Kalicinski | last post by:
Hi All, Does anybody has experience compiling XML parser written with boost::spirit on gcc? The parser is based on http://spirit.sourceforge.net/repository/applications/xml.zip samples. What I'm concerned of is compilation time - my current version takes about 30 minutes to compile on gcc 3.4.2 - this is completely unaccteptable. Am I doing something wrong or is this expected with gcc? N.b. on MSVC 2005 it compiles in less than 1...
2
2839
by: Rahul | last post by:
Hey Guys I have a development environment, in which the whole SQL syntax is stored in the Database. So the syntax in the databse column could be "where BirthDate = '12/31/2005' and ID = 345" Note : The above string is stored and the dates are in US format. so
3
6414
by: Chris Jones | last post by:
Hi, I've experimenting with using boost::pool_allocator with std::vector and gcc (4.1)., and I am having problems with segmentation violations. Below I give a simple example of one way I am getting this // Include files #include <cmath> #include <iostream> #include <vector>
3
1781
by: =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki | last post by:
How do it's by next of boost.spirit library it are not discrimitation a letter size that a small letters and big letters it are not discrimitation? I'm know how write s small parser by next of boost.spirit but at above a establishment I do not know! Thanks in advice.
4
2557
by: Man4ish | last post by:
namespace ve/////////////////ve.h { struct VertexProperties { std::size_t index; boost::default_color_type color; }; } /////////////////////////////////////////////////////////////////////////////////////////////////// namespace ed///////////////////////ed.h
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10097
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9175
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.