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 5970309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:21:24+00:00 2026-05-22T20:21:24+00:00

I’m trying to learn Boost Spirit and as an exercise, I’ve tried to parse

  • 0

I’m trying to learn Boost Spirit and as an exercise, I’ve tried to parse a SQL INSERT statement using Boost Spirit Classic.

This is the string I’m trying to parse:

INSERT INTO example_tab (cola, colb, colc, cold) VALUES (vala, valb, valc, vald);

From this SELECT example I’ve created this little grammar:

struct microsql_grammar : public grammar<microsql_grammar>
{
    template <typename ScannerT>
    struct definition
    {
        definition(microsql_grammar const& self)
        {
            keywords = "insert", "into", "values";

            chlit<>     LPAREN('(');
            chlit<>     RPAREN(')');
            chlit<>     SEMI(';');
            chlit<>     COMMA(',');

            typedef inhibit_case<strlit<> > token_t;

            token_t INSERT      = as_lower_d["insert"];
            token_t INTO        = as_lower_d["into"];
            token_t VALUES      = as_lower_d["values"];

            identifier =
                nocase_d
                [
                    lexeme_d
                    [
                        (alpha_p >> *(alnum_p | '_'))
                    ]
                ];

             string_literal =
                lexeme_d
                [
                    ch_p('\'') >>  +( anychar_p - ch_p('\'') )
                    >> ch_p('\'')
                ];

            program =               +(query);

            query =                 insert_into_clause >> SEMI;

            insert_into_clause =    insert_clause >> into_clause;

            insert_clause =         INSERT >> INTO >> identifier >> LPAREN >> var_list_clause >> RPAREN;

            into_clause =           VALUES >> LPAREN >> var_list_clause >> RPAREN;

            var_list_clause =       list_p( identifier, COMMA );
        }

        rule<ScannerT> const& start() const { return program; }

        symbols<> keywords;

        rule<ScannerT> identifier, string_literal, program, query, insert_into_clause, insert_clause,
            into_clause, var_list_clause;
    };
};

Using a minimal to test it:

void test_it(const string& my_example)
{
    microsql_grammar g;

    if (!parse(example.c_str(), g, space_p).full)
    {
                // point a - FAIL
        throw new exception();
    }

    // point b - OK
}

Unfortunately it always enters the point A and throws the exception. Since I’m new to this, I have no idea where my error lies. I have two questions:

  1. What’s the proper way to debug parsing errors when using Boost Spirit?
  2. Why parsing fails in this example?
  • 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-22T20:21:25+00:00Added an answer on May 22, 2026 at 8:21 pm

    To get visibility into what is failing to parse, assign the result of parse to a parse_info<>, then log/examine the parse_info<>::stop field, which in this case should be a const char * pointing at the last byte of you input string that matched your grammar.

    microsql_grammar g;
    
    parse_info<std::string::const_iterator> result = parse(example.begin(), example.end(), g, space_p)
    if (!result.full)
    {
        std::string parsed(example.begin(), result.stop);
        std::cout << parsed << std::endl;
    
                // point a - FAIL
    }
    
    // point b - OK
    

    Apologies if this doesn’t compile, but should be a starting point.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.