Dynamic Rule Generation

View: New views
1 Messages — Rating Filter:   Alert me  

Dynamic Rule Generation

by Damien.Garrido :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I'm new to Spirit and I'm wondering if it is possible to generate a rule dynamically...
My purpose is to be able to read tokens from a file and generate the grammar accordingly...

For example the following rule works as expected:

rule = str_p( "token_1" )
  | str_p( "token_2" )
  | str_p( "token_3" )
  ;

But is it possible to generate this rule in a loop ?
Something like :

// Put token in a list
std::list< std::string > token_list;
token_list.push_back( "token_1" );
token_list.push_back( "token_2" );
token_list.push_back( "token_3" );

// Generate a rule from the token list
for ( std::list< std::string >::iterator token = token_list.begin() ; token != token_list.end() ; ++token )
{
    rule = rule | str_p( token->c_str() );
}

Any help would be appreciated !

--
Damien Garrido


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general