Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7488135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:45:28+00:00 2026-05-29T14:45:28+00:00

I have an input string I’m trying to parse. It might look like either

  • 0

I have an input string I’m trying to parse. It might look like either of the two:

sys(error1, 2.3%)
sys(error2 , 2.4%)
sys(this error , 3%)

Note the space sometimes before the comma. In my grammer (boost spirit library) I’d like to capture “error1”, “error2”, and “this error” respectively.

Here is the original grammar I had to capture this – which absorbed the space at the end of the name:

name_string %= lexeme[+(char_ - ',' - '"')];
name_string.name("Systematic Error Name");

start = (lit("sys")|lit("usys")) > '('
  > name_string[boost::phoenix::bind(&ErrorValue::SetName, _val, _1)] > ','
  > errParser[boost::phoenix::bind(&ErrorValue::CopyErrorAndRelative, _val, _1)]
  > ')';

My attempt to fix this was first:

name_string %= lexeme[*(char_ - ',' - '"') > (char_ - ',' - '"' - ' ')];

however that completely failed. Looks like it failes to parse anything with a space in the middle.

I’m fairly new with Spirit – so perhaps I’m missing something simple. Looks like lexeme turns off skipping on the leading edge – I need something that does it on the leading and trailing edge.

Thanks in advance for any help!

Thanks to psur below, I was able to put together an answer. It isn’t perfect (see below), but I thought I would update the post for everyone to see it in context and nicely formatted:

qi::rule<Iterator, std::string(), ascii::space_type> name_word;
qi::rule<Iterator, std::string(), ascii::space_type> name_string;
ErrorValueParser<Iterator> errParser;

name_word %= +(qi::char_("_a-zA-Z0-9+"));
//name_string %= lexeme[name_word >> *(qi::hold[+(qi::char_(' ')) >> name_word])];

name_string %= lexeme[+(qi::char_("-_a-zA-Z0-9+")) >> *(qi::hold[+(qi::char_(' ')) >> +(qi::char_("-_a-zA-Z0-9+"))])];

start = (
         lit("sys")[bind(&ErrorValue::MakeCorrelated, _val)]
         |lit("usys")[bind(&ErrorValue::MakeUncorrelated, _val)]
         )
  >> '('
  >> name_string[bind(&ErrorValue::SetName, _val, _1)] >> *qi::lit(' ')
  >> ','
  >> errParser[bind(&ErrorValue::CopyErrorAndRelative, _val, _1)]
  >> ')';

This works! They key to this is the name_string, and in it the qi::hold, a operator I was not familiar with before this. It is almost like a sub-rule: everything inside qi::hold[…] must successfully parse for it to go. So, above, it will only allow a space after a word if there is another word following. The result is that if a sequence of words end in a space(s), those last spaces will not be parsed! They can be absorbed by the *qi::lit(‘ ‘) that follows (see the start rule).

There are two things I’d like to figure out how to improve here:

  • It would be nice to put the actual string parsing into name_word. The problem is the declaration of name_word – it fails when it is put in the appropriate spot in the definition of name_string.

  • It would be even better if name_string could include the parsing of the trailing spaces, though its return value did not. I think I know how to do that…

When/if I figure these out I will update this post. Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T14:45:30+00:00Added an answer on May 29, 2026 at 2:45 pm

    Below rules should work for you:

    name_word %= +(qi::char_("_a-zA-Z0-9"));
    
    start %= qi::lit("sys(")
      >> qi::lexeme[ name_word >> *(qi::hold[ +(qi::char_(' ')) >> name_word ]) ]
      >> *qi::lit(' ')
      >> qi::lit(',')
      // ...
    

    name_word parse only one word in name; I assumed that it contains only letter, digits and underscore.

    In start rule qi::hold is important. It will parse space only if next is name_word. In other case parser will rollback and move to *qi::lit(' ') and then to comma.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an input string that will look something like Monday 2:00 pm and
This is driving me nuts... I have an input string like so: String input
I have a input string like: $str = ':this is a applepie :) ';
I have an input string like this: \pard\nowidctlpar\qj\b0\scaps This Agreement\scaps0 is made and entered
I have test input string (key=value&key=value...) and key (like this D2335A9CA4924D9F914D2B47B450D436) I need to
I have a string input = "maybe (this is | that was) some ((nice
I have an input string that will either be a JSON packet, ala: {PHONE:555-513-4318,FIRSTNAME:Austin,ARTISTID:2,LASTNAME:Weber}
I have an input string in the following format: 12.34 When I call this
I have this input string(oid) : 1.2.3.4.5.66.77.88.99.10.52 I want group each number into 3
I have an input as 2:{{2,10},{6,4}} I am reading this as string input =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.