getting trie() to work with Rules ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

getting trie() to work with Rules ?

dudewithakeyboard
Hi,

The trie() function is really awesome and I'm wondering if there is a way to get it to work with Rules instead of Strings ?

I'm trying to find my Patterns in text and there can be 0 to n matches.

ZeroOrMore(trie())

would be a A LOT easier than the contruct I'm currently using which is basically checking for ANY and not my patterns, then for my patterns and then again for ANY and not my patterns:

public Rule AllThePatterns() {
                return oneOrMore(
                                zeroOrMore(testNot(Pattern1()),
                                                testNot(Pattern2()),
                                                testNot(Pattern3()), testNot(Pattern4()),
                                                ANY),
                                firstOf(Pattern1(), Pattern2(),
                                                Pattern3(), Pattern4()),
                                zeroOrMore(testNot(Pattern1()),
                                                testNot(Pattern2()),
                                                testNot(Pattern3()), testNot(Pattern4()),
                                                ANY));
        }

My patterns aren't actually called Pattern1 to 4, i just thought it would be more readable :)

Any help would be appreciated.
fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getting trie() to work with Rules ?

fge
Hello,

dudewithakeyboard wrote
Hi,

The trie() function is really awesome and I'm wondering if there is a way to get it to work with Rules instead of Strings ?

I'm trying to find my Patterns in text and there can be 0 to n matches.

ZeroOrMore(trie())

would be a A LOT easier than the contruct I'm currently using which is basically checking for ANY and not my patterns, then for my patterns and then again for ANY and not my patterns:

public Rule AllThePatterns() {
                return oneOrMore(
                                zeroOrMore(testNot(Pattern1()),
                                                testNot(Pattern2()),
                                                testNot(Pattern3()), testNot(Pattern4()),
                                                ANY),
                                firstOf(Pattern1(), Pattern2(),
                                                Pattern3(), Pattern4()),
                                zeroOrMore(testNot(Pattern1()),
                                                testNot(Pattern2()),
                                                testNot(Pattern3()), testNot(Pattern4()),
                                                ANY));
        }

My patterns aren't actually called Pattern1 to 4, i just thought it would be more readable :)

Any help would be appreciated.
First, this must mean you are using grappa, not parboiled, right? Note that grappa has a dedicated user group (since starting 2.x it differs quite fundamentally from parboiled1). See the project page for details.

As to what you want to achieve, what are your patterns exactly?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: getting trie() to work with Rules ?

dudewithakeyboard
Sorry for the very late response.

Yes, I'm using grappa...sorry about the confusion.
My patterns are quite convoluted so posting them here would prob not do much good.

Or do you mean the pattern I'm currently using to mimic trie() ?
Loading...