Re: [Flex-help] Data from multiple matches
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Calvin L. (callin) <ca...@ci...> - 2012-09-27 18:26:13
|
When you say "returns back to the previous state", I'm guessing you mean have flex scan over the input string again and find the next match? That would work, but wouldn't that be almost equivalent to doing a scan over the input multiple times? Unfortunately, that's the situation I'm trying to avoid for performance reasons. Here's a very simple example. Let's say I have two patterns: 1. 'google.com' 2. 'google.com/enterprise' (yes these are not interesting, but will show my point) If I get as input: 'http://www.google.com/enterprise/apps/business/', flex will match with #2. But I want to somehow know that the input also matches with #1. (note: there could be any number of patterns that match the input). The reason for all this is we allow users to give a sense of order in their regexes. Say #1 maps with some action A and #2 maps with some action B, if the input matches with #1 and #2, we want the action of #1 to execute because it's higher in order. If I could massage flex to tell me about all the matches, my problem is solved, and I wouldn't need flex to return the "correct" match (correct in terms of my purposes). Thanks for all the responses so far, Calvin On 9/27/12 11:08 AM, "John Gwinner" <jgw...@da...> wrote: >| >> I'm wondering if there is a way to have flex give me back data about >| >>all the matches it encountered on a single string before resolving the >| >>multiple matches and choosing one. > >You could have a pattern where the pattern matching action saves >something, and returns back to the previous state. You'd create an >object that would keep track of the overlaps. Flex would just identify >the patterns, not actually go to a different 'action' state as a result. > >My feeling is that you already have the patterns broken down individually >as you mention "all of the matches it encountered". > >If not, like you have a wild card match and you want to know if it >matched 1, then 2, then 3, then 4 of the same symbol, I think the >matching rules would need more of a breakdown anyway. > >Maybe a specific example would help? > > > == John == > > >| -----Original Message----- >| From: Calvin Lin (callin) [mailto:ca...@ci...] >| Sent: Thursday, September 27, 2012 11:03 AM >| To: Jeff Phillips >| Cc: fle...@li... >| Subject: Re: [Flex-help] Data from multiple matches >| >| Thanks for the reply Jeff. >| >| That solution makes sense, but as you suggested, it's not very scalable. >| The way we are using Flex, we allow users to input any number of >| regexes, and it's very possible for a large number of regexes to overlap >| and cause duplicate matches. I'm afraid this may just be a limitation of >| Flex, and we may need to think of other solutions. >| >| Calvin >| >| On 9/27/12 10:45 AM, "Jeff Phillips" <jm...@ya...> wrote: >| >| >Depending on the number of possible duplicate matches you might look at >| >using nested start conditions. So if you matched A you could enter >| >start condition A pass the token back through the input and then see if >| >you match B or C. So that if you then matched B you could enter start >| >condition AB. Again Pass the token back into the input stream and see >| >if you match C. Each start condition would need a terminal action in >| >the event you didn't find any further matches. This should work for a >| >small set of condition but it's not very scalable. >| > >| >Jeff >| > >| >On Sep 27, 2012, at 19:22, "Calvin Lin (callin)" <ca...@ci...> >| wrote: >| > >| >> Hi there, >| >> >| >> It's my understanding that flex resolves multiple matches by taking >| >>the one matching the most text. I have also read the FAQ entry about >| >>Flex not matching patterns in the ordered they are defined, but the >| >>solutions offered aren't exactly what I'm looking for. >| >> >| >> I'm wondering if there is a way to have flex give me back data about >| >>all the matches it encountered on a single string before resolving the >| >>multiple matches and choosing one. That is, say there are 3 regex >| >>expressions A, B, and C, and my input string matches all 3 of them. >| >>Regardless of which one flex chooses to return, I'd like to know >| >>somehow that it matched A, B, and C. Is this possible? It would be >| >>awesome if I could have flex write the rule number of each match to a >| >>variable that I can then read from, or something like that. >| >> >| >> I know you can use YY_USER_ACTION to specify code to execute prior to >| >>a matched rule's action. But my understanding is that this is for >| >>after the multiple matches are resolved and one is selected. What I'm >| >>hoping to do is have code execute before the multiple matches are >| resolved. >| >> >| >> The most ideal solution would be for flex to return the pattern that >| >>is highest in order, but the solutions on this page >| >>(http://flex.sourceforge.net/manual/Flex-is-not-matching-my-patterns-i >| >>n-t >| >>he-same-order-that-I-defined-them_002e.html#Flex-is-not-matching-my-pa >| >>tte >| >>rns-in-the-same-order-that-I-defined-them_002e) don't fit what I need. >| >>Adding '.*' only helps for resolving between 2 matches. >| >> >| >> Any help would be appreciated! >| >> Calvin >| >> >| >>---------------------------------------------------------------------- >| >>--- >| >>----- >| >> Everyone hates slow websites. So do we. >| >> Make your web apps faster with AppDynamics Download AppDynamics Lite >| >>for free today: >| >> http://ad.doubleclick.net/clk;258768047;13503038;j? >| >> http://info.appdynamics.com/FreeJavaPerformanceDownload.html >| >> _______________________________________________ >| >> Flex-help mailing list >| >> Fle...@li... >| >> https://lists.sourceforge.net/lists/listinfo/flex-help >| >| >| ------------------------------------------------------------------------ >| ------ >| Everyone hates slow websites. So do we. >| Make your web apps faster with AppDynamics Download AppDynamics Lite for >| free today: >| http://ad.doubleclick.net/clk;258768047;13503038;j? >| http://info.appdynamics.com/FreeJavaPerformanceDownload.html >| _______________________________________________ >| Flex-help mailing list >| Fle...@li... >| https://lists.sourceforge.net/lists/listinfo/flex-help |