The difference operator: the rule lit("policeman") - "police" will always fail ?

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

The difference operator: the rule lit("policeman") - "police" will always fail ?

by Alex Sekhoy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello, dear spirit devs!

i am curious if there's a way to parse "foobar" while not allowing "foo"? here's an explanation:

//cut here
struct keywords : qi::symbols<char> {
    keywords(){
        add
         ("if")
         ("else")
         //...etc
    }
} keywords_symbols;

rule<Iterator, std::string(), ascii::space> name;
name %= raw[
                        lexeme
                        [
                           ((alpha | char_('_')) >> *(alnum | char_('_')))
                            - keywords_symbols
                        ]
                     ];
//cut here

This rule doesn't allow such inputs as "ifxxx", "else123".

According to the new docs about "The Difference operator, (a -  b)":
Unlike classic Spirit, with Spirit2, the expression will always fail if the RHS is a successful match regardless if the RHS matches less characters. For example, the rule lit("policeman") - "police" will always fail to match. Spirit2 does not count the matching chars while parsing and there is no reliable and fast way to check if the LHS matches more than the RHS.

Could you be so kind to provide me with solutions for my task? Thank you guys!

Re: The difference operator: the rule lit("policeman") - "police" will always fail ?

by Dainis Polis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Alex Sekhoy wrote:
> Hello, dear spirit devs!
>
> i am curious if there's a way to parse "foobar" while not allowing "foo"?
> here's an explanation:
>  
Only when you not allow   foo >>  ! lit('b')
In another words if we know char , after  one  is  known  ending  of phrase,
then  this ending char must be  after   "foo"  and  after "foobar".
Then only after this char we know who is who. ;-)
 

 
 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general