[Pyparsing] Using pyparsing to implement a matching engine for a regexp-like matching language?
Brought to you by:
ptmcg
From: Andrew W. <and...@gm...> - 2008-04-09 12:44:49
|
I am trying to write a matching engine for a matching language for a filtering proxy compatible with that of The Proxomitron. The matching language is basically an extended superset of shell-style globs, with functionality comparable to regexps (see http://www.proxomitron.info/45/help/Matching%20Rules.html). I think that I can implement the parser for the match and replace patterns themselves using pyparsing, but I am not exactly sure of how to implement the "core" of the matching engine - the part that takes an input string, finds a match, and extracts any parts specified in the pattern. I could almost use pyparsing as a matching engine as well, by dynamically generating a parser from the pattern and parsing the data to be filtered with it, but pyparsing appears to be a pull parser (one that takes all its input at once), as opposed to a push parser (which can be fed multiple chunks of input). Also, non-matching input might cause parse errors. A matching engine for a filtering proxy has to be able to handle partial input and "hold" data until enough is received to determine whether there is a match (or else the entire document would have to be held until the end is reached, filtered, and then sent all at once to the remote client, and that would make it appear much less responsive and possibly break some applications). Is there a way to use pyparsing as a push parser, or can anyone recommend any other Python libraries that would be suitable for my purposes? I don't want to reinvent the wheel unless no suitable library exists. |