Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2005-03-26 06:28:46


> But I suspect it isnt the whole story, as I have the same 'seeking to end'
> problem
> with the more realistic tokeniser regex
>
> "(aaa)|([a-zA-Z][a-zA-Z0-9_-]*)|(.)|(\n)"
>
> where I'm looking for the longest identifier, but want 'aaa' treated as a
> keyword
> provided it isnt followed by other alphanums.

Doh! I forgot about subsequent (possibly unmatched) sub-expressions being
used to break ties, there's another patch below that I'm testing now, I'm
fairly sure it covers all eventualities this time.

> I also wondered if the fact that match_continuous is set is relevant
> since all (toplevel) matches will start at the same place.

Correct, it's not relevant in this issue (it might be necessary in your
"real" code however, depending on what you want to do).

John.

Index: boost/regex/v4/match_results.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/regex/v4/match_results.hpp,v
retrieving revision 1.18
diff -r1.18 match_results.hpp
303c303,304
< BidiIterator base = (*this)[-1].first;

---
>    BidiIterator base = this->prefix().first;
>    BidiIterator end = this->suffix().second;
312a314,341
>       if(p1->first == end)
>       {
>          if(p2->first != end)
>          {
>             // p2 must be better than p1, and no need to calculate
>             // actual distances:
>             base1 = 1;
>             base2 = 0;
>             break;
>          }
>          else
>          {
>             // *p1 and *p2 are either unmatched or match end-of sequence,
>             // either way no need to calculate distances:
>             base1 = 0;
>             base2 = 0;
>             len1 = 0;
>             len2 = 0;
>             break;
>          }
>       }
>       else if((p2->first == end) && (p1->first != end))
>       {
>          // p1 better than p2, and no need to calculate distances:
>          base1 = 0;
>          base2 = 1;
>          break;
>       } 

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net